File: trigger-single-table.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 (71 lines) | stat: -rw-r--r-- 1,676 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
# trigger-single-table.test

# Place all trigger tests that must be run with a single table instance here.
# These are tests that are used to provoke errors when two consecutive
# sessions are forced to run with the same table entry, hence they will
# use the same triggers attached to that table.

# Save the initial number of concurrent sessions
--source include/count_sessions.inc

--echo # Bug#34009876: When table_open_cache_instances = 1, the result of
--echo #               CONNECTION_ID() called on the trigger is wrong.

--echo Must be 1
SELECT @@GLOBAL.table_open_cache_instances;

DELIMITER //;
CREATE FUNCTION transaction_id()
RETURNS BIGINT
BEGIN
  RETURN connection_id();
END;
//
DELIMITER ;//

CREATE TABLE t1
(
  id  BIGINT NOT NULL PRIMARY KEY,
  tr1 BIGINT NOT NULL,
  tr2 BIGINT NOT NULL
);

DELIMITER //;
CREATE TRIGGER t1_insert_trigger
BEFORE INSERT ON t1 FOR EACH ROW
BEGIN
    SET NEW.tr1 = connection_id();
    SET NEW.tr2 = transaction_id();
END;
//
DELIMITER ;//

INSERT INTO t1(id) VALUES (1);
SELECT id,
       tr1 = connection_id() AS "tr1 valid",
       tr2 = connection_id() AS "tr2 valid"
FROM t1
WHERE id=1;

--enable_connect_log
connect (conn1, localhost, root, , test);
connection conn1;

INSERT INTO t1(id) VALUES (2);
SELECT id,
       tr1 = connection_id() AS "tr1 valid", 
       tr2 = connection_id() AS "tr2 valid"
FROM t1
WHERE id=2;

# Verify that we got different connection ids in the two inserts
SELECT COUNT(DISTINCT tr1), COUNT(DISTINCT tr2) FROM t1;

disconnect conn1;
connection default;

DROP TABLE t1;
DROP FUNCTION transaction_id;

# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc