-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: force column types in view plans (make view descriptors future-proof) #12611
Copy link
Copy link
Open
Labels
A-schema-changesA-sql-typingSQLtype inference, typing rules, type compatibility.SQLtype inference, typing rules, type compatibility.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-ux-surpriseIssue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.docs-todo
Milestone
Description
The problem is as follows; suppose at some time we define a view:
create view v as select somefunc(x+3, y) from ...then at some later point either of the following happens:
- we add a new implicit cast rule for literal constants
- the return type of
somefuncchanges - new overloads are added to
somefuncwhich change the resolution
Then any uses of the view will discover a new type for the columns, effectively changing the semantics of the view. In some cases it could even break (e.g. if the overload resolution for somefunc has become ambiguous)
This is because the code that re-creates the query plan from the view descriptor infers the types using the text of the original view query using the new typing rules.
There are two parts for a full solution to this, but the first will go a long way to make views future-proof:
- give the column types stored in the view descriptor as "demanded types" when instantiating the view plan. This will bias type checking strongly in favor of preserving the previous types and catch most problematic cases.
- annotate the syntax tree preserved in the view descriptor with the types of every expression node and the specific builtin overload used for each function call, then skip type checking entirely when instantiating the query plan from the view descriptor.
Jira issue: CRDB-6128
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-schema-changesA-sql-typingSQLtype inference, typing rules, type compatibility.SQLtype inference, typing rules, type compatibility.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-ux-surpriseIssue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.Issue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.docs-todo