[MDEV-32369] Memory leak when executing PS for query with IN subquery Created: 2023-10-06  Updated: 2023-10-31  Resolved: 2023-10-18

Status: Closed
Project: MariaDB Server
Component/s: Prepared Statements
Affects Version/s: 10.4, 10.5, 10.6, 10.11, 11.0
Fix Version/s: 10.4.32, 10.5.23, 10.6.16, 10.10.7, 10.11.6, 11.0.4, 11.1.3

Type: Bug Priority: Critical
Reporter: Igor Babaev Assignee: Dmitry Shulga
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-14959 Control over memory allocated for SP/PS Stalled
Relates
relates to MDEV-32569 Failure when executing PS for query u... Closed

 Description   

For the following test case a statement memory leak is detected when the server is built with -DWITH_PROTECT_STATEMENT_MEMROOT:BOOL=ON

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;
DROP TABLE t1,t2;

The leak is detected in the function Type_std_attributes::agg_item_set_converter()
with the following memory allocation

       Item_direct_ref_to_item *ref=
         new (thd->mem_root) Item_direct_ref_to_item(thd, *arg);



 Comments   
Comment by Dmitry Shulga [ 2023-10-17 ]

The branch for review is bb-10.4-MDEV-32369

Comment by Oleksandr Byelkin [ 2023-10-17 ]

OK to push

Comment by Igor Babaev [ 2023-10-25 ]

The following test case fails if the server is built with -DWITH_PROTECT_STATEMENT_MEMROOT:BOOL=ON

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;
DROP TABLE t1,t2;

Generated at Thu Feb 08 10:30:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.