Commit 2e6ae6eb authored by Sergey Petrunya's avatar Sergey Petrunya

BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with...

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.
parent 945a595a
...@@ -1562,6 +1562,23 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1, ...@@ -1562,6 +1562,23 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,
left(a1,7) left(a2,7) left(a1,7) left(a2,7)
1 - 01x 2 - 01x 1 - 01x 2 - 01x
drop table t1_1024, t2_1024; 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 optimizer_switch=@subselect_sj_mat_tmp;
set @subselect_mat_test_optimizer_switch_value=null; set @subselect_mat_test_optimizer_switch_value=null;
set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';
......
...@@ -1600,4 +1600,21 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1, ...@@ -1600,4 +1600,21 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,
left(a1,7) left(a2,7) left(a1,7) left(a2,7)
1 - 01x 2 - 01x 1 - 01x 2 - 01x
drop table t1_1024, t2_1024; 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 optimizer_switch=@subselect_sj_mat_tmp;
...@@ -1242,5 +1242,26 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1, ...@@ -1242,5 +1242,26 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,
drop table t1_1024, t2_1024; 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; set optimizer_switch=@subselect_sj_mat_tmp;
...@@ -13716,6 +13716,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, ...@@ -13716,6 +13716,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
bool maybe_null=(*cur_group->item)->maybe_null; bool maybe_null=(*cur_group->item)->maybe_null;
key_part_info->null_bit=0; key_part_info->null_bit=0;
key_part_info->field= field; key_part_info->field= field;
key_part_info->fieldnr= field->field_index + 1;
if (cur_group == group) if (cur_group == group)
field->key_start.set_bit(0); field->key_start.set_bit(0);
key_part_info->offset= field->offset(table->record[0]); key_part_info->offset= field->offset(table->record[0]);
...@@ -13839,6 +13840,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, ...@@ -13839,6 +13840,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
key_part_info->field->init(table); key_part_info->field->init(table);
key_part_info->key_type=FIELDFLAG_BINARY; key_part_info->key_type=FIELDFLAG_BINARY;
key_part_info->type= HA_KEYTYPE_BINARY; key_part_info->type= HA_KEYTYPE_BINARY;
key_part_info->fieldnr= key_part_info->field->field_index + 1;
key_part_info++; key_part_info++;
} }
/* Create a distinct key over the columns we are going to return */ /* Create a distinct key over the columns we are going to return */
...@@ -13856,6 +13858,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, ...@@ -13856,6 +13858,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
key_part_info->offset= (*reg_field)->offset(table->record[0]); key_part_info->offset= (*reg_field)->offset(table->record[0]);
key_part_info->length= (uint16) (*reg_field)->pack_length(); key_part_info->length= (uint16) (*reg_field)->pack_length();
key_part_info->fieldnr= (*reg_field)->field_index + 1;
/* TODO: /* TODO:
The below method of computing the key format length of the The below method of computing the key format length of the
key part is a copy/paste from opt_range.cc, and table.cc. key part is a copy/paste from opt_range.cc, and table.cc.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment