Commit 0d9db6b
committed
MDEV-37243: SP memory root protection disappears after a metadata change
Problem:
When a stored routine involes a cursor and metadata of table on which
the cursor is defined changes, the SP instruction has to be reparsed.
For ex:
CREATE OR REPLACE TABLE t1 (a INT);
CREATE OR REPLACE FUNCTION f1() RETURNS INT
BEGIN
DECLARE vc INT DEFAULT 0;
DECLARE cur CURSOR FOR SELECT a FROM t1;
OPEN cur;
FETCH cur INTO vc;
CLOSE cur;
RETURN vc;
END;
SELECT f1(); - first execution, sp-mem_root marked read-only on exec
SELECT f1(); - read-only sp-mem_root
ALTER TABLE t1 MODIFY a TEXT; - metadta change
SELECT f1(); - reparse, rerun instr and mark new mem_root read-only
sp_lex_instr is re-parsed after the metadata change, which sets up a
new mem_root for reparsing. Once the instruction is re-parsed and
re-executed(via reset_lex_and_exec_core), the new memory root assigned
to the instruction being reparsed remains writable. This violates the
invariant of SP memory root protection.
Fix:
Mark the new memory root created for reparsing with read-only flag,
after the first execution of the SP instruction.1 parent e2f91f4 commit 0d9db6b
1 file changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
520 | 531 | | |
| 532 | + | |
521 | 533 | | |
522 | 534 | | |
523 | 535 | | |
| |||
0 commit comments