File: create_table_select.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (113 lines) | stat: -rw-r--r-- 3,308 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--echo # Bug #28523025: INNODB: ASSERTION FAILURE:
--echo #                LOCK0LOCK.CC:1468:LOCK_REC_GET_REC_NOT_GAP(LOCK)

--source include/have_debug_sync.inc

# Minimal reproduction of original issue:
CREATE TABLE t0(a INT PRIMARY KEY);
CREATE VIEW v0 AS SELECT a FROM t0;
DROP TABLE t0;
CREATE TABLE t0(a int) REPLACE SELECT 0 AS a;
DROP TABLE t0;
DROP VIEW v0;

# A version in which there are conflicting rows and REPLACE is used:
CREATE TABLE t0(a INT, b INT);
INSERT INTO t0 VALUES (1,1), (1,2), (2,2);

CREATE TABLE t1(a INT, b INT);
CREATE VIEW v0 AS SELECT b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(
  a INT PRIMARY KEY,
  b INT
) REPLACE SELECT a,b FROM t0 ORDER BY a,b;
SELECT * FROM t1;
DROP TABLE t1;
DROP TABLE t0;
DROP VIEW v0;

# A version in which there are conflicting rows and IGNORE is used:
CREATE TABLE t0(a INT, b INT);
INSERT INTO t0 VALUES (1,1), (1,2), (2,2);

CREATE TABLE t1(a INT, b INT);
CREATE VIEW v0 AS SELECT b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(
  a INT PRIMARY KEY,
  b INT
) IGNORE SELECT a,b FROM t0 ORDER BY a,b;
SELECT * FROM t1;
DROP TABLE t1;
DROP TABLE t0;
DROP VIEW v0;

# A version in which there are conflicting rows and no modifier is used:
CREATE TABLE t0(a INT, b INT);
INSERT INTO t0 VALUES (1,1), (1,2), (2,2);

CREATE TABLE t1(a INT, b INT);
CREATE VIEW v0 AS SELECT b FROM t1;
DROP TABLE t1;
--error ER_DUP_ENTRY
CREATE TABLE t1(
  a INT PRIMARY KEY,
  b INT
) SELECT a,b FROM t0 ORDER BY a,b;
DROP TABLE t0;
DROP VIEW v0;

# Demonstration that correct type of locks (X instead of S followed by X) is
# taken for REPLACE and IODKU, regardless of whether or not there is a TRIGGER
# which causes a "subquery" with it's own lifecycle, even if this "subquery"
# also operates on the same table.
# This is to demonstrate that REPLCAE/IODKU flags should be tracked not per
# per trx, nor per table, not even per <trx,table> pair, but rather per cursor.
# In this test the exact list of locks reported by performance_schema is not as
# important, as the fact the list for i=1 is the same as list for i=2, which
# means that the "subquery" did not confuse the logic of the outer query.
# The only allowed difference between the two lists is the IS table lock
# and S lock on supremum pseudo-record taken by "subquery" intself.
--let i=1
while ($i <= 2)
{
    --let table=t$i

    eval CREATE TABLE $table(a INT NOT NULL PRIMARY KEY, b INT NOT NULL UNIQUE);
    eval INSERT INTO $table (a,b) VALUES
        (1,10), (2,20), (3,30), (4,40), (5,50), (6,60), (8,80), (10,100);

    if ($i==2)
    {
        CREATE TABLE tt (i INT) ENGINE = InnoDB;
        CREATE TRIGGER t2_bi BEFORE INSERT ON t2
            FOR EACH ROW
                INSERT INTO tt SELECT a as i FROM t2 WHERE a=10000;
    }

    BEGIN;

    --eval REPLACE INTO $table (a,b) VALUES (2,13)
    --eval INSERT INTO $table (a,b) VALUES (4,43) ON DUPLICATE KEY UPDATE b=43

    --eval REPLACE INTO $table (a,b) VALUES (7,60)
    --eval INSERT INTO $table (a,b) VALUES (9,80) ON DUPLICATE KEY UPDATE a=9


    eval SELECT index_name,lock_type,lock_mode,lock_status,lock_data
    FROM performance_schema.data_locks
    WHERE object_schema='test' AND object_name = '$table'
    ORDER BY 1,2,3,4,5;


    ROLLBACK;
    --inc $i
}

DROP TRIGGER t2_bi;
DROP TABLE tt;
DROP TABLE t2;
DROP TABLE t1;