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

ER_BAD_FIELD_ERROR (Unknown column in where clause) on the 2nd execution of PS

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL), 10.11
    • 10.5, 10.6
    • Prepared Statements
    • None

    Description

      The problem was introduced in 5.5 tree with the following revision:

      revno: 4030
      revision-id: monty@askmonty.org-20140124125018-qwln430o4bu3pued
      parent: monty@askmonty.org-20140124123019-2ts6q2ip6076gmqg
      committer: Michael Widenius <monty@askmonty.org>
      branch nick: maria-5.5
      timestamp: Fri 2014-01-24 14:50:18 +0200
      message:
        Fix for MDEV-5531: double call procedure in one session - hard shutdown the server
        Main fix was to not cache derivied tables as they may be temporary tables that are deleted before the next query.
        This was a bit tricky as Item_field::fix_fields depended on cached_tables to be set to resolve some columns.

      CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
      CREATE TABLE t2 (c INT) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (1,1),(2,2);
      INSERT INTO t2 VALUES (3),(4);
       
      PREPARE stmt FROM 'SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq WHERE a IN ( SELECT c FROM t2 WHERE c <= sq.b )';
      EXECUTE stmt;
      EXECUTE stmt;

      query 'EXECUTE stmt' failed: 1054: Unknown column 'sq.b' in 'where clause'

      Attachments

        Issue Links

          Activity

            simplified prepare (easier to debug):

            PREPARE stmt FROM 'SELECT 1 FROM ( SELECT DISTINCT * FROM t1 ) AS sq WHERE a IN ( SELECT 1 FROM t2 WHERE sq.b <= c)';

            The problem is that during the first execute, we call, as part of sub query optimization:

            void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref)

            This sets ctx->outer_contex = NULL for the new context.

            This causes setup_without_group-> setup_conds for the second execution to not find the outer ref field sq.b.

            One can't use the old outer_context for the new context as in fix_outer_field we do:

            Item_subselect *prev_subselect_item=
            last_checked_context->select_lex->master_unit()->item;

            Which is 0 for the new context that was created.

            monty Michael Widenius added a comment - simplified prepare (easier to debug): PREPARE stmt FROM 'SELECT 1 FROM ( SELECT DISTINCT * FROM t1 ) AS sq WHERE a IN ( SELECT 1 FROM t2 WHERE sq.b <= c)'; The problem is that during the first execute, we call, as part of sub query optimization: void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref) This sets ctx->outer_contex = NULL for the new context. This causes setup_without_group-> setup_conds for the second execution to not find the outer ref field sq.b. One can't use the old outer_context for the new context as in fix_outer_field we do: Item_subselect *prev_subselect_item= last_checked_context->select_lex->master_unit()->item; Which is 0 for the new context that was created.

            Still reproducible on all existing versions.

            elenst Elena Stepanova added a comment - Still reproducible on all existing versions.

            People

              shulga Dmitry Shulga
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.