diff options
author | igor@rurik.mysql.com <> | 2006-10-31 17:31:56 -0800 |
---|---|---|
committer | igor@rurik.mysql.com <> | 2006-10-31 17:31:56 -0800 |
commit | 2a7acba7e10197ec4a651ae828ff51c0a2ff4747 (patch) | |
tree | b8cf0e80a37eba77a6cccf9e41a8871266533675 /mysql-test/t/subselect.test | |
parent | 17eb0b353e5a112e1d0005b71190c1e3278e0583 (diff) | |
download | mariadb-git-2a7acba7e10197ec4a651ae828ff51c0a2ff4747.tar.gz |
Fixed bug #21727.
This is a performance issue for queries with subqueries evaluation
of which requires filesort.
Allocation of memory for the sort buffer at each evaluation of a
subquery may take a significant amount of time if the buffer is rather big.
With the fix we allocate the buffer at the first evaluation of the
subquery and reuse it at each subsequent evaluation.
Diffstat (limited to 'mysql-test/t/subselect.test')
-rw-r--r-- | mysql-test/t/subselect.test | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 6d5082c360b..2f3ae3347e8 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -2426,3 +2426,40 @@ SELECT ( FROM t1 t2 GROUP BY t2.a; DROP TABLE t1,t2; + +# +# Bug #21727: Correlated subquery that requires filesort: +# slow with big sort_buffer_size +# + +CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)); +CREATE TABLE t2 (x int auto_increment, y int, z int, + PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)); + +disable_query_log; +let $1=3000; +while ($1) +{ + eval INSERT INTO t1(a) VALUES(RAND()*1000); + eval SELECT MAX(b) FROM t1 INTO @id; + let $2=10; + while ($2) + { + eval INSERT INTO t2(y,z) VALUES(@id,RAND()*1000); + dec $2; + } + dec $1; +} +enable_query_log; + +SET SESSION sort_buffer_size = 32 * 1024; +SELECT SQL_NO_CACHE COUNT(*) + FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c + FROM t1) t; + +SET SESSION sort_buffer_size = 8 * 1024 * 1024; +SELECT SQL_NO_CACHE COUNT(*) + FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c + FROM t1) t; + +DROP TABLE t1,t2; |