[MDEV-2746] LP:670417 - Diverging results in maria-5.3-mwl128-dsmrr-cpk with join buffer (incremental, BKA join) Created: 2010-11-03  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
Reporter: Philip Stoev (Inactive) Assignee: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug670417.xml    

 Description   

The following query

SELECT table2.col_varchar_key FROM t2 STRAIGHT_JOIN ( t1 AS table2 JOIN t1 AS table3 ON table3.pk ) ON table3.col_varchar_key = table2.col_varchar_key AND table3.col_varchar_key = table2.col_varchar_nokey ;

Returns 999 rows when executed with BKA in maria-5.3-mwl128-dsmrr-cpk . All other execution plans and trees (maria-5.3 and maria-5.3-mwl128) agree that the query should return 1000 rows.



 Comments   
Comment by Philip Stoev (Inactive) [ 2010-11-03 ]

Re: Diverging results in maria-5.3-mwl128-dsmrr-cpk with join buffer (incremental, BKA join)
Test case:

--disable_abort_on_error
SET SESSION optimizer_switch = 'index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,table_elimination=on';
SET SESSION optimizer_use_mrr = 'force';
SET SESSION join_cache_level = 6;
SET SESSION join_buffer_size = 136;
SET SESSION debug = '';
--enable_abort_on_error

--disable_warnings
DROP TABLE /*! IF EXISTS */ t1;
DROP TABLE /*! IF EXISTS */ t2;
--enable_warnings

CREATE TABLE t1 (
pk int(11) NOT NULL AUTO_INCREMENT,
col_int_key int(11) NOT NULL,
col_varchar_key varchar(1) NOT NULL,
col_varchar_nokey varchar(1) NOT NULL,
PRIMARY KEY (pk),
KEY col_int_key (col_int_key),
KEY col_varchar_key (col_varchar_key,col_int_key)
) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (10,8,'v','v'),(11,8,'f','f'),(12,5,'v','v'),(13,8,'s','s'),(14,8,'a','a'),(15,6,'p','p'),(16,7,'z','z'),(17,2,'a','a'),(18,5,'h','h'),(19,7,'h','h'),(20,2,'v','v'),(21,9,'v','v'),(22,142,'b','b'),(23,3,'y','y'),(24,0,'v','v'),(25,3,'m','m'),(26,5,'z','z'),(27,9,'n','n'),(28,1,'d','d'),(29,107,'a','a');
CREATE TABLE t2 (
pk int(11) NOT NULL AUTO_INCREMENT,
col_int_key int(11) NOT NULL,
col_varchar_key varchar(1) NOT NULL,
col_varchar_nokey varchar(1) NOT NULL,
PRIMARY KEY (pk),
KEY col_int_key (col_int_key),
KEY col_varchar_key (col_varchar_key,col_int_key)
) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;
INSERT INTO t2 VALUES (1,9,'x','x'),(2,5,'g','g'),(3,1,'o','o'),(4,0,'g','g'),(5,1,'v','v'),(6,190,'m','m'),(7,6,'x','x'),(8,3,'c','c'),(9,4,'z','z'),(10,3,'i','i'),(11,186,'x','x'),(12,1,'g','g'),(13,8,'q','q'),(14,226,'m','m'),(15,133,'p','p'),(16,6,'e','e'),(17,3,'t','t'),(18,8,'j','j'),(19,5,'h','h'),(20,7,'w','w');

SELECT COUNT(table2.col_varchar_key) FROM t2 STRAIGHT_JOIN ( t1 AS table2 JOIN t1 AS table3 ON table3.pk ) ON table3.col_varchar_key = table2.col_varchar_key AND table3.col_varchar_key = table2.col_varchar_nokey ;
EXPLAIN SELECT COUNT(table2.col_varchar_key) FROM t2 STRAIGHT_JOIN ( t1 AS table2 JOIN t1 AS table3 ON table3.pk ) ON table3.col_varchar_key = table2.col_varchar_key AND table3.col_varchar_key = table2.col_varchar_nokey ;

Comment by Sergei Petrunia [ 2010-11-03 ]

Re: Diverging results in maria-5.3-mwl128-dsmrr-cpk with join buffer (incremental, BKA join)
One can get a simpler testcase by doing

DELETE FROM t2 WHERE pk <> 1;

Then the query will produce 47 rows instead of 50 (as opposed to 999 instead of 1000).

Comment by Sergei Petrunia [ 2010-11-03 ]

Re: Diverging results in maria-5.3-mwl128-dsmrr-cpk with join buffer (incremental, BKA join)

  • One can repeat the problem with default @@join_buffer_size setting (i.e. this is not related to buffer overflows). The only requirement is that @@join_cache_level==6.
  • The problem goes away when one runs

set optimizer_switch='index_condition_pushdown=off';

and comes back when one runs

set optimizer_switch='index_condition_pushdown=on';

Looks like something with DS-MRR and index condition pushdown.

Comment by Sergei Petrunia [ 2010-11-03 ]

Re: Diverging results in maria-5.3-mwl128-dsmrr-cpk with join buffer (incremental, BKA join)
Also, the problem goes away if one turns off key sorting:

set optimizer_switch='mrr_sort_keys=off';

makes the query produce correct result, irrespectively of index_condition_pushdown setting.

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

Launchpad bug id: 670417

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