-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: add a view dep on sequence string arguments #50103
sql: add a view dep on sequence string arguments #50103
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.
So.. if nextval('s')
is inside a CASE and it wouldn't necessarily get executed, do we want to error out if the source doesn't exist? E.g. this works in postgres:
radu=> CREATE VIEW v AS SELECT CASE WHEN EXISTS (SELECT * FROM t WHERE x=1) THEN nextval('s') ELSE 0 END;
CREATE VIEW
radu=> SELECT * FROM v;
ERROR: "s" is not a sequence
radu=> DELETE FROM t WHERE true;
DELETE 1
radu=> SELECT * FROM v;
case
------
0
(1 row)
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @RichardJCai)
So would it be correct if we didn't error out if the source didn't exist? This case is really strange to me, is this the only one you can think of that results in this behaviour? Where it's valid to have a call referring to a sequence where the sequence may not exist. |
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 @RichardJCai and @rohany)
pkg/sql/opt/optbuilder/scalar.go, line 512 at r1 (raw file):
Previously, rohany (Rohan Yadav) wrote…
What if resolve datasource returns an error? I think you only want to ignore it if it is a "UnknownDescriptor" error (or something like that)
The second arg is a name, not an error. Errors are returned via panics that are caught at the optbuilder entrpoint.
That said, I agree that we probably want to tolerate "UnknownDescriptor" here.. Postgres definitely allows you to create a view with a nextval call for a bogus sequence.
Wait what version of PG are you using @RaduBerinde , I'm using PG 12 and this does raise an error.
Or maybe your error comes from s existing but being a table instead of a sequence? |
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.
Oh, wow, good catch, yeah it looks like I had a table 's'
that I forgot about. I retract my comments then, erroring out seems like the correct thing to do.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @RichardJCai and @rohany)
744c380
to
884ba01
Compare
884ba01
to
57666ad
Compare
57666ad
to
4d9c795
Compare
@RaduBerinde Do you want to take another look before I merge this? |
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! 1 of 0 LGTMs obtained (waiting on @RaduBerinde, @RichardJCai, and @rohany)
Thanks for the reviews! |
bors r+ |
Build failed (retrying...) |
Build failed (retrying...) |
Build failed |
I think TestDistinct is flakey, although I noticed one of my comments is out of date so I'm gonna update that and retry. |
…when creating a view. Also fixed minor bug where column dependencies were not being added when a sequence is referred to in a currval call. Fixes cockroachdb#24556, 50033 Release note (sql change): Sequences passed as a string argument into views are now tracked as a dependency. Example: CREATE VIEW v AS SELECT nextval('s') will now add a dependency on sequence s.
4d9c795
to
abee50f
Compare
bors r+ |
Build succeeded |
Add a dependency on sequences that are used via string argument when creating a view.
Also fixed minor bug where column dependencies were not being added when a sequence is referred to in a currval call.
Fixes (part of) #24556 and #50033
Release note (sql change): Sequences passed as a string argument into views
are now tracked as a dependency. Example: CREATE VIEW v AS SELECT nextval('s')
will now add a dependency on sequence s.