-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathfk_read_committed
119 lines (106 loc) · 3.44 KB
/
fk_read_committed
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
114
115
116
117
118
119
# LogicTest: local
statement ok
CREATE TABLE jars (j INT PRIMARY KEY)
statement ok
CREATE TABLE cookies (c INT PRIMARY KEY, j INT REFERENCES jars (j))
statement ok
SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED
# Foreign key checks of the parent require durable shared locking under weaker
# isolation levels.
query T
EXPLAIN (OPT) INSERT INTO cookies VALUES (1, 1)
----
insert cookies
├── values
│ └── (1, 1)
└── f-k-checks
└── f-k-checks-item: cookies(j) -> jars(j)
└── anti-join (lookup jars)
├── lookup columns are key
├── locking: for-share,durability-guaranteed
├── with-scan &1
└── filters (true)
# Under serializable isolation, locking is not required, unless
# enable_implicit_fk_locking is true.
statement ok
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE
query T
EXPLAIN (OPT) INSERT INTO cookies VALUES (1, 1)
----
insert cookies
├── values
│ └── (1, 1)
└── f-k-checks
└── f-k-checks-item: cookies(j) -> jars(j)
└── anti-join (lookup jars)
├── lookup columns are key
├── with-scan &1
└── filters (true)
statement ok
SET enable_implicit_fk_locking = true
query T
EXPLAIN (OPT) INSERT INTO cookies VALUES (1, 1)
----
insert cookies
├── values
│ └── (1, 1)
└── f-k-checks
└── f-k-checks-item: cookies(j) -> jars(j)
└── anti-join (lookup jars)
├── lookup columns are key
├── locking: for-share
├── with-scan &1
└── filters (true)
statement ok
RESET enable_implicit_fk_locking
statement ok
COMMIT
query T
EXPLAIN (OPT) UPDATE cookies SET j = 2 WHERE c = 1
----
update cookies
├── project
│ ├── scan cookies
│ │ └── constraint: /5: [/1 - /1]
│ └── projections
│ └── 2
└── f-k-checks
└── f-k-checks-item: cookies(j) -> jars(j)
└── anti-join (lookup jars)
├── lookup columns are key
├── locking: for-share,durability-guaranteed
├── with-scan &1
└── filters (true)
# Foreign key checks of the child do not require locking.
query T
EXPLAIN (OPT) UPDATE jars SET j = j + 4
----
update jars
├── project
│ ├── scan jars
│ └── projections
│ └── jars.j + 4
└── f-k-checks
└── f-k-checks-item: cookies(j) -> jars(j)
└── project
└── inner-join (hash)
├── except-all
│ ├── with-scan &1
│ └── with-scan &1
├── distinct-on
│ └── scan cookies
└── filters
└── j = cookies.j
query T
EXPLAIN (OPT) DELETE FROM jars WHERE j = 1
----
delete jars
├── scan jars
│ └── constraint: /4: [/1 - /1]
└── f-k-checks
└── f-k-checks-item: cookies(j) -> jars(j)
└── semi-join (hash)
├── with-scan &1
├── scan cookies
└── filters
└── j = cookies.j