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

Optimizer Context is empty for EXPLAIN that uses a table

    XMLWordPrintable

Details

    Description

      Run this as .test testcase:

      CREATE TABLE t1 (a INT, b INT, KEY(a));
      INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
       
      # Note: this is essential: without it, the context is present:
      analyze table t1;
       
      create function add1(i int) returns int deterministic
        return i+1;
       
      set optimizer_record_context=1;
      explain select * from t1 where b< add1(3);
      select * from information_schema.optimizer_context;
       
      drop function add1;
      DROP TABLE t1;
      

      and observe this:

      explain select * from t1 where b< add1(3);
      id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
      1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using where
      select * from information_schema.optimizer_context;
      QUERY   CONTEXT
      drop function add1;
      DROP TABLE t1;
      

      There is nothing in the context, because we take this if in store_optimizer_context():

        if (!thd->opt_ctx_recorder ||
            lex->query_tables == *(lex->query_tables_last))
        {
          return false;
        }
      

      lex->query_tables points to t1,
      lex->query_tables_last points to somewhere where there is a pointer to t1.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              psergei Sergei Petrunia
              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.