#At file:///work/bzr_trees/37870-bug-5.1-bugteam/
2765 Evgeny Potemkin 2008-10-17
Bug#37870: Usage of uninitialized value caused failed assertion.
The convert_constant_item function converts a constant to integer using
field for condition like 'field = a_constant'. When the convert_constant_item
is called for a subquery the outer select is already being executed, so
convert_constant_item saves field's value to prevent its corruption.
For EXPLAIN field's value isn't initialized thus when convert_constant_item
tries to restore saved value it fails assertion.
Now the convert_constant_item doesn't save/restore field's value
for EXPLAIN.
modified:
mysql-test/r/explain.result
mysql-test/t/explain.test
sql/item_cmpfunc.cc
per-file messages:
mysql-test/r/explain.result
Added a test case for the bug#37870.
mysql-test/t/explain.test
Added a test case for the bug#37870.
sql/item_cmpfunc.cc
Bug#37870: Usage of uninitialized value caused failed assertion.
Now the convert_constant_item doesn't save/restore field's value
for EXPLAIN.
=== modified file 'mysql-test/r/explain.result'
--- a/mysql-test/r/explain.result 2007-11-16 11:00:57 +0000
+++ b/mysql-test/r/explain.result 2008-10-17 07:55:06 +0000
@@ -107,3 +107,16 @@ 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 B (dt datetime not null);
+create table BB (dt datetime not null);
+insert into B values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+insert into BB values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+flush tables;
+EXPLAIN SELECT OUTR.dt FROM B AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM BB 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
+drop tables B,BB;
=== modified file 'mysql-test/t/explain.test'
--- a/mysql-test/t/explain.test 2007-11-16 11:00:57 +0000
+++ b/mysql-test/t/explain.test 2008-10-17 07:55:06 +0000
@@ -94,4 +94,15 @@ EXPLAIN SELECT 1 FROM
DROP TABLE t2;
DROP TABLE t1;
+--echo #
+--echo # Bug#37870: Usage of uninitialized value caused failed assertion.
+--echo #
+create table B (dt datetime not null);
+create table BB (dt datetime not null);
+insert into B values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+insert into BB values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
+flush tables;
+EXPLAIN SELECT OUTR.dt FROM B AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM BB AS INNR WHERE OUTR.dt IS NULL );
+drop tables B,BB;
+
# End of 5.0 tests.
=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc 2008-09-09 15:52:38 +0000
+++ b/sql/item_cmpfunc.cc 2008-10-17 07:55:06 +0000
@@ -415,8 +415,9 @@ static bool convert_constant_item(THD *t
/*
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 *t
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. */