summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/explain.result15
-rw-r--r--mysql-test/t/explain.test12
-rw-r--r--sql/item_cmpfunc.cc5
3 files changed, 30 insertions, 2 deletions
diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result
index 2ce8b8c384f..f3822fe370d 100644
--- a/mysql-test/r/explain.result
+++ b/mysql-test/r/explain.result
@@ -107,3 +107,18 @@ X X X X X X X X X
X X X X X X X X X Range checked for each record (index map: 0xFFFFFFFFFF)
DROP TABLE t2;
DROP TABLE t1;
+#
+# Bug#37870: Usage of uninitialized value caused failed assertion.
+#
+create table t1 (dt datetime not null);
+create table t2 (dt datetime not null);
+insert into t1 values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+insert into t2 values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+flush tables;
+EXPLAIN SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL );
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY OUTR ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY INNR ALL NULL NULL NULL NULL 2 Using where
+SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL );
+dt
+drop tables t1, t2;
diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test
index c9ae8aceaf6..09a8245b27b 100644
--- a/mysql-test/t/explain.test
+++ b/mysql-test/t/explain.test
@@ -94,4 +94,16 @@ EXPLAIN SELECT 1 FROM
DROP TABLE t2;
DROP TABLE t1;
+--echo #
+--echo # Bug#37870: Usage of uninitialized value caused failed assertion.
+--echo #
+create table t1 (dt datetime not null);
+create table t2 (dt datetime not null);
+insert into t1 values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+insert into t2 values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+flush tables;
+EXPLAIN SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL );
+SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL );
+drop tables t1, t2;
+
# End of 5.0 tests.
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index bd6065c9403..0c95336251b 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -415,8 +415,9 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
/*
Store the value of the field if it references an outer field because
the call to save_in_field below overrides that value.
+ Don't store it for EXPLAIN since it's not initialized.
*/
- if (field_item->depended_from)
+ if (field_item->depended_from && !thd->lex->describe)
orig_field_val= field->val_int();
if (!(*item)->is_null() && !(*item)->save_in_field(field, 1))
{
@@ -427,7 +428,7 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
result= 1; // Item was replaced
}
/* Restore the original field value. */
- if (field_item->depended_from)
+ if (field_item->depended_from && !thd->lex->describe)
{
result= field->store(orig_field_val, TRUE);
/* orig_field_val must be a valid value that can be restored back. */