Skip to content

Commit 69ffc9c

Browse files
author
Martin Hansson
committed
Bug#21625929: ASSERTION FAILED: FALSE IN CREATE_TMP_FIELD
WITH UNKNOWN OUTER FIELD Some assertions in sql_tmp_table.cc were added in a merge from 5.6. They ruled out the possibility that a temporary table column could be created on the basis of a prepared statement parameter. Fixed by reverting the behavior back to 5.6 in this particular case: I.e. not creating columns for parameters during PREPARE. During EXECUTE we don't have this problem, obviously, since at that time the parameters have been substituted by constant expressions.
1 parent 5bb1544 commit 69ffc9c

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

mysql-test/r/sp.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7858,3 +7858,14 @@ PREPARE s FROM
78587858
ERROR 42000: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t1.b' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
78597859
DROP TABLE t1, t2;
78607860
SET sql_mode = DEFAULT;
7861+
#
7862+
# ASSERTION FAILED: FALSE IN CREATE_TMP_FIELD WITH UNKNOWN OUTER FIELD
7863+
#
7864+
CREATE TABLE t1 ( a INT );
7865+
SET @v = 1;
7866+
PREPARE stmt FROM 'SELECT 1 FROM ( SELECT ? FROM t1 GROUP BY a ) al;';
7867+
EXECUTE stmt USING @v;
7868+
1
7869+
PREPARE stmt FROM 'CREATE TABLE t2 AS SELECT ? FROM t1';
7870+
EXECUTE stmt USING @v;
7871+
DROP TABLE t1, t2;

mysql-test/t/sp.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9096,3 +9096,18 @@ PREPARE s FROM
90969096

90979097
DROP TABLE t1, t2;
90989098
SET sql_mode = DEFAULT;
9099+
9100+
--echo #
9101+
--echo # ASSERTION FAILED: FALSE IN CREATE_TMP_FIELD WITH UNKNOWN OUTER FIELD
9102+
--echo #
9103+
CREATE TABLE t1 ( a INT );
9104+
9105+
SET @v = 1;
9106+
9107+
PREPARE stmt FROM 'SELECT 1 FROM ( SELECT ? FROM t1 GROUP BY a ) al;';
9108+
EXECUTE stmt USING @v;
9109+
9110+
PREPARE stmt FROM 'CREATE TABLE t2 AS SELECT ? FROM t1';
9111+
EXECUTE stmt USING @v;
9112+
9113+
DROP TABLE t1, t2;

sql/sql_tmp_table.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ static Field *create_tmp_field_for_schema(THD *thd, Item *item, TABLE *table)
242242
If modify_item is 0 then fill_record() will update
243243
the temporary table
244244
245-
@retval
246-
NULL on error
247-
@retval
248-
new_created field
245+
@retval NULL On error. This also happens if the item is a prepared statement
246+
parameter.
247+
248+
@retval new_created field
249249
*/
250250

251251
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
@@ -390,6 +390,8 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
390390
break;
391391
result->set_derivation(item->collation.derivation);
392392
break;
393+
case Item::PARAM_ITEM:
394+
return NULL;
393395
default: // Dosen't have to be stored
394396
DBUG_ASSERT(false);
395397
break;
@@ -954,6 +956,8 @@ create_tmp_table(THD *thd, Temp_table_param *param, List<Item> &fields,
954956

955957
if (!new_field)
956958
{
959+
if (type == Item::PARAM_ITEM)
960+
goto update_hidden;
957961
DBUG_ASSERT(thd->is_fatal_error);
958962
goto err; // Got OOM
959963
}

0 commit comments

Comments
 (0)