mariadb/mysql-test/main/ps_mem_leaks.test
2024-10-29 14:20:03 +01:00

367 lines
9.2 KiB
Text

# This file contains test cases that use the memory leaks detection feature
# provided by the cmake build option -DWITH_PROTECT_STATEMENT_MEMROOT
--source include/not_embedded.inc
# The cmake option -DWITH_PROTECT_STATEMENT_MEMROOT is used only
# for debug build
--source include/have_debug.inc
--source include/have_partition.inc
--echo #
--echo # MDEV-32369: Memory leak when executing PS for query with IN subquery
--echo #
CREATE TABLE t1 (a VARCHAR(10)) ENGINE=MYISAM;
CREATE TABLE t2 (b VARCHAR(10) CHARACTER SET utf8) ENGINE=MYISAM;
INSERT INTO t1 VALUES ('b'), ('a'), ('c');
INSERT INTO t2 VALUES ('c'), ('d'), ('b');
PREPARE stmt FROM "SELECT t1.a FROM t1 WHERE t1.a IN (SELECT t2.b FROM t2)";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DELETE FROM t1;
DELETE FROM t2;
INSERT INTO t1 VALUES ('b');
INSERT INTO t2 VALUES ('b');
PREPARE stmt FROM "SELECT t1.a FROM t1 WHERE t1.a IN (SELECT t2.b FROM t2)";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2;
--echo #
--echo # MDEV-32569: Failure when executing PS for query using IN subquery
--echo #
CREATE TABLE t1 (a varchar(10)) ENGINE=MYISAM;
CREATE TABLE t2 (b varchar(10) CHARACTER SET utf8) ENGINE=MYISAM;
INSERT INTO t1 VALUES ('b');
INSERT INTO t2 VALUES ('b');
PREPARE stmt FROM
"SELECT STRAIGHT_JOIN t1.a FROM t1 WHERE t1.a IN (SELECT t2.b FROM t2)";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1,t2;
--echo #
--echo # MDEV-32733: Two JSON related tests running in PS mode fail on server
--echo # built with -DWITH_PROTECT_STATEMENT_MEMROOT=YES
--echo #
PREPARE stmt FROM "select json_contains_path('{\"key1\":1}', 'oNE', '$.key2[1]') as exp";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
--echo #
--echo # MDEV-32466: Potential memory leak on execuing of create view statement
--echo #
--delimiter |
CREATE FUNCTION f1 () RETURNS VARCHAR(1)
BEGIN
DECLARE rec1 ROW TYPE OF v1;
SELECT z INTO rec1 FROM v1;
RETURN 1;
END|
--delimiter ;
CREATE FUNCTION f2 () RETURNS VARCHAR(1) RETURN '!';
CREATE VIEW v1 AS SELECT f2() z;
PREPARE stmt FROM "SELECT f1()";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
# Clean up
DROP FUNCTION f1;
DROP VIEW v1;
DROP FUNCTION f2;
--echo #
--echo # MDEV-32867: ASAN errors in Item_func_json_contains_path::val_int upon PS execution
--echo #
CREATE TABLE t1 (f BLOB) ENGINE=MyISAM;
PREPARE stmt FROM "SELECT * FROM t1 WHERE JSON_EXISTS(JSON_ARRAY('[true,1234567890]'), '$**.*') != JSON_CONTAINS_PATH(JSON_INSERT('{}', '$[1]', NULL), 'all', '$[1]')";
EXECUTE stmt;
# Clean up
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
--echo # End of 10.4 tests
--echo #
--echo # MDEV-34447: Memory leakage is detected on running the test main.ps against the server 11.1
--echo #
CREATE TABLE t1 (id INT, value INT);
CREATE TABLE t2 (id INT);
PREPARE stmt FROM 'UPDATE t1 SET value = (SELECT 1 FROM t2 WHERE id = t1.id)';
EXECUTE stmt;
INSERT INTO t1 VALUES (1,10),(2,10),(3,10);
INSERT INTO t2 VALUES (1),(2);
EXECUTE stmt;
SELECT * FROM t1;
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2;
--echo # Memory leak also could take place on running the DELETE statement
--echo # with the LIMIT clause. Check it.
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 (c1) VALUES (1), (2), (3);
CREATE PROCEDURE p1(p1 INT)
DELETE FROM t1 LIMIT p1;
CALL p1(0);
CALL p1(1);
CALL p1(2);
--echo # Clean up
DROP TABLE t1;
DROP PROCEDURE p1;
--echo #
--echo # MDEV-34757: assertion of (mem_root->flags & 4) == 0 fails in 2nd ps execution with partition pruning
--echo #
# same as the first MDEV-34444 testcase but with explain
CREATE TABLE t1 (id INT, value INT);
CREATE TABLE t2 (id INT);
PREPARE stmt FROM 'EXPLAIN UPDATE t1 SET value = (SELECT 1 FROM t2 WHERE id = t1.id)';
# we are testing 2nd ps assertion failure, not explain output, which
# may vary from version to version
--disable_result_log
EXECUTE stmt;
--enable_result_log
INSERT INTO t1 VALUES (1,10),(2,10),(3,10);
INSERT INTO t2 VALUES (1),(2);
--disable_result_log
EXECUTE stmt;
--enable_result_log
SELECT * FROM t1;
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2;
# 2nd ps mem leak; partition pruning
set @var1=5;
set @var2=4;
create table t1 (a int) partition by list(a) (
partition p0 values in (null,1,2),
partition p1 values in (3,4)
);
create table t2 (a int);
insert into t1 values (1),(2),(3),(4);
insert into t2 values (4);
PREPARE stmt FROM 'UPDATE t1 t1 SET a = (SELECT 1 FROM t2 WHERE a = t1.a) where a = ?';
execute stmt using @var1;
select * from t1;
execute stmt using @var2;
select * from t1;
deallocate prepare stmt;
drop table t1, t2;
# same but with explain
set @var1=5;
set @var2=4;
create table t1 (a int) partition by list(a) (
partition p0 values in (null,1,2),
partition p1 values in (3,4)
);
create table t2 (a int);
insert into t1 values (1),(2),(3),(4);
insert into t2 values (4);
PREPARE stmt FROM 'EXPLAIN UPDATE t1 t1 SET a = (SELECT 1 FROM t2 WHERE a = t1.a) where a = ?';
execute stmt using @var1;
select * from t1;
execute stmt using @var2;
select * from t1;
deallocate prepare stmt;
drop table t1, t2;
# top level impossible where
set @var1=1;
set @var2=2;
CREATE TABLE t1 ( id INT(10), value INT(10) );
CREATE TABLE t2 ( id INT(10) );
insert into t1 values (1,10),(2,10),(3,10);
insert into t2 values (1),(2);
PREPARE stmt FROM 'UPDATE t1 t1 SET value = (SELECT 1 FROM t2 WHERE id = t1.id) WHERE ?=?';
execute stmt using @var1, @var2;
execute stmt using @var1, @var1;
deallocate prepare stmt;
DROP TABLE t1,t2;
# top level impossible where, with explain
set @var1=1;
set @var2=2;
CREATE TABLE t1 ( id INT(10), value INT(10) );
CREATE TABLE t2 ( id INT(10) );
insert into t1 values (1,10),(2,10),(3,10);
insert into t2 values (1),(2);
PREPARE stmt FROM 'EXPLAIN UPDATE t1 t1 SET value = (SELECT 1 FROM t2 WHERE id = t1.id) WHERE ?=?';
execute stmt using @var1, @var2;
execute stmt using @var1, @var1;
deallocate prepare stmt;
DROP TABLE t1,t2;
# Now we do delete instead of update
# same as the second MDEV-34447 testcase but with explain
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 (c1) VALUES (1), (2), (3);
CREATE PROCEDURE p1(p1 INT)
EXPLAIN DELETE FROM t1 LIMIT p1;
CALL p1(0);
CALL p1(1);
CALL p1(2);
--echo # Clean up
DROP TABLE t1;
DROP PROCEDURE p1;
# partition pruning
set @var1=5;
set @var2=4;
create table t1 (a int) partition by list(a) (
partition p0 values in (1,2),
partition p1 values in (3,4)
);
create table t2 (a int);
insert into t1 values (1),(2),(3),(4);
insert into t2 values (4);
PREPARE stmt FROM 'DELETE FROM t1 where a = ?';
execute stmt using @var1;
select * from t1;
execute stmt using @var2;
select * from t1;
deallocate prepare stmt;
drop table t1, t2;
# same but with explain
set @var1=5;
set @var2=4;
create table t1 (a int) partition by list(a) (
partition p0 values in (1,2),
partition p1 values in (3,4)
);
create table t2 (a int);
insert into t1 values (1),(2),(3),(4);
insert into t2 values (4);
PREPARE stmt FROM 'EXPLAIN DELETE FROM t1 where a = ?';
execute stmt using @var1;
select * from t1;
execute stmt using @var2;
select * from t1;
deallocate prepare stmt;
drop table t1, t2;
# top level impossible where
set @var1=1;
set @var2=2;
CREATE TABLE t1 ( id INT(10), value INT(10) );
CREATE TABLE t2 ( id INT(10) );
insert into t1 values (1,10),(2,10),(3,10);
insert into t2 values (1),(2);
PREPARE stmt FROM 'DELETE FROM t1 WHERE ?=?';
execute stmt using @var1, @var2;
execute stmt using @var1, @var1;
deallocate prepare stmt;
DROP TABLE t1,t2;
# top level impossible where, with explain
set @var1=1;
set @var2=2;
CREATE TABLE t1 ( id INT(10), value INT(10) );
CREATE TABLE t2 ( id INT(10) );
insert into t1 values (1,10),(2,10),(3,10);
insert into t2 values (1),(2);
PREPARE stmt FROM 'EXPLAIN DELETE FROM t1 WHERE ?=?';
execute stmt using @var1, @var2;
execute stmt using @var1, @var1;
deallocate prepare stmt;
DROP TABLE t1,t2;
--echo #
--echo # MDEV-33858: Assertion `(mem_root->flags & 4) == 0' fails on 2nd execution of PS with -DWITH_PROTECT_STATEMENT_MEMROOT=ON
--echo #
CREATE TABLE t (a INT);
INSERT INTO t VALUES (1),(2); # Optional, fails either way
PREPARE stmt FROM "UPDATE t SET a = 0 LIMIT ?";
EXECUTE stmt USING 0;
EXECUTE stmt USING 1;
# CLeanup
DROP TABLE t;
--echo #
--echo # MDEV-35249: Assertion `(mem_root->flags & 4) == 0' failed in convert_subq_to_jtbm
--echo #
CREATE TABLE t (a INT, b INT, c INT);
INSERT INTO t VALUES (1,2,3),(4,5,6);
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t;
CREATE VIEW v2 AS SELECT * FROM v1;
PREPARE stmt FROM 'UPDATE t SET a = 0 WHERE b IN (SELECT c FROM v2)';
EXECUTE stmt;
EXECUTE stmt;
# Cleanup
DROP VIEW v2;
DROP VIEW v1;
DROP TABLE t;
--echo # End of 10.5 tests
--echo #
--echo # MDEV-33769: Memory leak found in the test main.rownum run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT
--echo #
CREATE OR REPLACE TABLE t1(a INT);
PREPARE stmt FROM 'SELECT 1 FROM t1 WHERE ROWNUM() < 2';
EXECUTE stmt;
EXECUTE stmt;
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
PREPARE stmt FROM 'SELECT * FROM t1 WHERE ROWNUM() < ?';
--echo # Expected output is two rows (1), (2)
EXECUTE stmt USING 3;
--echo # Expected output is one row (1)
EXECUTE stmt USING 2;
--echo # Expected output is three rows (1), (2), (3)
EXECUTE stmt USING 4;
--echo # Clean up
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
--echo # End of 10.6 tests