summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2022-12-28 19:38:37 +0200
committerMonty <monty@mariadb.org>2022-12-28 21:46:37 +0200
commitdd26d4f430f4149c2f6391cce62c27d3e8c7bef2 (patch)
treea5fc9449c31dff059ea5b567bb060b48011b08c8
parent7b14dff8b1d02bbcb4264eec31827fad6c90111d (diff)
downloadmariadb-git-dd26d4f430f4149c2f6391cce62c27d3e8c7bef2.tar.gz
MDEV-30310 Assertion failure in best_access_path upon IN exceeding IN_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.
-rw-r--r--mysql-test/main/derived.result19
-rw-r--r--mysql-test/main/derived.test19
-rw-r--r--mysql-test/main/func_group.result2
-rw-r--r--mysql-test/main/metadata.result8
-rw-r--r--mysql-test/main/mysql_client_test.result2
-rw-r--r--mysql-test/main/type_enum.result2
-rw-r--r--mysql-test/main/type_set.result2
-rw-r--r--sql/sql_union.cc5
8 files changed, 46 insertions, 13 deletions
diff --git a/mysql-test/main/derived.result b/mysql-test/main/derived.result
index 0eb4f131571..91e85ef4339 100644
--- a/mysql-test/main/derived.result
+++ b/mysql-test/main/derived.result
@@ -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
#
diff --git a/mysql-test/main/derived.test b/mysql-test/main/derived.test
index 3bb52e603f9..5119bca4ea8 100644
--- a/mysql-test/main/derived.test
+++ b/mysql-test/main/derived.test
@@ -1206,5 +1206,24 @@ 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 #
diff --git a/mysql-test/main/func_group.result b/mysql-test/main/func_group.result
index 1e0fd660189..82107de4657 100644
--- a/mysql-test/main/func_group.result
+++ b/mysql-test/main/func_group.result
@@ -1821,7 +1821,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;
diff --git a/mysql-test/main/metadata.result b/mysql-test/main/metadata.result
index 5786e2fd461..ab28cab52cb 100644
--- a/mysql-test/main/metadata.result
+++ b/mysql-test/main/metadata.result
@@ -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
@@ -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;
@@ -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;
diff --git a/mysql-test/main/mysql_client_test.result b/mysql-test/main/mysql_client_test.result
index dbc1feaa23b..e32053e50f3 100644
--- a/mysql-test/main/mysql_client_test.result
+++ b/mysql-test/main/mysql_client_test.result
@@ -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
# ------------------------------------
diff --git a/mysql-test/main/type_enum.result b/mysql-test/main/type_enum.result
index 9e313f5b302..a935e3d63cb 100644
--- a/mysql-test/main/type_enum.result
+++ b/mysql-test/main/type_enum.result
@@ -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
diff --git a/mysql-test/main/type_set.result b/mysql-test/main/type_set.result
index 571e0d36eaf..5821bbae984 100644
--- a/mysql-test/main/type_set.result
+++ b/mysql-test/main/type_set.result
@@ -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
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 188f98aa7dd..e77023f1fd3 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -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)
{
@@ -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;
}