[MDEV-3147] LP:901478 - Wrong result (missing row) with join_cache_level>=4, firstmatch=OFF, ORDER BY, Aria Created: 2011-12-07  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: Major
Reporter: Elena Stepanova Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug901478.xml    

 Description   

The following query

SELECT * FROM t1, t2
WHERE c IN ( SELECT c FROM t1, t2 )
ORDER BY b;

produces a wrong result (with one row in t1 and N rows in t2, returns only one row instead of N) if it's run with firstmatch=OFF and join_cache_level>=4.

Only reproducible if t2 is Aria and t1 is either Aria or MyISAM.

I failed to see any difference between EXPLAIN output for join_cache_level=1 vs 4, but I will put both here anyway (first two outputs below).

EXPLAIN output with join_cache_level=4, firstmatch=OFF (wrong result)

1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 Using filesort
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 range c c 5 NULL 2 100.00 Using index condition
1 PRIMARY t2 ref c c 5 test.t2.c 2 100.00 Using index; Start temporary; End temporary

select 'x' AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` semi join (`test`.`t1` join `test`.`t2`) join `test`.`t2` where (`test`.`t2`.`c` = `test`.`t2`.`c`) order by `test`.`t2`.`b`

EXPLAIN output with join_cache_level=1, firstmatch=OFF (correct result)

1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 Using filesort
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 range c c 5 NULL 2 100.00 Using index condition
1 PRIMARY t2 ref c c 5 test.t2.c 2 100.00 Using index; Start temporary; End temporary

select 'x' AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` semi join (`test`.`t1` join `test`.`t2`) join `test`.`t2` where (`test`.`t2`.`c` = `test`.`t2`.`c`) order by `test`.`t2`.`b`

EXPLAIN output with join_cache_level=1, firstmatch=ON (correct result)

1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 Using filesort
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 range c c 5 NULL 2 100.00 Using index condition
1 PRIMARY t2 ref c c 5 test.t2.c 2 100.00 Using index; FirstMatch(t2)

select 'x' AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` semi join (`test`.`t1` join `test`.`t2`) join `test`.`t2` where (`test`.`t2`.`c` = `test`.`t2`.`c`) order by `test`.`t2`.`b`

Minimal optimizer_switch: firstmatch=off

Full optimizer_switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

Test case:

SET optimizer_switch='firstmatch=off';
SET join_cache_level=4; # Reproducible with 4..8

CREATE TABLE t1 ( a CHAR(1) ) ENGINE=Aria;
INSERT INTO t1 VALUES ('x');
CREATE TABLE t2 ( b INT, c INT, KEY(b), KEY(c)) ENGINE=Aria;
INSERT INTO t2 VALUES (1,0);
INSERT INTO t2 VALUES (2,8);

SELECT * FROM t1, t2
WHERE c IN ( SELECT c FROM t1, t2 )
ORDER BY b;

  1. End of test case
  1. Expected result:
    #
  2. a b c
  3. x 1 0
  4. x 2 8
    #
  5. Result:
    #
  6. a b c
  7. x 1 0


 Comments   
Comment by Elena Stepanova [ 2011-12-09 ]

Re: Wrong result (missing row) with join_cache_level>=4, firstmatch=OFF, ORDER BY, Aria
bzr version-info
revision-id: psergey@askmonty.org-20111208002238-zeewdrj61uqiscwo
date: 2011-12-08 04:22:38 +0400
build-date: 2011-12-09 17:06:06 +0200
revno: 3337
branch-nick: maria-5.3

Comment by Rasmus Johansson (Inactive) [ 2011-12-13 ]

Launchpad bug id: 901478

Generated at Thu Feb 08 06:46:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.