Wrong result with semijoin + materialization + multipart key
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| MariaDB |
Fix Released
|
High
|
Sergey Petrunia | ||
Bug Description
The following query:
SELECT * FROM t1
WHERE (a) IN (
SELECT a
FROM t2
JOIN t3 ON b = a
);
returns
| a |
+------+
| 19 |
| 19 |
| 19 |
when executed with semijoin+
| a |
+------+
| 19 |
| 19 |
| 19 |
| 20 |
| 20 |
| 20 |
| 20 |
| 20 |
| 20 |
when executed otherwise (which seems to be the correct result).
Offending explain:
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 9 | Using where |
| 1 | PRIMARY | <subquery2> | eq_ref | distinct_key | distinct_key | 5 | func | 1 | |
| 2 | SUBQUERY | t3 | ALL | NULL | NULL | NULL | NULL | 13 | |
| 2 | SUBQUERY | t2 | ref | b | b | 4 | test.t1.a | 1 | Using where; Using index |
minimal switch: semijoin=
full switch: index_merge=
bzr version-info
revision-id: <email address hidden>
date: 2011-10-17 03:42:56 -0700
build-date: 2011-10-18 13:05:59 +0300
revno: 3239
branch-nick: maria-5.3
test case:
CREATE TABLE t1 ( a int) ;
INSERT INTO t1 VALUES (19),(19)
CREATE TABLE t2 ( b int NOT NULL , c int NOT NULL , KEY (b,c)) ;
INSERT INTO t2 VALUES (14,1),
CREATE TABLE t3 ( a int, d int) ;
INSERT INTO t3 VALUES (19,1),
SET SESSION optimizer_
SELECT * FROM t1
WHERE (a) IN (
SELECT a
FROM t2
JOIN t3 ON b = a );
| Changed in maria: | |
| milestone: | none → 5.3 |
| assignee: | nobody → Sergey Petrunia (sergefp) |
| Changed in maria: | |
| importance: | Undecided → High |
| Changed in maria: | |
| status: | Confirmed → Fix Committed |
| Changed in maria: | |
| status: | Fix Committed → Fix Released |

MariaDB [bug877288]> explain SELECT * FROM t1 WHERE (a) IN ( SELECT a FROM t2 JOIN t3 ON b = a ); ------- -----+- ------- -----+- ------- +------ ------- --+---- ------- ---+--- ------+ ------- ------- --+---- --+---- ------- ------- ------- -+ ------- -----+- ------- -----+- ------- +------ ------- --+---- ------- ---+--- ------+ ------- ------- --+---- --+---- ------- ------- ------- -+ ------- -----+- ------- -----+- ------- +------ ------- --+---- ------- ---+--- ------+ ------- ------- --+---- --+---- ------- ------- ------- -+
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 9 | Using where |
| 1 | PRIMARY | <subquery2> | eq_ref | distinct_key | distinct_key | 5 | func | 1 | |
| 2 | SUBQUERY | t3 | ALL | NULL | NULL | NULL | NULL | 13 | |
| 2 | SUBQUERY | t2 | ref | b | b | 4 | bug877288.t1.a | 1 | Using where; Using index |
+----+-