-
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 new Datum type for column name literals #12281
Conversation
b25f90d
to
8cffb03
Compare
Review status: 0 of 21 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/parser/datum.go, line 512 at r1 (raw file):
I know this code didn't originate with you, but isn't the rest of the method equivalent to pkg/sql/parser/datum.go, line 576 at r1 (raw file):
Could half of the code below be eliminated by embedding Comments from Reviewable |
Review status: 0 of 21 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/parser/datum.go, line 512 at r1 (raw file): Previously, cuongdo (Cuong Do) wrote…
Good point pkg/sql/parser/datum.go, line 576 at r1 (raw file): Previously, cuongdo (Cuong Do) wrote…
Yes - I had this originally, but I got rid of it because it made it really hard to track down some issues. There are lots of methods that Comments from Reviewable |
Review status: 0 of 21 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/parser/datum.go, line 576 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Yeah, I see that now. It's probably better to not embed then. Comments from Reviewable |
Review status: 0 of 21 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/parser/datum.go, line 512 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Actually, if you look at the docs of Comments from Reviewable |
I should mention that I tried the approach of modifying the |
I think we need nathan's input on this. @nvanbenschoten care to comment? (Perhaps even we'll need to keep this sit until the end of the week when nathan is available again) Reviewed 19 of 19 files at r1. pkg/sql/executor.go, line 1422 at r1 (raw file):
Here I'm not sure why we special case the array types. Can't we have a general case with FamilyEqual for all the array types? pkg/sql/parser/aggregate_builtins.go, line 74 at r1 (raw file):
This ought to be replaced by a single aggregate which takes TypeAny as argument and returns tArray{...} as return value. If you can't figure this out here perhaps file an issue and mark this here with a TODO. Comments from Reviewable |
This commit adds a new column type, `name`, that describes fields that are SQL identifiers. This type is primarily for postgres compatibility - there are several fields in pg_catalog tables with type `name` in postgres, and at least one ORM (sequelize) expects that the pgwire type returned for these columns corresponds with the `name` type.
This commit changes the type of fields in pg_catalog tables to `name` to correspond with the types in postgres.
This commit allows TypeString and TypeName to compare to each other via `Equals` but not via `FamilyEquals`, and adds an extra rule to the overload finder that attempts to narrow the list of overloads by `FamilyEquals`-based equality. This allows us to safely remove the comparison overloads for operations between names and strings.
ac493ab
to
f869548
Compare
Review status: 13 of 23 files reviewed at latest revision, 4 unresolved discussions, some commit checks pending. pkg/sql/executor.go, line 1422 at r1 (raw file): Previously, knz (kena) wrote…
Only certain array types are supported. Decimal array types, for instance, are unsupported. pkg/sql/parser/aggregate_builtins.go, line 74 at r1 (raw file): Previously, knz (kena) wrote…
I made a TODO. Comments from Reviewable |
Ready for review - I'd definitely like some feedback on the modifications I made to the type checker in commit 3. I think the way I've (ab?)used the |
Most of this looks good! However, I don't think I like what's going on in An alternative idea that came to mind when I heard about adding this change was to instead add better support for type aliasing without needing to add all new datum types. Right now, we map a large number of type names to a single Datum type and then map this single Datum type back to a single OID. As an example, we have a similar issue to what prompted this change with Reviewed 13 of 19 files at r1, 1 of 1 files at r2, 3 of 4 files at r3, 4 of 6 files at r4. pkg/sql/parser/aggregate_builtins.go, line 74 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
The issue is that the signature would be @knz: we should chat sometime next week in person about how we'd want to represent cases like this. pkg/sql/parser/constant.go, line 303 at r4 (raw file):
You're missing some code here that would allow literal type inference to properly work with the Name type. pkg/sql/parser/constant.go, line 330 at r4 (raw file):
While you're here, could you fix this and the TypeBytes case to use their respective constructors? pkg/sql/parser/datum.go, line 512 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Strange! Nice find though pkg/sql/parser/datum.go, line 576 at r1 (raw file): Previously, cuongdo (Cuong Do) wrote…
Maybe just name the field pkg/sql/parser/expr.go, line 1029 at r4 (raw file):
Don't we need some changes here (and in eval.go) to allow the expected casts to work? pkg/sql/sqlbase/structured.go, line 1644 at r4 (raw file):
Is this intentional? Comments from Reviewable |
TFTR! I agree that the I love the idea of switching this approach out for a type aliasing approach. I think that would be so much cleaner - as you note, In the meantime, I'll put this PR on hold. Review status: 21 of 23 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. pkg/sql/parser/expr.go, line 1029 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Yeah, I just didn't get to that in this commit. pkg/sql/sqlbase/structured.go, line 1644 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
No - in fact I'm surprised tests pass with this. I left this here by accident when I was experimenting to see whether we could get away with not adding a new column type kind to structured.proto. Comments from Reviewable |
Closing this - superseded by #12641 |
This PR adds a new column type,
name
, that describes fields that are SQL identifiers. This type is primarily for postgres compatibility -there are several fields in pg_catalog tables with typename
inpostgres, and at least one ORM (sequelize) expects that the pgwire type returned for these columns corresponds with the
name
type.pg_catalog
is also updated to use the new type.This PR ended up being larger than I would have liked. Ideally, adding
name
shouldn't require adding a new column type to the enum instructured.proto
since allname
types are going to stay in virtual tables and not be persisted. Unfortunately it seems like we need to add that new column type anyway - it's used in various non-persistence operations that get done during e.g.GROUP BY
or array aggregation.Resolves #12207.
Feedback about ways to simplify this would be very welcome.
This change is