-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: still more routine dependency improvements #159126
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
Conversation
a2ded74 to
05772f0
Compare
mgartner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fix the case for enums, which also synthesize check constraints? Is it worth adding this test:
CREATE TYPE typ AS ENUM ('foo', 'bar');
CREATE TABLE t (a INT, b typ);
CREATE PROCEDURE p() LANGUAGE SQL AS $$
INSERT INTO t (a) VALUES (1);
UPDATE t SET a = a + 1;
$$;
CALL p();
ALTER TABLE t DROP COLUMN b;
CALL p();We don't have to worry about partial indexes for now, because of #97813. I'll add a note to that issue pointing this out. If you think it's worth a TODO in the code where we build partial index predicates, then you can add one.
@mgartner reviewed 4 of 4 files at r1, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @ZhouXing19)
ZhouXing19
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ZhouXing19 reviewed 4 of 4 files at r1, all commit messages.
Reviewable status:complete! 2 of 0 LGTMs obtained (waiting on @DrewKimball)
05772f0 to
caecd97
Compare
|
@mgartner good point about enums and partial indexes. I added an enum test (already fixed), but noticed that there were several more cases we didn't handle for partial indexes. Those are now fixed, with test cases added. |
mgartner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgartner reviewed 5 of 5 files at r2, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball and @ZhouXing19)
pkg/sql/opt/optbuilder/partial_index.go line 128 at r2 (raw file):
// dependencies on any UDTs or columns referenced by the predicate. The // partial index will already prevent dropping such UDTs or columns. defer b.DisableSchemaDepTracking()()
I'm wondering if this is the only addition you need for partial indexes. It looks like the three others you added all lead down to this method - the metadata and two arbiter cases. Did you try making just this one addition?
caecd97 to
7d097e8
Compare
DrewKimball
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @mgartner and @ZhouXing19)
pkg/sql/opt/optbuilder/partial_index.go line 128 at r2 (raw file):
Previously, mgartner (Marcus Gartner) wrote…
I'm wondering if this is the only addition you need for partial indexes. It looks like the three others you added all lead down to this method - the metadata and two arbiter cases. Did you try making just this one addition?
I believe each of those cases ends up building the predicate directly with buildScalar, so it's necessary. I did try removing some of them individually to make sure the tests fail as expected, though it wasn't exhaustive.
|
Unit tests flaked, just kicked off a retry. |
7d097e8 to
62d693d
Compare
|
Hm, the flake in TestCreateAsVTable is because I made the |
I missed in cockroachdb#158935 that check constraints and partial index predicates are additional places where we unnecessarily track transitive column dependencies when creating a routine. The fix is gated behind the same session setting as cockroachdb#158935. Fixes cockroachdb#158154 Release note (sql change): Fixed two cases where creation of a routine resolves unnecessary column dependencies, which can prevent drop of the column without first dropping the routine. Here, the unnecessary dependencies are due to references within CHECK constraints, including those for RLS policies and hash-sharded indexes, as well as those in partial index predicates. The fix is gated behind the session setting `use_improved_routine_deps_triggers_and_computed_cols`, which is off by default before 26.1.
62d693d to
3b5e421
Compare
|
I looked further into that test flake, and decided it was worth fixing in the backport. The second commit handles that by adding a check for virtual tables in appendOrdinaryColumnsFromTable before deciding to track column dependencies. |
A previous fix in cockroachdb#146250 added dependency tracking for tables in appendOrdinaryColumnsFromTable. This fix missed that the table could be a virtual table, in which case we don't need (and in some places can't handle) tracking dependencies. This commit adds a filter to avoid tracking virtual tables. The only place I've found where this mattered was in the cross-DB check for views, which led to a test flake after some changes in the previous commit. Informs cockroachdb#158154 Release note: None
3b5e421 to
ca1e3c7
Compare
|
TFTRs! bors r+ |
|
blathers backport 26.1 |
sql: still more routine dependency improvements
I missed in #158935 that check constraints and partial index predicates
are additional places where we unnecessarily track transitive column
dependencies when creating a routine. The fix is gated behind the same
session setting as #158935.
Fixes #158154
Release note (sql change): Fixed two cases where creation of a routine
resolves unnecessary column dependencies, which can prevent drop of the
column without first dropping the routine. Here, the unnecessary
dependencies are due to references within CHECK constraints, including
those for RLS policies and hash-sharded indexes, as well as those in
partial index predicates. The fix is gated behind the session setting
use_improved_routine_deps_triggers_and_computed_cols, which is off bydefault before 26.1.
optbuilder: don't track deps for virtual tables
A previous fix in #146250 added dependency tracking for tables in
appendOrdinaryColumnsFromTable. This fix missed that the table could
be a virtual table, in which case we don't need (and in some places
can't handle) tracking dependencies. This commit adds a filter to
avoid tracking virtual tables.
The only place I've found where this mattered was in the cross-DB
check for views, which led to a test flake after some changes in
the previous commit.
Informs #158154
Release note: None