[MDEV-5203] Different results with record_cond_statistics=on and record_cond_statistics=off with SOME subquery Created: 2013-10-29  Updated: 2013-11-06  Resolved: 2013-11-06

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: 10.0.6

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Timour Katchaounov (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-83 Cost-based choice for the pushdown of... Stalled

 Description   

The following test case produces different result sets for the first and the second SELECT. SELECT is the same, only the value of record_cond_statistics differs.
The same query on 10.0-base or on MariaDB 5.3 or on MySQL 5.6 produces 2 rows, which I assume to be a correct result.

CREATE TABLE t1 (i1 INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (9),(8);
 
CREATE TABLE t2 (id2 INT, i2 INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,5),(2,6);
 
CREATE TABLE t3 (pk3 INT PRIMARY KEY, i3 INT) ENGINE=MyISAM;
INSERT INTO t3 VALUES (1,0),(2,6);
 
SELECT * FROM t1 AS outer_t1, t2, t3 
WHERE pk3 = id2 AND i2 < SOME ( SELECT i1 FROM t1 WHERE i1 < outer_t1.i1 );
 
SET optimizer_switch='record_cond_statistics=on';
 
SELECT * FROM t1 AS outer_t1, t2, t3 
WHERE pk3 = id2 AND i2 < SOME ( SELECT i1 FROM t1 WHERE i1 < outer_t1.i1 );

Results:

SELECT * FROM t1 AS outer_t1, t2, t3 
WHERE pk3 = id2 AND i2 < SOME ( SELECT i1 FROM t1 WHERE i1 < outer_t1.i1 );
i1	id2	i2	pk3	i3
9	1	5	1	0
9	2	6	2	6
SET optimizer_switch='record_cond_statistics=on';
SELECT * FROM t1 AS outer_t1, t2, t3 
WHERE pk3 = id2 AND i2 < SOME ( SELECT i1 FROM t1 WHERE i1 < outer_t1.i1 );
i1	id2	i2	pk3	i3
9	1	5	1	0
8	1	5	1	0
9	2	6	2	6
8	2	6	2	6

EXPLAIN with record_cond_statistics=off:

id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	outer_t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Subqueries: 2; Using join buffer (flat, BNL join)
1	PRIMARY	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.id2	1	100.00	
2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
Warnings:
Note	1276	Field or reference 'test.outer_t1.i1' of SELECT #2 was resolved in SELECT #1
Note	1003	select `test`.`outer_t1`.`i1` AS `i1`,`test`.`t2`.`id2` AS `id2`,`test`.`t2`.`i2` AS `i2`,`test`.`t3`.`pk3` AS `pk3`,`test`.`t3`.`i3` AS `i3` from `test`.`t1` `outer_t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`pk3` = `test`.`t2`.`id2`) and <nop>(<expr_cache><`test`.`t2`.`i2`,`test`.`outer_t1`.`i1`>(<in_optimizer>(`test`.`t2`.`i2`,<exists>(select `test`.`t1`.`i1` from `test`.`t1` where ((`test`.`t1`.`i1` < `test`.`outer_t1`.`i1`) and trigcond(((<cache>(`test`.`t2`.`i2`) < `test`.`t1`.`i1`) or isnull(`test`.`t1`.`i1`)))) having trigcond(<is_not_null_test>(`test`.`t1`.`i1`)))))))

EXPLAIN with record_cond_statistics=on:

id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	outer_t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Subqueries: 2; Using join buffer (flat, BNL join)
1	PRIMARY	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.id2	1	100.00	Using where
2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
Warnings:
Note	1276	Field or reference 'test.outer_t1.i1' of SELECT #2 was resolved in SELECT #1
Note	1003	select `test`.`outer_t1`.`i1` AS `i1`,`test`.`t2`.`id2` AS `id2`,`test`.`t2`.`i2` AS `i2`,`test`.`t3`.`pk3` AS `pk3`,`test`.`t3`.`i3` AS `i3` from `test`.`t1` `outer_t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`pk3` = `test`.`t2`.`id2`) and <nop>(<expr_cache><`test`.`t2`.`i2`,`test`.`outer_t1`.`i1`>(<in_optimizer>(`test`.`t2`.`i2`,<exists>(select `test`.`t1`.`i1` from `test`.`t1` where ((`test`.`t1`.`i1` < `test`.`outer_t1`.`i1`) and trigcond(((<cache>(`test`.`t2`.`i2`) < `test`.`t1`.`i1`) or isnull(`test`.`t1`.`i1`)))) having trigcond(<is_not_null_test>(`test`.`t1`.`i1`)))))))



 Comments   
Comment by Timour Katchaounov (Inactive) [ 2013-11-06 ]

Already fixed by the following commit:

revno: 3752
fixes bug: https://mariadb.atlassian.net/browse/MDEV-5178
committer: timour@askmonty.org <timour@askmonty.org>
branch nick: 10.0-md83-4170-static-dyn-push
timestamp: Thu 2013-10-31 16:19:45 +0200
message:

  • Addressed review comments:
  • moved the calculation of the extra cost of subquery predicates during join optimization
    into a separate method JOIN::static_pushdown_cost()
  • fixed small errors in static_pushdown_cost()
  • added a call to this method into optimize_straight_join, so that SELECT STRAIGHT_JOIN
    is optimized in the same way as regular joins
  • added test cases for SELECT STRAIGHT_JOIN
  • Fixed bug MDEV-5178 Valgrind warnings (Conditional jump or move depends on uninitialised value) with static_cond_pushdown=on, FROM subquery
Generated at Thu Feb 08 07:02:29 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.