[Commits] Rev 3169: BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization in file:///home/psergey/dev2/5.3-push18/

Sergey Petrunya psergey at askmonty.org
Mon Aug 29 20:54:18 EEST 2011


At file:///home/psergey/dev2/5.3-push18/

------------------------------------------------------------
revno: 3169
revision-id: psergey at askmonty.org-20110829175416-1tk3shy5deenu13q
parent: psergey at askmonty.org-20110829155741-lt1xkq1wunwokczb
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.3-push18
timestamp: Mon 2011-08-29 21:54:16 +0400
message:
  BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization
  - Let create_tmp_table set KEY_PART_INFO::fieldnr. It is needed in add_ref_to_table_cond(), and possibly other places.
=== modified file 'mysql-test/r/subselect_mat.result'
--- a/mysql-test/r/subselect_mat.result	2011-08-22 21:00:13 +0000
+++ b/mysql-test/r/subselect_mat.result	2011-08-29 17:54:16 +0000
@@ -1562,6 +1562,23 @@
 left(a1,7)	left(a2,7)
 1 - 01x	2 - 01x
 drop table t1_1024, t2_1024;
+#
+# BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization
+#
+CREATE TABLE t1 (c int, d varchar(1), KEY(d)) ;
+INSERT INTO t1 VALUES (2,'x'),(2,'x'),(2,'j'),(2,'c');
+CREATE TABLE t2 (a int, d varchar(1)) ;
+INSERT INTO t2 VALUES (1,'x');
+CREATE TABLE t3 (d varchar(1)) ;
+INSERT INTO t3 VALUES ('x'),('x'),('j'),('c');
+SELECT t2.a, t1.c
+FROM t1, t2
+WHERE t2.d IN ( SELECT d FROM t3 )
+AND t1.d = t2.d
+GROUP BY 1 , 2;
+a	c
+1	2
+drop table t1,t2,t3;
 set optimizer_switch=@subselect_sj_mat_tmp;
 set @subselect_mat_test_optimizer_switch_value=null;
 set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';

=== modified file 'mysql-test/r/subselect_sj_mat.result'
--- a/mysql-test/r/subselect_sj_mat.result	2011-08-09 15:34:26 +0000
+++ b/mysql-test/r/subselect_sj_mat.result	2011-08-29 17:54:16 +0000
@@ -1600,4 +1600,21 @@
 left(a1,7)	left(a2,7)
 1 - 01x	2 - 01x
 drop table t1_1024, t2_1024;
+#
+# BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization
+#
+CREATE TABLE t1 (c int, d varchar(1), KEY(d)) ;
+INSERT INTO t1 VALUES (2,'x'),(2,'x'),(2,'j'),(2,'c');
+CREATE TABLE t2 (a int, d varchar(1)) ;
+INSERT INTO t2 VALUES (1,'x');
+CREATE TABLE t3 (d varchar(1)) ;
+INSERT INTO t3 VALUES ('x'),('x'),('j'),('c');
+SELECT t2.a, t1.c
+FROM t1, t2
+WHERE t2.d IN ( SELECT d FROM t3 )
+AND t1.d = t2.d
+GROUP BY 1 , 2;
+a	c
+1	2
+drop table t1,t2,t3;
 set optimizer_switch=@subselect_sj_mat_tmp;

=== modified file 'mysql-test/t/subselect_sj_mat.test'
--- a/mysql-test/t/subselect_sj_mat.test	2011-08-09 15:34:26 +0000
+++ b/mysql-test/t/subselect_sj_mat.test	2011-08-29 17:54:16 +0000
@@ -1242,5 +1242,26 @@
 
 drop table t1_1024, t2_1024;
 
+--echo #
+--echo # BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization
+--echo #
+
+CREATE TABLE t1 (c int, d varchar(1), KEY(d)) ;
+INSERT INTO t1 VALUES (2,'x'),(2,'x'),(2,'j'),(2,'c');
+
+CREATE TABLE t2 (a int, d varchar(1)) ;
+INSERT INTO t2 VALUES (1,'x');
+
+CREATE TABLE t3 (d varchar(1)) ;
+INSERT INTO t3 VALUES ('x'),('x'),('j'),('c');
+
+SELECT t2.a, t1.c
+FROM t1, t2
+WHERE t2.d IN ( SELECT d FROM t3 )
+AND t1.d = t2.d
+GROUP BY 1 , 2;
+
+drop table t1,t2,t3;
+
 set optimizer_switch=@subselect_sj_mat_tmp;
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-08-26 21:40:29 +0000
+++ b/sql/sql_select.cc	2011-08-29 17:54:16 +0000
@@ -13716,6 +13716,7 @@
       bool maybe_null=(*cur_group->item)->maybe_null;
       key_part_info->null_bit=0;
       key_part_info->field=  field;
+      key_part_info->fieldnr= field->field_index + 1;
       if (cur_group == group)
         field->key_start.set_bit(0);
       key_part_info->offset= field->offset(table->record[0]);
@@ -13839,6 +13840,7 @@
       key_part_info->field->init(table);
       key_part_info->key_type=FIELDFLAG_BINARY;
       key_part_info->type=    HA_KEYTYPE_BINARY;
+      key_part_info->fieldnr= key_part_info->field->field_index + 1;
       key_part_info++;
     }
     /* Create a distinct key over the columns we are going to return */
@@ -13856,6 +13858,7 @@
 
       key_part_info->offset=   (*reg_field)->offset(table->record[0]);
       key_part_info->length=   (uint16) (*reg_field)->pack_length();
+      key_part_info->fieldnr= (*reg_field)->field_index + 1;
       /* TODO:
         The below method of computing the key format length of the
         key part is a copy/paste from opt_range.cc, and table.cc.



More information about the commits mailing list