Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-5203

Different results with record_cond_statistics=on and record_cond_statistics=off with SOME subquery

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 10.0.6
    • None
    • None

    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`)))))))

      Attachments

        Issue Links

          Activity

            People

              timour Timour Katchaounov (Inactive)
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.