mirror of
https://github.com/MariaDB/server.git
synced 2025-08-24 03:12:20 +02:00

TABLE_LIST parsed from procedure code is transferred into tables to lock for INSERT. The procedure code is CREATE VIEW so its TABLE_LIST is parsed as TL_IGNORE, but same view exists and when existing view is opened mysql_make_view() uses same TABLE_LIST that was initialized from CREATE VIEW and then added as part of prelocking context. So existing view is opened and its table is assigned TL_IGNORE from prelocking context. Finally, INSERT has TABLE_LIST duplication: the one that was parsed from INSERT; the another one came from procedure prelocking, its lock_type came from the procedure code and the real table was found via existing view. The sequence of execution: 1. Procedure p is compiled as part of open_and_process_routine(), its code is parsed and create_or_alter_view_finalize() initializes v TABLE_LIST as TL_IGNORE; 2. Procedure p prelocking adds v to prelocking_ctx with TL_IGNORE; 3. DML prelocking adds v from prelocking_ctx; 4. View is opened, mysql_make_view() assigns t lock_type from v; 5. open_and_lock_tables() attempts to lock t with TL_IGNORE. The fix skips TL_IGNORE at 2. when table list parsed by procedure is added for prelocking: if (my_hash_insert(&m_sptabs, (uchar *)tab)) return FALSE; m_sptabs designation was defined as strictly for prelocking: /** Multi-set representing optimized list of tables to be locked by this routine. Does not include tables which are used by invoked routines. @note For prelocking-free SPs this multiset is constructed too. We do so because the same instance of sp_head may be called both in prelocked mode and in non-prelocked mode. */ HASH m_sptabs; The fix was proposed by Sergei Golubchik <serg@mariadb.org>.
128 lines
3.7 KiB
Text
128 lines
3.7 KiB
Text
drop table if exists t1,t2;
|
|
create table t1 ( n int auto_increment primary key);
|
|
lock tables t1 write;
|
|
insert into t1 values(NULL);
|
|
unlock tables;
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
lock tables t1 write, t1 as t0 read;
|
|
insert into t1 values(NULL);
|
|
unlock tables;
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
lock tables t1 write, t1 as t0 read, t1 as t2 read;
|
|
insert into t1 values(NULL);
|
|
unlock tables;
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
lock tables t1 write, t1 as t0 write, t1 as t2 read;
|
|
insert into t1 values(NULL);
|
|
unlock tables;
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
lock tables t1 write, t1 as t0 write, t1 as t2 read, t1 as t3 read;
|
|
insert into t1 values(NULL);
|
|
unlock tables;
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
lock tables t1 write, t1 as t0 write, t1 as t2 write;
|
|
insert into t1 values(NULL);
|
|
unlock tables;
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
drop table t1;
|
|
CREATE TABLE t1 (a int);
|
|
CREATE TABLE t2 (a int);
|
|
lock tables t1 write,t1 as b write, t2 write, t2 as c read;
|
|
drop table t1,t2;
|
|
CREATE TABLE t1 (a int);
|
|
CREATE TABLE t2 (a int);
|
|
lock tables t1 write,t1 as b write, t2 write, t2 as c read;
|
|
drop table t2,t1;
|
|
unlock tables;
|
|
create temporary table t1(f1 int);
|
|
lock tables t1 write;
|
|
insert into t1 values (1);
|
|
show columns from t1;
|
|
Field Type Null Key Default Extra
|
|
f1 int(11) YES NULL
|
|
insert into t1 values(2);
|
|
drop table t1;
|
|
unlock tables;
|
|
#
|
|
# Bug#19988193 ASSERTION `(*TABLES)->REGINFO.LOCK_TYPE >= TL_READ'
|
|
# FAILED IN LOCK_EXTERNAL
|
|
#
|
|
CREATE TABLE t1(a INT);
|
|
CREATE PROCEDURE p1() CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
# Create trigger calling proc creating view, when view DOES NOT
|
|
# exist already
|
|
CREATE TRIGGER trg_p1_t1 AFTER INSERT ON t1 FOR EACH ROW CALL p1();
|
|
|
|
# Verify that it is possible to lock table
|
|
LOCK TABLES t1 WRITE;
|
|
UNLOCK TABLES;
|
|
|
|
# Fails, as expected
|
|
INSERT INTO t1 VALUES (1);
|
|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger
|
|
|
|
# Make sure v1 already exists
|
|
CREATE VIEW v1 AS SELECT a+1 FROM t1;
|
|
|
|
# Verify that it is possible to lock table
|
|
LOCK TABLES t1 WRITE;
|
|
UNLOCK TABLES;
|
|
|
|
# Verify that we get the expected error when inserting into the table
|
|
INSERT INTO t1 VALUES (1);
|
|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger
|
|
|
|
# Cleanup
|
|
DROP TRIGGER trg_p1_t1;
|
|
DROP PROCEDURE p1;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
#
|
|
# Bug#21198646 ASSERTION FAILED: (*TABLES)->REGINFO.LOCK_TYPE >= TL_READ
|
|
# FILE LOCK.CC, LINE 356
|
|
#
|
|
CREATE TABLE t2(a INT);
|
|
# Create procedure p1 invoking RENAME TABLE
|
|
CREATE PROCEDURE p1() RENAME TABLE t2 TO t3;
|
|
# Create function f1 calling p1
|
|
CREATE FUNCTION f1() RETURNS INT BEGIN CALL p1(); RETURN 1; END $
|
|
# Invoke function f1 and verify that we get the expected error
|
|
SELECT f1();
|
|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger
|
|
# Cleanup
|
|
DROP PROCEDURE p1;
|
|
DROP FUNCTION f1;
|
|
DROP TABLE t2;
|
|
#
|
|
# MDEV-16686 DDL in procedure propagates no locking to tables locked by DML
|
|
#
|
|
create table t (i int);
|
|
create view v as select * from t;
|
|
create procedure p() create view v as select * from t;
|
|
create trigger tr after insert on t for each row call p();
|
|
insert into t values (1), (2);
|
|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger
|
|
drop procedure p;
|
|
drop view v;
|
|
drop table t;
|
|
CREATE TABLE t (a INT);
|
|
CREATE PROCEDURE p() RENAME TABLE t TO t2;
|
|
CREATE TRIGGER tt AFTER INSERT ON t FOR EACH ROW CALL p();
|
|
INSERT INTO t VALUES (0);
|
|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger
|
|
drop procedure p;
|
|
drop table t;
|
|
# End of 10.11 tests
|