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/parser: Add new DOidWrapper type and use for OID and Name types #12641
sql/parser: Add new DOidWrapper type and use for OID and Name types #12641
Conversation
Quite a good job. Well done. I assume that you have checked the output of I wonder if pursuant to #12145 and #12530, the types Reviewed 6 of 6 files at r1, 29 of 29 files at r2, 16 of 16 files at r3, 17 of 17 files at r4, 1 of 1 files at r5, 5 of 5 files at r6. pkg/sql/analyze.go, line 1435 at r2 (raw file):
You could simplify this by making pkg/sql/limit.go, line 118 at r2 (raw file):
Same as earlier, pkg/sql/pg_catalog.go, line 868 at r3 (raw file):
I don't understand why you removed the DEFAULT - or perhaps why the DEFAULT clause was there in the first place :) pkg/sql/pg_catalog.go, line 1262 at r3 (raw file):
see my previous comment pkg/sql/parser/datum.go, line 238 at r2 (raw file):
If I were you I would use the name (Same for pkg/sql/parser/datum.go, line 1894 at r2 (raw file):
Like in my other comments I'd suggest erroring out if this ever happens instead of accepting it silently. pkg/sql/parser/datum.go, line 1900 at r2 (raw file):
Put the explanation in a comment and use a simpler panic message. The person encountering the panic can then look at the code where it was triggered. pkg/sql/parser/datum.go, line 1931 at r2 (raw file):
The inverse condition reads simpler: if v, ok := other.(*DOidWrapper); ok {
return d.Wrapped.Compare(v.Wrapped)
}
return d.Wrapped.Compare(other) pkg/sql/parser/datum.go, line 1941 at r2 (raw file):
Make pkg/sql/parser/datum.go, line 1987 at r2 (raw file):
pkg/sql/parser/eval.go, line 2385 at r2 (raw file):
Why not changing it right away then? pkg/sql/parser/type.go, line 410 at r1 (raw file):
I think pkg/sql/parser/type.go, line 449 at r1 (raw file):
pkg/sql/parser/type.go, line 502 at r2 (raw file):
I'm not sure it even makes sense to re-wrap a type by calling pkg/sql/parser/type.go, line 110 at r4 (raw file):
In the intermediate commit(s) where both pkg/sql/pgwire/types.go, line 614 at r3 (raw file):
And what about pkg/sql/sqlbase/structured.proto, line 42 at r3 (raw file):
Given the amount of redundancy caused by STRING and NAME existing side by side, or INT and OID, I would suggest investigating if we could have one field in the column type with its "behavior type" (the code that runs) and another one with its "advertised type". Have the latter nullable so that if it doesn't exist yet it defaults to the behavior type, for backward compatibility. Either in this PR or file a followup issue. Comments from Reviewable |
Reviewed 6 of 6 files at r1, 29 of 29 files at r2, 16 of 16 files at r3, 17 of 17 files at r4, 1 of 1 files at r5, 5 of 5 files at r6. pkg/sql/pg_catalog.go, line 868 at r3 (raw file): Previously, knz (kena) wrote…
I did something similar in my NAME patch - agreed that there was no reason to have this in the first place. We have no name literal syntax, so the default doesn't work. pkg/sql/parser/datum.go, line 238 at r2 (raw file): Previously, knz (kena) wrote…
I'm personally happy about the pkg/sql/parser/datum.go, line 1876 at r2 (raw file):
Being able to override Couldn't we still modify the pkg/sql/parser/datum.go, line 1894 at r2 (raw file): Previously, knz (kena) wrote…
+1 Comments from Reviewable |
@nvanbenschoten Any chance you can progress this soon? It'd be great to get further along with our Sequelize support. |
@cuongdo yep, I'm hoping to get this in by early next week. |
ae598eb
to
0774fc2
Compare
Thanks for the reviews! Review status: 0 of 38 files reviewed at latest revision, 18 unresolved discussions. pkg/sql/analyze.go, line 1435 at r2 (raw file): Previously, knz (kena) wrote…
Good call. Done. pkg/sql/limit.go, line 118 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/pg_catalog.go, line 868 at r3 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Yeah, I was looking at Jordan's change when I removed DEFAULT. He had correctly recognized that the DEFAULT clause was useless. It was there because I was much more strict about information_schema tables when they were originally implemented (I tried to get the CREATE TABLE results to match with MySQL). Since then it has become clear that identical schemas are unnecessary. pkg/sql/parser/datum.go, line 1876 at r2 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Ah great point! We could do pretty much exactly what we do for pkg/sql/parser/datum.go, line 1894 at r2 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. pkg/sql/parser/datum.go, line 1900 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/datum.go, line 1931 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/datum.go, line 1941 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/datum.go, line 1987 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/eval.go, line 2385 at r2 (raw file): Previously, knz (kena) wrote…
Added as the new first commit. pkg/sql/parser/type.go, line 410 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/type.go, line 449 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/type.go, line 502 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/type.go, line 110 at r4 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/pgwire/types.go, line 614 at r3 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/sqlbase/structured.proto, line 42 at r3 (raw file): Previously, knz (kena) wrote…
That's actually exactly how I initially implemented this, but it quickly became apparent that the approach caused more issues than it solved. To demonstrate why this is, take a look at all references to Comments from Reviewable |
0774fc2
to
72a6c39
Compare
72a6c39
to
af6220c
Compare
Reviewed 1 of 29 files at r2, 31 of 33 files at r7, 1 of 16 files at r8, 14 of 19 files at r9, 1 of 1 files at r10, 4 of 5 files at r11, 1 of 1 files at r12. pkg/sql/parser/builtins.go, line 1564 at r7 (raw file):
I don't get how this format_type() built-in belongs to this PR. Where is it used? pkg/sql/sqlbase/structured.proto, line 42 at r3 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Well one would argue that the current state with all this redundancy is not especially pleasant to work with either. Comments from Reviewable |
LGTM except the change to builtins.go which I don't understand. Review status: 37 of 38 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. Comments from Reviewable |
This change adds the `parser.DOidWrapper` and `parser.tOidWrapper` types, which wrap Datums and Types respectively, allowing custom Oid values to be attached. The reason the types were introduced was to permit the introduction of Datum types with new Object IDs while maintaining identical behavior to current Datum types. Specifically, it obviates the need to: - define a new `parser.Datum` type. - define a new `parser.Type` type. - support operations and functions for the new Type. - support mixed-type operations between the new Type and the old Type. Instead, DOidWrapper allows a standard Datum to be wrapped with a new Oid. This approach provides two major advantages: - performance of the existing Datum types are not affected because they do not need to have custom oid.Oids added to their structure. - the introduction of new Datum aliases is straightforward and does not require additions to typing rules or type-dependent evaluation behavior. Types that currently benefit from DOidWrapper are: - `DOid => DOidWrapper(*DInt, oid.T_oid)` - `DName => DOidWrapper(*DString, oid.T_name)`
This change uses DOidWrapper to add a new DName type. It then uses this type in pg_catalog wherever Postgres does.
This change uses DOidWrapper to add a new DOid type. It then uses this type in pg_catalog wherever Postgres does.
This change cleans up `OidPseudoType` and makes its distinction from `OidColType` more clear.
af6220c
to
dc8d9fa
Compare
TFTR! Review status: 12 of 38 files reviewed at latest revision, 5 unresolved discussions. pkg/sql/parser/builtins.go, line 1564 at r7 (raw file): Previously, knz (kena) wrote…
I think what you're seeing is the result of a rebase. I didn't add this in here. Comments from Reviewable |
Reviewed 9 of 9 files at r13. Comments from Reviewable |
Replaces #12281.
Resolves #12207.
This change adds the
parser.DOidWrapper
andparser.tOidWrapper
types, which wrap Datums and Types respectively, allowing custom Oid
values to be attached. The reason the types were introduced was to
permit the introduction of Datum types with new Object IDs while
maintaining identical behavior to current Datum types. Specifically,
it obviates the need to:
parser.Datum
type.parser.Type
type.Instead, DOidWrapper allows a standard Datum to be wrapped with a new Oid.
This approach provides two major advantages:
do not need to have custom oid.Oids added to their structure.
require
additions to typing rules or type-dependent evaluation behavior.
Types that currently benefit from DOidWrapper are:
DOid => DOidWrapper(*DInt, oid.T_oid)
DName => DOidWrapper(*DString, oid.T_name)
This change is