-
Notifications
You must be signed in to change notification settings - Fork 4k
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
base: master
Are you sure you want to change the base?
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)
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.
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?
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.