-
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: force column types in view plans (make view descriptors future-proof) #12611
Comments
I was actually just thinking about this, and I think your two proposed changes sound solid (although I don't think the first one is necessary if we do the second one). They would address your first and third potential issue. However, I don't think they would address the second, which is more tricky and may require function versioning. IIRC correctly, most SQL databases like Postgres will compile persisted statements to an internal representation before storing. This allows them to avoid these kinds of issues. If we're going to be re-parsing and typing our serialized format, fully type-annotating the expression tree seems like the right approach. Also, I think we should be doing this in cases like CHECK constraints as well. Anywhere that statements need to be persisted will face these complications. |
Yeah perhaps I should mention a few of these ideas in the IR RFC too. |
This change addresses a few related problems (described in more detail in cockroachdb#12532): - ambiguous datum types after serialization - invalid prefix casts after expression processing (like `INTERVAL INTERVAL `1.5s`'). Changes: - a new FmtFlag adds type annotations to datums and placeholders. This ensures that expressions that contain `DDInterval`, `DDate` can be formatted and re-parsed correctly. This replaces ad-hoc type prepending like `INTERVAL '..'` or `DATE '..'`. - `CastExpr.TypeCheck` now returns the underlying type-checked expression directly when it is a Datum that we know for sore is of identical type. - `castPrefix` (renamed to `castPrepend`) now only functions if the underlying expression is a string literal (preventing incorrect expressions like `DECIMAL '1.0':::string`). `castPrefixParens` is removed (it was incorrect). - `AnnotateTypeExpr.TypeCheck` now returns the underlying type-checked expression rather than changing the `AnnotateTypeExpr` in-place and returning it (which could result in double annotations with the new `FmtFlag`). `AnnotateTypeExpr` is no longer a `TypedExpr` so it is never part of a type-checked expression (which makes sense). - type checking tests are extended to verify the serliazed type-checked expression, which verifies both serialization and type resolution. Note that changing the prepend syntax to a `AnnotateTypeExpr` was considered but that doesn't work for things like `DECIMAL '2.0'`. Fixes cockroachdb#12532. Resolves some of the concerns in cockroachdb#12611.
This change addresses a few related problems (described in more detail in cockroachdb#12532): - ambiguous datum types after serialization - invalid prefix casts after expression processing (like `INTERVAL INTERVAL `1.5s`'). Changes: - a new FmtFlag adds type annotations to datums and placeholders. This ensures that expressions that contain `DDInterval`, `DDate` can be formatted and re-parsed correctly. This replaces ad-hoc type prepending like `INTERVAL '..'` or `DATE '..'`. - `CastExpr.TypeCheck` now returns the underlying type-checked expression directly when it is a Datum that we know for sure is of identical type. - `castPrefix` (renamed to `castPrepend`) now only functions if the underlying expression is a string literal (preventing incorrect expressions like `DECIMAL '1.0':::STRING`). `castPrefixParens` is removed (it was incorrect). - `AnnotateTypeExpr.TypeCheck` now returns the underlying type-checked expression rather than changing the `AnnotateTypeExpr` in-place and returning it (which could result in double annotations with the new `FmtFlag`). `AnnotateTypeExpr` is no longer a `TypedExpr` so it is never part of a type-checked expression (which makes sense). - type checking tests are extended to verify the serialized type-checked expression, which verifies both serialization and type resolution. Note that changing the prepend syntax to a `AnnotateTypeExpr` was considered but that doesn't work for things like `DECIMAL '2.0'`. Fixes cockroachdb#12532. Helps with cockroachdb#12611.
This change addresses a few related problems (described in more detail in cockroachdb#12532): - ambiguous datum types after serialization - invalid prefix casts after expression processing (like `INTERVAL INTERVAL `1.5s`'). Changes: - a new FmtFlag adds type annotations to datums and placeholders. This ensures that expressions that contain `DDInterval`, `DDate` can be formatted and re-parsed correctly. This replaces ad-hoc type prepending like `INTERVAL '..'` or `DATE '..'`. - `CastExpr.TypeCheck` now returns the underlying type-checked expression directly when it is a Datum that we know for sure is of identical type. - `castPrefix` (renamed to `castPrepend`) now only functions if the underlying expression is a string literal (preventing incorrect expressions like `DECIMAL '1.0':::STRING`). `castPrefixParens` is removed (it was incorrect). - `AnnotateTypeExpr.TypeCheck` now returns the underlying type-checked expression rather than changing the `AnnotateTypeExpr` in-place and returning it (which could result in double annotations with the new `FmtFlag`). `AnnotateTypeExpr` is no longer a `TypedExpr` so it is never part of a type-checked expression (which makes sense). - type checking tests are extended to verify the serialized type-checked expression, which verifies both serialization and type resolution. Note that changing the prepend syntax to a `AnnotateTypeExpr` was considered but that doesn't work for things like `DECIMAL '2.0'`. Fixes cockroachdb#12532. Helps with cockroachdb#12611.
This needs #15388 which I bumped to 1.1, so bumping this one to 1.1 as well. This needs to be documented as a known limitation though. |
@knz how is this looking for 1.1? |
Not making it into 1.1.0. Under consideration for inclusion in a subsequent minor release along with several other view bugfix PRs. |
@rohany this one too. @RaduBerinde, just noticed you triaged this in the Optimizer board - I don't think you were planning to deal with it soon though, right? |
No, I had just triaged all opt issues. |
We have marked this issue as stale because it has been inactive for |
The problem is as follows; suppose at some time we define a view:
then at some later point either of the following happens:
somefunc
changessomefunc
which change the resolutionThen 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:
Jira issue: CRDB-6128
The text was updated successfully, but these errors were encountered: