Skip to content

Commit

Permalink
MDEV-30310 Assertion failure in best_access_path upon IN exceeding IN…
Browse files Browse the repository at this point in the history
…_PREDICATE_CONVERSION_THRESHOLD, derived_with_keys=off

The bug was some old code that, without any explanation, reset
PART_KEY_FLAG from fields in temporary tables. This caused
join_tab->key_dependent to not be updated properly, which caused
an assert.
  • Loading branch information
montywi committed Feb 10, 2023
1 parent 4be0bfa commit 02b7735
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 13 deletions.
19 changes: 19 additions & 0 deletions mysql-test/main/derived.result
Original file line number Diff line number Diff line change
Expand Up @@ -1419,5 +1419,24 @@ A
1
drop table t1, duplicates_tbl;
#
# MDEV-30310
# Assertion failure in best_access_path upon IN exceeding
# IN_PREDICATE_CONVERSION_THRESHOLD, derived_with_keys=off
#
CREATE TABLE t1 (l_orderkey int);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (o_orderkey int);
INSERT INTO t2 VALUES (3),(4);
SET IN_PREDICATE_CONVERSION_THRESHOLD= 2;
SET OPTIMIZER_SWITCH='derived_with_keys=on';
SELECT * FROM t1 JOIN t2 ON (l_orderkey = o_orderkey) WHERE l_orderkey IN (1, 2, 3);
l_orderkey o_orderkey
SET OPTIMIZER_SWITCH='derived_with_keys=off';
SELECT * FROM t1 JOIN t2 ON (l_orderkey = o_orderkey) WHERE l_orderkey IN (1, 2, 3);
l_orderkey o_orderkey
SET @@IN_PREDICATE_CONVERSION_THRESHOLD=@@global.IN_PREDICATE_CONVERSION_THRESHOLD;
SET @@OPTIMIZER_SWITCH=@@global.OPTIMIZER_SWITCH;
DROP TABLE t1, t2;
#
# End of 11.0 tests
#
19 changes: 19 additions & 0 deletions mysql-test/main/derived.test
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,25 @@ from t1;

drop table t1, duplicates_tbl;

--echo #
--echo # MDEV-30310
--echo # Assertion failure in best_access_path upon IN exceeding
--echo # IN_PREDICATE_CONVERSION_THRESHOLD, derived_with_keys=off
--echo #

CREATE TABLE t1 (l_orderkey int);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (o_orderkey int);
INSERT INTO t2 VALUES (3),(4);
SET IN_PREDICATE_CONVERSION_THRESHOLD= 2;
SET OPTIMIZER_SWITCH='derived_with_keys=on';
SELECT * FROM t1 JOIN t2 ON (l_orderkey = o_orderkey) WHERE l_orderkey IN (1, 2, 3);
SET OPTIMIZER_SWITCH='derived_with_keys=off';
SELECT * FROM t1 JOIN t2 ON (l_orderkey = o_orderkey) WHERE l_orderkey IN (1, 2, 3);
SET @@IN_PREDICATE_CONVERSION_THRESHOLD=@@global.IN_PREDICATE_CONVERSION_THRESHOLD;
SET @@OPTIMIZER_SWITCH=@@global.OPTIMIZER_SWITCH;
DROP TABLE t1, t2;

--echo #
--echo # End of 11.0 tests
--echo #
2 changes: 1 addition & 1 deletion mysql-test/main/func_group.result
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ CREATE TABLE t1(f1 YEAR(4));
INSERT INTO t1 VALUES (0000),(2001);
(SELECT MAX(f1) FROM t1) UNION (SELECT MAX(f1) FROM t1);
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def MAX(f1) MAX(f1) 13 4 4 Y 32864 0 63
def MAX(f1) MAX(f1) 13 4 4 Y 49248 0 63
MAX(f1)
2001
DROP TABLE t1;
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/main/metadata.result
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ id data data
2 female no
select t1.id from t1 union select t2.id from t2;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id id 246 4 1 Y 32768 0 63
def id id 246 4 1 Y 49152 0 63
id
1
2
Expand All @@ -158,7 +158,7 @@ insert into t1 values (2,'two');
set @arg00=1 ;
select @arg00 FROM t1 where a=1 union distinct select 1 FROM t1 where a=1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def @arg00 @arg00 8 20 1 Y 32768 0 63
def @arg00 @arg00 8 20 1 Y 49152 0 63
@arg00
1
select * from (select @arg00) aaa;
Expand All @@ -168,12 +168,12 @@ def aaa @arg00 @arg00 8 20 1 Y 32768 0 63
1
select 1 union select 1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def 1 1 3 1 1 N 32769 0 63
def 1 1 3 1 1 N 49153 0 63
1
1
select * from (select 1 union select 1) aaa;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def aaa 1 1 3 1 1 N 32769 0 63
def aaa 1 1 3 1 1 N 49153 0 63
1
1
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/mysql_client_test.result
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mysql_stmt_next_result(): 0; field_count: 0
# cat MYSQL_TMP_DIR/test_mdev26145.out.log
# ------------------------------------
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def MAX(a) MAX(a) 3 11 0 Y 32768 0 63
def MAX(a) MAX(a) 3 11 0 Y 49152 0 63
# ------------------------------------


Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/type_enum.result
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,7 @@ t2 CREATE TABLE `t2` (
DROP TABLE t2;
SELECT c_int FROM t1 UNION SELECT c_enum FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def c_int c_int 253 11 0 Y 0 0 8
def c_int c_int 253 11 0 Y 16384 0 8
c_int
SELECT COALESCE(c_int, c_enum) FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/type_set.result
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ t2 CREATE TABLE `t2` (
DROP TABLE t2;
SELECT c_int FROM t1 UNION SELECT c_set FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def c_int c_int 253 33 0 Y 0 0 33
def c_int c_int 253 33 0 Y 16384 0 33
c_int
SELECT COALESCE(c_int, c_set) FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
Expand Down
5 changes: 0 additions & 5 deletions sql/sql_union.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ select_unit::create_result_table(THD *thd_arg, List<Item> *column_types,
return TRUE;

table->keys_in_use_for_query.clear_all();
for (uint i=0; i < table->s->fields; i++)
table->field[i]->flags &= ~(PART_KEY_FLAG | PART_INDIRECT_KEY_FLAG);

if (create_table)
{
Expand Down Expand Up @@ -393,9 +391,6 @@ select_union_recursive::create_result_table(THD *thd_arg,
return true;

incr_table->keys_in_use_for_query.clear_all();
for (uint i=0; i < table->s->fields; i++)
incr_table->field[i]->flags &= ~(PART_KEY_FLAG | PART_INDIRECT_KEY_FLAG);

return false;
}

Expand Down

0 comments on commit 02b7735

Please sign in to comment.