Commit a775788
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 d3767f9 commit a775788
1 file changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
537 | 548 | | |
| 549 | + | |
538 | 550 | | |
539 | 551 | | |
540 | 552 | | |
| |||
0 commit comments