[MDEV-2722] LP:951937 - Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off Created: 2012-03-11 Updated: 2015-02-02 Resolved: 2012-10-04 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Launchpad | ||
| Attachments: |
|
| Description |
|
The following query SELECT * FROM v on the test data returns 6 rows if it's executed with semijoin=on and materialization=on, and 19 rows otherwise. The latter is correct. bzr version-info Also reproducible on 5.5 (revno 3316). EXPLAIN with semijoin=on, materialization=on (wrong result): id select_type table type possible_keys key key_len ref rows filtered Extra Minimal optimizer_switch: materialization=on,semijoin=on Test case (with the variation): --source include/have_innodb.inc CREATE TABLE t1 ( CREATE ALGORITHM=TEMPTABLE VIEW v AS SELECT * FROM t1;
SELECT * FROM v
ALTER TABLE t1 MODIFY COLUMN b VARCHAR(1);
SELECT * FROM v
|
| Comments |
| Comment by Sergei Petrunia [ 2012-03-19 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off #0 evaluate_join_record (join=0x9f54a28, join_tab=0x9f5cdb8, error=0) at sql_select.cc:15531 |
| Comment by Sergei Petrunia [ 2012-03-19 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off |
| Comment by Sergei Petrunia [ 2012-03-19 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off this part of WHERE condition: "(`j2`.`t1a`.`b` >= `j2`.`t1a`.`a`)" is attached to table v (i.e. <derived3>), and it evaluates to FALSE. This is wrong because the dataset has t1.a=t1.b for all rows. |
| Comment by Sergei Petrunia [ 2012-03-19 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off |
| Comment by Sergei Petrunia [ 2012-03-19 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off The question is why we're doing that. The clause (t1a.b >= t1a.a OR t1b.b = 'z') was originally inside the subquery, and has been attached to the subquery's |
| Comment by Sergei Petrunia [ 2012-03-19 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off (t1b.a = t1a.a) and so, t1b.b = 'z' got converted into (t1a.a = 'z' and v.a = 'z') (**) We got it, because we've had a multi-equality of: t1a.a=t1b.a=t1b.b=v.a and a join order of {v, t1a, t1b }. The first element is `v`, the first one inside the sjm nest is `t1a`. Substitution (**) is generally useful, but not when we get it inside an OR clause. When we do it inside an OR clause, that has other OR-part that can be evaluated only inside the subquery, we end up with un-evaluable clause. |
| Comment by Sergei Petrunia [ 2012-03-20 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off "(((t1a.b >= t1a.a) or multiple equal('z', t1b.b, t1a.a, v.a, t1b.a)) and multiple equal(t1b.b, t1a.a, v.a, t1b.a))" the multiple-equal inside the OR clause is the same as the outer one, except that it also includes constant 'z'. After equality substitution for the inner multiple equal('z', t1b.b, t1a.a, v.a, t1b.a) , we get In MariaDB: In MySQL: |
| Comment by Sergei Petrunia [ 2012-03-20 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off |
| Comment by Sergei Petrunia [ 2012-03-21 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off select * from ot convert_subq_to_sj(), followed by equality propagation, will produce this WHERE 01 multi-equal(ot.a, it.a) and Suppose the chosen join order is Now, we do equality substitution:
This shows the problem. Suppose we're doing equality substitution for an OR multi-equal(inherited(ot.a, it.a), 111) is this a case like in #03, or like in #06? There is no way to tell. |
| Comment by Sergei Petrunia [ 2012-03-23 ] |
|
Re: Wrong result (missing rows) with semijoin+materialization, IN subquery, InnoDB, TEMPTABLE view or derived_merge=off |
| Comment by Rasmus Johansson (Inactive) [ 2012-04-03 ] |
|
Launchpad bug id: 951937 |