Details
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'
Gliffy Diagrams
Attachments
Issue Links
- relates to
-
MDEV-5531 double call procedure in one session - hard shutdown the server
-
- Closed
-
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
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.