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

Wrong result with index_merge_sort_intersection (and rowid_filter)

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.5, 10.6, 10.7, 10.8, 10.9
    • 10.5, 10.6
    • Optimizer

    Description

      Note: Setting to 10.5+ as the test case below only fails with rowid_filter=on (default in 10.5+, the switch is absent in previous versions), but possibly the test case can be further modified to make it irrelevant.

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (f int) ENGINE=InnoDB;
      INSERT INTO t1 VALUES (0),(4);
       
      CREATE TABLE t2 (pk int, a int, b varchar(10), PRIMARY KEY (pk), KEY a (a), KEY b (b)) ENGINE=InnoDB;
      INSERT INTO t2 VALUES
        (1,2,'v'),(2,3,'p'),(3,4,'p'),(4,2,'y'),(5,7,'q'),
        (6,4,'a'),(7,1,'d'),(8,5,'a'),(9,5,'z'),(10,1,'t'),
        (11,1,'y'),(12,5,'o'),(13,4,'a'),(14,5,'s'),(15,5,'m');
       
      ANALYZE TABLE t1, t2 PERSISTENT FOR ALL;
       
      SET optimizer_switch='rowid_filter=on'; # Default
       
      SET optimizer_switch='index_merge_sort_intersection=off'; # Default
      SELECT * FROM t1 JOIN t2 ON t1.f = t2.a WHERE t2.b >= 'j' AND t2.a != 5;
       
      SET optimizer_switch='index_merge_sort_intersection=on';
      SELECT * FROM t1 JOIN t2 ON t1.f = t2.a WHERE t2.b >= 'j' AND t2.a != 5;
       
      DROP TABLE t1, t2;
      

      10.5 674842be

      SET optimizer_switch='index_merge_sort_intersection=off';
      SELECT * FROM t1 JOIN t2 ON t1.f = t2.a WHERE t2.b >= 'j' AND t2.a != 5;
      f	pk	a	b
      4	3	4	p
      SET optimizer_switch='index_merge_sort_intersection=on';
      SELECT * FROM t1 JOIN t2 ON t1.f = t2.a WHERE t2.b >= 'j' AND t2.a != 5;
      f	pk	a	b
      

      Plans:

      SET optimizer_switch='index_merge_sort_intersection=off';
      EXPLAIN EXTENDED SELECT * FROM t1 JOIN t2 ON t1.f = t2.a WHERE t2.b >= 'j' AND t2.a != 5;
      id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
      1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
      1	SIMPLE	t2	ALL	a,b	NULL	NULL	NULL	15	48.89	Using where; Using join buffer (flat, BNL join)
      Warnings:
      Note	1003	select `test`.`t1`.`f` AS `f`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`f` and `test`.`t2`.`b` >= 'j' and `test`.`t1`.`f` <> 5
      SET optimizer_switch='index_merge_sort_intersection=on';
      EXPLAIN EXTENDED SELECT * FROM t1 JOIN t2 ON t1.f = t2.a WHERE t2.b >= 'j' AND t2.a != 5;
      id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
      1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
      1	SIMPLE	t2	index_merge|filter	a,b	a,b|b	5,13|13	NULL	5 (73%)	73.33	Using sort_intersect(a,b); Using where; Using join buffer (flat, BNL join); Using rowid filter
      Warnings:
      Note	1003	select `test`.`t1`.`f` AS `f`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`f` and `test`.`t2`.`b` >= 'j' and `test`.`t1`.`f` <> 5
      

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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