Skip to content

Commit 51cea65

Browse files
committed
opt: add additional read-committed fk cascade testing
When backporting #150291, it was noted that our ccl test had no delete fast path test case and that the execbuilder logic test ommitted a non-fast path test case. We didn't hold up backport for these test cases, but we are adding them now. Informs: #150291 Release note: None
1 parent afef2d2 commit 51cea65

File tree

2 files changed

+173
-17
lines changed

2 files changed

+173
-17
lines changed

pkg/ccl/logictestccl/testdata/logic_test/fk_read_committed

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,45 @@ SELECT * FROM child_150282;
195195
----
196196
4 4
197197

198+
# Test the fk delete fast path
199+
statement ok
200+
DELETE FROM parent_150282;
201+
202+
statement ok
203+
DELETE FROM child_150282;
204+
205+
statement ok
206+
INSERT INTO parent_150282 VALUES (1, 2, 3);
207+
208+
user root
209+
210+
statement ok
211+
BEGIN ISOLATION LEVEL READ COMMITTED;
212+
213+
statement ok
214+
SELECT 1;
215+
216+
statement async fk_delete
217+
WITH sleep AS (SELECT pg_sleep(1)) DELETE FROM parent_150282 WHERE p = 1;
218+
219+
user testuser
220+
221+
statement ok
222+
INSERT INTO child_150282 VALUES (4, 1);
223+
224+
user root
225+
226+
awaitstatement fk_delete
227+
228+
statement ok
229+
COMMIT;
230+
231+
query III
232+
SELECT * FROM parent_150282;
233+
----
234+
235+
query II
236+
SELECT * FROM child_150282;
237+
----
238+
198239
subtest end

pkg/sql/opt/exec/execbuilder/testdata/fk_read_committed

Lines changed: 132 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LogicTest: local-read-committed
22

33
statement ok
4-
CREATE TABLE jars (j INT PRIMARY KEY)
4+
CREATE TABLE jars (j INT PRIMARY KEY, i INT, UNIQUE INDEX (i), FAMILY (j, i))
55

