Commit 14798d3c authored by Monty's avatar Monty

MDEV-23159 Assertion `table_share->tmp_table != NO_TMP_TABLE || m_lock_type != 2'...

The problem was that opt_sum_query() was, as part of MIN/MAX optimization,
doing read operations on constant tables that where already closed

Fixed by ensuring we don't try to read from tables that are closed.
parent 1e778a3b
......@@ -31,3 +31,36 @@ select * from t2;
f1 f2
3 qux
DROP TABLE t1, t2;
#
# MDEV-23159 Assertion `table_share->tmp_table != NO_TMP_TABLE ||
# m_lock_type != 2' + SIGSEGV in trnman_can_read_from
# (on optimized builds)
#
SET @org_sql_mode=@@SQL_MODE;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=Aria ROW_FORMAT=COMPRESSED;
INSERT INTO t1 VALUES(1);
CREATE TEMPORARY TABLE t2(b INT);
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT MAX(a) FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 Using index
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
DROP TABLE t1,t2;
SET SQL_MODE='';
CREATE TABLE t1 (c INT PRIMARY KEY) ENGINE=Aria;
CREATE TABLE t2 (d INT);
INSERT INTO t1 VALUES (1);
SELECT c FROM t1 WHERE (c) IN (SELECT MIN(c) FROM t2);
c
DROP TABLE t1,t2;
USE test;
SET SQL_MODE='ONLY_FULL_GROUP_BY';
CREATE TABLE t3 (c1 DECIMAL(1,1) PRIMARY KEY,c2 DATE,c3 NUMERIC(10) UNSIGNED) ENGINE=Aria;
CREATE TABLE t2 (f1 INTEGER ) ENGINE=Aria;
INSERT INTO t3 VALUES (0,0,0);
SELECT c1 FROM t3 WHERE (c1) IN (SELECT MIN(DISTINCT c1) FROM t2);
c1
DROP TABLE t2,t3;
SET @@SQL_MODE=@org_sql_mode;
#
# End of 10.3 tests
#
......@@ -40,3 +40,36 @@ INSERT IGNORE INTO t1 VALUES (1),(2);
CREATE OR REPLACE TABLE t2 ENGINE=Aria AS SELECT SUM(a) AS f1, IFNULL( 'qux', ExtractValue( 'foo', 'bar' ) ) AS f2 FROM t1;
select * from t2;
DROP TABLE t1, t2;
--echo #
--echo # MDEV-23159 Assertion `table_share->tmp_table != NO_TMP_TABLE ||
--echo # m_lock_type != 2' + SIGSEGV in trnman_can_read_from
--echo # (on optimized builds)
--echo #
SET @org_sql_mode=@@SQL_MODE;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=Aria ROW_FORMAT=COMPRESSED;
INSERT INTO t1 VALUES(1);
CREATE TEMPORARY TABLE t2(b INT);
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT MAX(a) FROM t2);
DROP TABLE t1,t2;
SET SQL_MODE='';
CREATE TABLE t1 (c INT PRIMARY KEY) ENGINE=Aria;
CREATE TABLE t2 (d INT);
INSERT INTO t1 VALUES (1);
SELECT c FROM t1 WHERE (c) IN (SELECT MIN(c) FROM t2);
DROP TABLE t1,t2;
USE test;
SET SQL_MODE='ONLY_FULL_GROUP_BY';
CREATE TABLE t3 (c1 DECIMAL(1,1) PRIMARY KEY,c2 DATE,c3 NUMERIC(10) UNSIGNED) ENGINE=Aria;
CREATE TABLE t2 (f1 INTEGER ) ENGINE=Aria;
INSERT INTO t3 VALUES (0,0,0);
SELECT c1 FROM t3 WHERE (c1) IN (SELECT MIN(DISTINCT c1) FROM t2);
DROP TABLE t2,t3;
SET @@SQL_MODE=@org_sql_mode;
--echo #
--echo # End of 10.3 tests
--echo #
......@@ -399,20 +399,28 @@ int opt_sum_query(THD *thd,
break;
}
longlong info_limit= 1;
error= 0;
table->file->info_push(INFO_KIND_FORCE_LIMIT_BEGIN, &info_limit);
if (likely(!(error= table->file->ha_index_init((uint) ref.key, 1))))
if (!table->const_table)
{
if (likely(!(error= table->file->ha_index_init((uint) ref.key,
1))))
error= (is_max ?
get_index_max_value(table, &ref, range_fl) :
get_index_min_value(table, &ref, item_field, range_fl,
prefix_len));
}
/* Verify that the read tuple indeed matches the search key */
if (!error &&
reckey_in_range(is_max, &ref, item_field->field,
conds, range_fl, prefix_len))
error= HA_ERR_KEY_NOT_FOUND;
if (!table->const_table)
{
table->file->ha_end_keyread();
table->file->ha_index_end();
}
table->file->info_push(INFO_KIND_FORCE_LIMIT_END, NULL);
if (error)
{
......
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