-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
sql: fix trigger interaction with computed columns #133328
Conversation
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.
Reviewed all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball and @mw5h)
pkg/sql/opt/optbuilder/trigger.go
line 136 at r1 (raw file):
// the computed columns. if eventType == tree.TriggerEventInsert || eventType == tree.TriggerEventUpdate { mb.recomputeComputedColsForTrigger(eventType)
I think an optbiulder test or two for this would be useful to show how this recomputation is planned.
pkg/sql/opt/optbuilder/trigger.go
line 830 at r1 (raw file):
// hasRowLevelTriggers returns true if the table has any row-level triggers that // match the given action time and event type. func (mb *mutationBuilder) hasRowLevelTriggers(
This function is not used in this PR - remove it?
pkg/ccl/logictestccl/testdata/logic_test/triggers
line 2601 at r1 (raw file):
# see NULLs. In addition, while a BEFORE trigger can modify a computed column, # the changed value is ignored. In contrast, the computed column *does* show # the effect of modifications to the columns it depends on.
Does a WHEN
expression see NULLs for the computed column, or the pre-trigger value of the column? Can you add some tests for this case?
8d0f31a
to
e4784e1
Compare
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 (waiting on @mgartner and @mw5h)
pkg/sql/opt/optbuilder/trigger.go
line 136 at r1 (raw file):
Previously, mgartner (Marcus Gartner) wrote…
I think an optbiulder test or two for this would be useful to show how this recomputation is planned.
Good idea, Done.
pkg/sql/opt/optbuilder/trigger.go
line 830 at r1 (raw file):
Previously, mgartner (Marcus Gartner) wrote…
This function is not used in this PR - remove it?
🤦 Oops, removed it.
pkg/ccl/logictestccl/testdata/logic_test/triggers
line 2601 at r1 (raw file):
Previously, mgartner (Marcus Gartner) wrote…
Does a
WHEN
expression see NULLs for the computed column, or the pre-trigger value of the column? Can you add some tests for this case?
It sees NULLs, I'll add some tests.
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.
Reviewed 2 of 3 files at r2, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @mw5h)
TFTR! bors r+ |
Build failed (retrying...): |
bors r- |
Canceled. |
e4784e1
to
983d18c
Compare
Needed a rebase. |
This commit makes the following changes to the way row-level BEFORE triggers interact with computed columns: * BEFORE triggers now observe NULL values in place of computed columns. * Modifications to computed columns by BEFORE triggers are ignored. * Computed columns are re-computed after row-level BEFORE triggers execute. These changes make the behavior consistent with that of Postgres. Fixes cockroachdb#132979 Release note: None
983d18c
to
43d6d62
Compare
bors r+ |
Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches. Issue #132979: branch-release-24.3. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from 43d6d62 to blathers/backport-release-24.3-133328: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 24.3.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
This commit makes the following changes to the way row-level BEFORE triggers interact with computed columns:
These changes make the behavior consistent with that of Postgres.
Fixes #132979
Release note: None