Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: add tests for FK delete cascade fast-path with UDF #88933

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/sql/opt/optbuilder/fk_cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func tryNewOnDeleteFastCascadeBuilder(
if memo.CanBeCompositeSensitive(md, &sel.Filters) {
return nil, false
}
// TODO(mgartner): Disallow this fast path if there is a UDF invocation.
if sel.Relational().HasSubquery {
return nil, false
}
Expand Down
69 changes: 69 additions & 0 deletions pkg/sql/opt/optbuilder/testdata/fk-on-delete-cascade
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ exec-ddl
CREATE TABLE child (c INT PRIMARY KEY, p INT NOT NULL REFERENCES parent(p) ON DELETE CASCADE)
----

exec-ddl
CREATE FUNCTION one_volatile() RETURNS INT VOLATILE LANGUAGE SQL AS 'SELECT 1'
----

exec-ddl
CREATE FUNCTION one_immutable() RETURNS INT IMMUTABLE LANGUAGE SQL AS 'SELECT 1'
----

# Simple cascade; fast path (the filter gets transferred over to the cascade).
build-cascades
DELETE FROM parent WHERE p > 1
Expand Down Expand Up @@ -104,6 +112,67 @@ root
└── filters
└── child.p:15 = p:18

# Delete with volatile UDF; no fast path.
build-cascades
DELETE FROM parent WHERE p > one_volatile()
----
root
├── delete parent
│ ├── columns: <none>
│ ├── fetch columns: p:4
│ ├── input binding: &1
│ ├── cascades
│ │ └── child_p_fkey
│ └── select
│ ├── columns: p:4!null crdb_internal_mvcc_timestamp:5 tableoid:6
│ ├── scan parent
│ │ └── columns: p:4!null crdb_internal_mvcc_timestamp:5 tableoid:6
│ └── filters
│ └── p:4 > one_volatile()
└── cascade
└── delete child
├── columns: <none>
├── fetch columns: c:12 child.p:13
└── semi-join (hash)
├── columns: c:12!null child.p:13!null
├── scan child
│ ├── columns: c:12!null child.p:13!null
│ └── flags: disabled not visible index feature
├── with-scan &1
│ ├── columns: p:16!null
│ └── mapping:
│ └── parent.p:4 => p:16
└── filters
└── child.p:13 = p:16

# Delete with immutable UDF; fast path.
build-cascades
DELETE FROM parent WHERE p > one_immutable()
----
root
├── delete parent
│ ├── columns: <none>
│ ├── fetch columns: p:4
│ ├── cascades
│ │ └── child_p_fkey
│ └── select
│ ├── columns: p:4!null crdb_internal_mvcc_timestamp:5 tableoid:6
│ ├── scan parent
│ │ └── columns: p:4!null crdb_internal_mvcc_timestamp:5 tableoid:6
│ └── filters
│ └── p:4 > one_immutable()
└── cascade
└── delete child
├── columns: <none>
├── fetch columns: c:12 child.p:13
└── select
├── columns: c:12!null child.p:13!null
├── scan child
│ ├── columns: c:12!null child.p:13!null
│ └── flags: disabled not visible index feature
└── filters
└── child.p:13 > one_immutable()

# Delete everything.
build-cascades
DELETE FROM parent
Expand Down