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

LP:802858 - Inferior plan selected after mwl#106 with ORDER BY

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Resolution: Not a Bug
    • None
    • None
    • None

    Description

      The following view:

      CREATE VIEW v1 AS SELECT DISTINCT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 0, 9 ;

      is executed with an inferior plan after mwl#106 .

      Before mwl106:

      explain:

      1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9
      2 DERIVED t1 range b,b_2 b 4 NULL 226 Using where; Using temporary

      counters:

      Handler_read_next 0
      Handler_read_prev 8
      Handler_read_rnd 0
      Handler_read_rnd_next 19
      Handler_write 20

      after mwl106:

      explain:

      1 PRIMARY <derived2> ALL NULL NULL NULL NULL 222
      2 DERIVED t1 ref b,b_2 b_2 4 const 222 Using where; Using index; Using temporary; Using filesort

      counters:

      -Handler_read_next 208
      -Handler_read_prev 0
      -Handler_read_rnd 9
      -Handler_read_rnd_next 219
      -Handler_tmp_update 0
      -Handler_tmp_write 217
      -Handler_write 2

      The results returned are also different, but I do not know if the difference is legitimate or not.

      Test case:

      CREATE TABLE t1 (
      a INT,
      b INT NOT NULL,
      c char(100),
      KEY (b, c),
      KEY (b, a, c)
      )

      INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5), (6, 6, 6), (7, 7, 7), (8, 8, 8), (9, 9, 9);

      INSERT INTO t1 SELECT a + 10, b, c FROM t1;
      INSERT INTO t1 SELECT a + 20, b, c FROM t1;
      INSERT INTO t1 SELECT a + 40, b, c FROM t1;
      INSERT INTO t1 SELECT a + 80, b, c FROM t1;
      INSERT INTO t1 SELECT a + 160, b, c FROM t1;
      INSERT INTO t1 SELECT a + 320, b, c FROM t1;
      INSERT INTO t1 SELECT a + 640, b, c FROM t1;
      INSERT INTO t1 SELECT a + 1280, b, c FROM t1 LIMIT 80;

      CREATE VIEW v1 AS SELECT DISTINCT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 0, 9 ;
      EXPLAIN SELECT * FROM v1;
      FLUSH STATUS;
      SELECT * FROM v1;
      SHOW STATUS LIKE '%Handler%';

      Attachments

        Activity

          People

            igor Igor Babaev
            philipstoev Philip Stoev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 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.