Commit 53fde5bb authored by Sergey Petrunya's avatar Sergey Petrunya

BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item*...

BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*)
Fixed Item* Item_equal::get_first(JOIN_TAB *context, Item *field_item) to work correctly in the case where:
- context!= NO_PARTICULAR_TAB, it points to a table within SJ-Materialization nest
- field_item points to an item_equal that has a constant Item_field but does not have any fields
  from tables that are within semi-join nests.


parent 8a8e5a50
...@@ -1811,6 +1811,26 @@ a b c ...@@ -1811,6 +1811,26 @@ a b c
4 4 2 4 4 2
4 4 4 4 4 4
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*)
#
CREATE TABLE t1 ( a VARCHAR(3) );
CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) );
INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron');
EXPLAIN
SELECT * FROM
( SELECT * FROM t1 ) AS alias1,
t2 AS alias2
WHERE b = a AND a IN (
SELECT alias3.c
FROM t2 AS alias3, t2 AS alias4
WHERE alias4.c = alias3.b
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2
3 MATERIALIZED alias4 index c c 11 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
# This must be at the end: # This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp; set optimizer_switch=@subselect_sj_mat_tmp;
set join_cache_level=@save_join_cache_level; set join_cache_level=@save_join_cache_level;
......
...@@ -1849,6 +1849,24 @@ a b c ...@@ -1849,6 +1849,24 @@ a b c
4 4 2 4 4 2
4 4 4 4 4 4
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*)
#
CREATE TABLE t1 ( a VARCHAR(3) );
CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) );
INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron');
EXPLAIN
SELECT * FROM
( SELECT * FROM t1 ) AS alias1,
t2 AS alias2
WHERE b = a AND a IN (
SELECT alias3.c
FROM t2 AS alias3, t2 AS alias4
WHERE alias4.c = alias3.b
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
DROP TABLE t1,t2;
# This must be at the end: # This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp; set optimizer_switch=@subselect_sj_mat_tmp;
set join_cache_level=@save_join_cache_level; set join_cache_level=@save_join_cache_level;
...@@ -1510,6 +1510,25 @@ SELECT * FROM t1 LEFT JOIN t2 ON ( a = b ) ...@@ -1510,6 +1510,25 @@ SELECT * FROM t1 LEFT JOIN t2 ON ( a = b )
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo #
--echo # BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*)
--echo #
CREATE TABLE t1 ( a VARCHAR(3) );
CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) );
INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron');
EXPLAIN
SELECT * FROM
( SELECT * FROM t1 ) AS alias1,
t2 AS alias2
WHERE b = a AND a IN (
SELECT alias3.c
FROM t2 AS alias3, t2 AS alias4
WHERE alias4.c = alias3.b
);
DROP TABLE t1,t2;
--echo # This must be at the end: --echo # This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp; set optimizer_switch=@subselect_sj_mat_tmp;
set join_cache_level=@save_join_cache_level; set join_cache_level=@save_join_cache_level;
......
...@@ -5853,13 +5853,15 @@ Item* Item_equal::get_first(JOIN_TAB *context, Item *field_item) ...@@ -5853,13 +5853,15 @@ Item* Item_equal::get_first(JOIN_TAB *context, Item *field_item)
if (emb_nest && emb_nest->sj_mat_info && emb_nest->sj_mat_info->is_used) if (emb_nest && emb_nest->sj_mat_info && emb_nest->sj_mat_info->is_used)
{ {
/* /*
It's a field from an materialized semi-join. We can substitute it only It's a field from an materialized semi-join. We can substitute it for
for a field from the same semi-join. Find the first of such items. - a constant item
- a field from the same semi-join
Find the first of such items:
*/ */
while ((item= it++)) while ((item= it++))
{ {
if (it.get_curr_field()->table->pos_in_table_list->embedding == emb_nest) if (item->const_item() ||
it.get_curr_field()->table->pos_in_table_list->embedding == emb_nest)
{ {
/* /*
If we found given field then return NULL to avoid unnecessary If we found given field then return NULL to avoid unnecessary
......
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