mirror of
https://github.com/MariaDB/server.git
synced 2025-10-29 09:56:12 +01:00
Queries having the following form may cause a crash SELECT t1.a FROM ( SELECT a AS a1 FROM t1 ) dt JOIN t1 ON a1 LIKE EXISTS ( SELECT a + RAND () FROM t1 UNION SELECT a FROM t1); because the table t1 has some JOIN cleanup operations performed prematurely during the subselect. In this particular case, the presence of RAND() makes the subquery uncacheable, necessitating the need to execute the subquery multiple times during join record evaluation. Each time the subquery runs, it creates its own JOIN structure which has references to the table t1. When the subquery completes, JOIN::cleanup and functions called by it result in ha_end_keyread() being called on table t1. However, we are not done with table t1 because the upper level `select t1.a from...` query requires table t1 to be open. To solve this, we make the executor aware of when we're in subqueries like this and delay JOIN cleanup until the end of the query.
13 lines
461 B
Text
13 lines
461 B
Text
CREATE TABLE t1 ( a double, key (a)) ;
|
|
INSERT INTO t1 VALUES (1),(2),(-3);
|
|
SELECT t1.a FROM ( SELECT a AS a1 FROM t1 ) dt
|
|
JOIN t1 ON a1 LIKE EXISTS ( SELECT a + RAND () FROM t1 UNION SELECT a FROM t1) ;
|
|
DROP TABLE t1;
|
|
CREATE TABLE t1 ( a VARCHAR(100), b bool) ;
|
|
INSERT INTO t1 VALUES ('-101',-87),('-95',59),(NULL,48);
|
|
SELECT
|
|
(SELECT 1 FROM (SELECT 1 HAVING rand() ) dt1
|
|
UNION
|
|
SELECT a FROM t1 WHERE b IN (SELECT a FROM t1) LIMIT 1)
|
|
FROM t1;
|
|
DROP TABLE t1;
|