66
statement ok
77
CREATE TABLE cookies (c INT PRIMARY KEY, j INT REFERENCES jars (j), FAMILY (c, j))
@@ -231,16 +231,17 @@ vectorized: true
231231
│ │ set: j
232232
│ │
233233
│ └── • buffer
234-
│ │ columns: (j, j_new)
234+
│ │ columns: (j, i, j_new)
235235
│ │ label: buffer 1
236236
│ │
237237
│ └── • render
238-
│ │ columns: (j, j_new)
238+
│ │ columns: (j, i, j_new)
239239
│ │ render j_new: j + 4
240240
│ │ render j: j
241+
│ │ render i: i
241242
│ │
242243
│ └── • scan
243-
│ columns: (j)
244+
│ columns: (j, i)
244245
│ estimated row count: 1,000 (missing stats)
245246
│ table: jars@jars_pkey
246247
│ spans: FULL SCAN
@@ -280,10 +281,13 @@ vectorized: true
280281
│ │ │ estimated row count: 33
281282
│ │ │ filter: j IS DISTINCT FROM j_new
282283
│ │ │
283-
│ │ └── • scan buffer
284-
│ │ columns: (j, j_new)
285-
│ │ estimated row count: 100
286-
│ │ label: buffer 1000000
284+
│ │ └── • project
285+
│ │ │ columns: (j, j_new)
286+
│ │ │
287+
│ │ └── • scan buffer
288+
│ │ columns: (j, i, j_new)
289+
│ │ estimated row count: 100
290+
│ │ label: buffer 1000000
287291
│ │
288292
│ └── • constraint-check
289293
│ │
@@ -336,15 +340,15 @@ vectorized: true
336340
│ │ │ columns: (j)
337341
│ │ │
338342
│ │ └── • scan buffer
339-
│ │ columns: (j, j_new)
343+
│ │ columns: (j, i, j_new)
340344
│ │ estimated row count: 1,000 (missing stats)
341345
│ │ label: buffer 1
342346
│ │
343347
│ └── • project
344348
│ │ columns: (j_new)
345349
│ │
346350
│ └── • scan buffer
347-
│ columns: (j, j_new)
351+
│ columns: (j, i, j_new)
348352
│ estimated row count: 1,000 (missing stats)
349353
│ label: buffer 1
350354
@@ -364,7 +368,7 @@ EXPLAIN (OPT) DELETE FROM jars WHERE j = 1
364368
----
365369
delete jars
366370
├── scan jars
367-
│ ├── constraint: /6: [/1 - /1]
371+
│ ├── constraint: /7: [/1 - /1]
368372
│ └── flags: avoid-full-scan
369373
└── f-k-checks
370374
└── f-k-checks-item: cookies(j) -> jars(j)
@@ -390,11 +394,11 @@ vectorized: true
390394
│ │ from: jars
391395
│ │
392396
│ └── • buffer
393-
│ │ columns: (j)
397+
│ │ columns: (j, i)
394398
│ │ label: buffer 1
395399
│ │
396400
│ └── • scan
397-
│ columns: (j)
401+
│ columns: (j, i)
398402
│ estimated row count: 1 (missing stats)
399403
│ table: jars@jars_pkey
400404
│ spans: /1/0
@@ -441,7 +445,118 @@ vectorized: true
441445
│ table: cookies@cookies_pkey
442446
│ spans: FULL SCAN
443447
444-
└── • scan buffer
445-
columns: (j)
446-
estimated row count: 1 (missing stats)
447-
label: buffer 1
448+
└── • project
449+
│ columns: (j)
450+
451+
└── • scan buffer
452+
columns: (j, i)
453+
estimated row count: 1 (missing stats)
454+
label: buffer 1
455+
456+
query T
457+
EXPLAIN (OPT) DELETE FROM jars WHERE i = 1
458+
----
459+
delete jars
460+
├── scan jars@jars_i_key
461+
│ ├── constraint: /8: [/1 - /1]
462+
│ └── flags: avoid-full-scan
463+
└── f-k-checks
464+
└── f-k-checks-item: cookies(j) -> jars(j)
465+
└── semi-join (hash)
466+
├── with-scan &1
467+
├── scan cookies
468+
│ └── flags: avoid-full-scan
469+
└── filters
470+
└── j = cookies.j
471+
472+
473+
query T
474+
EXPLAIN (VERBOSE) DELETE FROM jars WHERE i = 1
475+
----
476+
distribution: local
477+
vectorized: true
478+
·
479+
• root
480+
│ columns: ()
481+
482+
├── • delete
483+
│ │ columns: ()
484+
│ │ estimated row count: 0 (missing stats)
485+
│ │ from: jars
486+
│ │
487+
│ └── • buffer
488+
│ │ columns: (j, i)
489+
│ │ label: buffer 1
490+
│ │
491+
│ └── • scan
492+
│ columns: (j, i)
493+
│ estimated row count: 1 (missing stats)
494+
│ table: jars@jars_i_key
495+
│ spans: /1/0
496+
│ locking strength: for update
497+
498+
├── • fk-cascade
499+
│ │ fk: gumballs_j_fkey
500+
│ │
501+
│ └── • delete
502+
│ │ columns: ()
503+
│ │ estimated row count: 0 (missing stats)
504+
│ │ from: gumballs
505+
│ │
506+
│ └── • project
507+
│ │ columns: (g)
508+
│ │
509+
│ └── • project
510+
│ │ columns: (g, j)
511+
│ │
512+
│ └── • hash join (inner)
513+
│ │ columns: (g, j, j)
514+
│ │ estimated row count: 89 (missing stats)
515+
│ │ equality: (j) = (j)
516+
│ │ right cols are key
517+
│ │
518+
│ ├── • scan
519+
│ │ columns: (g, j)
520+
│ │ estimated row count: 1,000 (missing stats)
521+
│ │ table: gumballs@gumballs_pkey
522+
│ │ spans: FULL SCAN
523+
│ │ locking strength: for update
524+
│ │ locking durability: guaranteed
525+
│ │
526+
│ └── • distinct
527+
│ │ columns: (j)
528+
│ │ estimated row count: 10
529+
│ │ distinct on: j
530+
│ │
531+
│ └── • project
532+
│ │ columns: (j)
533+
│ │
534+
│ └── • scan buffer
535+
│ columns: (j, i)
536+
│ estimated row count: 100
537+
│ label: buffer 1000000
538+
539+
└── • constraint-check
540+
541+
└── • error if rows
542+
│ columns: ()
543+
544+
└── • hash join (right semi)
545+
│ columns: (j)
546+
│ estimated row count: 1 (missing stats)
547+
│ equality: (j) = (j)
548+
│ right cols are key
549+
550+
├── • scan
551+
│ columns: (j)
552+
│ estimated row count: 1,000 (missing stats)
553+
│ table: cookies@cookies_pkey
554+
│ spans: FULL SCAN
555+
556+
└── • project
557+
│ columns: (j)
558+
559+
└── • scan buffer
560+
columns: (j, i)
561+
estimated row count: 1 (missing stats)
562+
label: buffer 1

0 commit comments

Comments
 (0)