-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
error msg for invalid reference to non-existent table or column in existing view #2038
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.
Looks very close! That string prefix match feels like something we could tighten up a bit more, but everything else looks good.
Skip: true, | ||
Query: "SELECT * FROM b;", | ||
ExpectedErr: sql.ErrInvalidRefInView, |
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.
Interesting! I just tried this on MySQL and was surprised that it generated the "view reference invalid..." error. I expected MySQL would just remember the *
, but it totally does expand *
to the columns in the table at the time when the view is created. As a direct result of that... if you alter the base table and add more columns, those new columns won't show up when you query the view.
sql/planbuilder/from.go
Outdated
// TODO: Need better way to determine the view usage here. | ||
// Creating new view or updating existing view to reference non-existent table/view do not apply here. | ||
// Need to account for non-existing functions or users without appropriate privilege to the referenced table/column/function. | ||
if (sql.ErrTableNotFound.Is(err) || sql.ErrColumnNotFound.Is(err)) && strings.HasPrefix(strings.ToLower(b.ctx.Query()), "select") { |
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.
Good point about the error needing to be different for creating a new view with a bad column references, versus querying an existing view that has a bad column reference. Relying on the prefix match for SELECT
works okay, but won't cover all cases and feels like there should be a better way...
Does this code get invoked when creating a new view? It seems like it wouldn't, but I haven't tested. Any other ideas on how to avoid the string prefix matching check there?
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.
No, this error message is not returned when creating a new view referencing invalid table. This error message is returned only when querying existing view that its referenced tables, columns, functions or user privileges were altered to become invalid.
Creating a new view or updating existing view to have invalid references to these will not cause this issue.
I'll think of ideas to avoid prefix matching :)
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.
Looks good! I think we can simplify one block a bit, but after that, I think this is ready to go.
It catches invalid reference to non-existent table or column in existing view. This includes
SELECT
queries on a view that references table or column that was removed or renamed.Note: For now, It does not catch references to invalid functions or users without appropriate privilege cases and queries other than
SELECT
queries.Fixes: dolthub/dolt#6691