-
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: Adding support for integral aliases. #16548
Conversation
Nice - this looks good structurally. Review status: 0 of 5 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file):
Hah, I didn't realize we actually had references to If I had my druthers we'd purge the In any event, I think this looks good structurally. I believe to achieve our goals of compatibility we will only need 2 tags in here for the pkg/sql/sqlbase/table.go, line 112 at r1 (raw file):
I'm not sure we need to do this nil check dance unless you're anticipating something about protobuf changes that I'm not familiar with. Can you instead use the Comments from Reviewable |
Review status: 0 of 5 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file):
Spanner has it, and it is their only integer type (and If we were pre-1.0 I'd say get rid of I'm not sure that we need both Comments from Reviewable |
Review status: 0 of 5 files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file):
Does it make sense to use the width or precision fields instead of adding a new one? They convey a similar limitation and wouldn't require a proto change. Comments from Reviewable |
Reviewed 4 of 5 files at r1, 1 of 1 files at r2. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file): Previously, bdarnell (Ben Darnell) wrote…
hugh then
pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, mjibson (Matt Jibson) wrote…
Maybe precision then -- it seems to me that width would be a restriction on top of the type, e.g. to use fewer bits. I'm not sure -- perhaps an int should just not have a precision field at all and instead have its "kind" pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file):
So perhaps here the better name would be "ApparentType" ("Apparent" because that's what the user sees even if the actual implementation type is something else) or maybe just "TypeAlias" so that is better resonates with the name of the struct member you define below. then
pkg/sql/sqlbase/table.go, line 97 at r2 (raw file):
s/subtype/subType/ Comments from Reviewable |
Don't forget to squash your commits here since they are related. Review status: all files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. Comments from Reviewable |
Review status: 2 of 5 files reviewed at latest revision, 5 unresolved discussions, some commit checks pending. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file): Previously, knz (kena) wrote…
pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, knz (kena) wrote…
I was thinking of reusing the precision field, but then we'd still have the issue that we don't echo back the user's precise specifications back at them when they issue a SHOW CREATE TABLE command because int8 would just become an int again. pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, knz (kena) wrote…
pkg/sql/sqlbase/table.go, line 112 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Thanks for the Go pointer! pkg/sql/sqlbase/table.go, line 97 at r2 (raw file): Previously, knz (kena) wrote…
What are you thoughts on renaming the proto type to AliasType. Comments from Reviewable |
Reviewed 3 of 3 files at r3. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file): Previously, m-schneider (Masha Schneider) wrote…
1 - yes, absolutely! less code is good code pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, m-schneider (Masha Schneider) wrote…
👍 pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, m-schneider (Masha Schneider) wrote…
I had to think about this more today, especially in the light of your other comment that is suggesting to extend also FLOAT with aliases. First of all to clarify the rest of this comment and subsequent discussion, let's name things properly: we'll have the semantic type ("SemType") corresponding to the current "kind", which influences how computations are performed and which Go type is storing the value, and the visible type ("VisType" - sorry I'll punt on "alias" for now), what you are introducing, which influences what clients see. I have two orthogonal proposals which I would like to bring to the table: A) encode both semtype and vistype into a single field, using e.g. low-order bits for semtype and high-order bits for vistype. This idea stems from the observation it's wasteful to spend 2 times 32 bits in memory (when the struct is loaded - protobuf encodes efficiently) when very few bits would be sufficient. The advantage of this proposal is that it would make the introduction of vistypes backward-compatible: a high-order word set to 0 says that the vistype is the "canonical" vistype. With that proposal you would not introduce a separate enum here but rather extend the list of possible values in the enum above, for example B) regardless of whether you encode them together (prop A above) or not (your current code), take the opportunity to rename kind -> semtype and subkind -> vistype throughout the code 😸 To come back to the word "alias" I am not too keen on introducing this now, as you said the word "alias" is super-overloaded and also it doesn't completely clarify (in the name) what an alias really means. Hence my idea of semtype vs vistype. pkg/sql/sqlbase/table.go, line 97 at r2 (raw file): Previously, m-schneider (Masha Schneider) wrote…
see above Comments from Reviewable |
Review status: all files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, knz (kena) wrote…
The precision field for INT columns is 0 currently, so we could let 0 -> INT and 8 -> INT8 (though distinguishing int64 from int8 could be tough). Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions, all commit checks successful. pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
We do not need to distinguish between types of the same length like int64/int8/bigint/int - just between types of different length like int8/int4/int2. Comments from Reviewable |
@jordanlewis Just curious: do we need to also actually compute differently because pg thinks they have different lengths? Would clients notice? e.g. with regards to overflow/range. (this is actually a question David was asking earlier, but now I'm curious too) |
4f4b9f8
to
bb37ca7
Compare
We're planning on replicating PG behavior by throwing error messages when clients try to insert out of range values. I could see clients running legacy pg code using the error message. Review status: 1 of 5 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file): Previously, knz (kena) wrote…
pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, knz (kena) wrote…
So now that we have a reasonable name for Semantic Type, I've renamed AliasType to VisibleType. I think the bit shifting will add extra complexity for a minor space saving in the order of 32 bits per column, so I'm keeping the second field. pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
If we replicate pg behavior then we would distinguish between types of the same length. Comments from Reviewable |
Reviewed 4 of 4 files at r4. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file): Previously, m-schneider (Masha Schneider) wrote…
See my comment above. I think it is probably necessary for semantic correctness to unify them. pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Yes not only we need to distinguish between them but also propagate them; for example pkg/sql/sqlbase/structured.proto, line 68 at r2 (raw file): Previously, m-schneider (Masha Schneider) wrote…
ack Comments from Reviewable |
LGTM for this PR assuming you fix the broken tests in However please ensure either in the next PRs or by opening a follow-up issue that the question of what to do with equivalent types but with different names (e.g. Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. Comments from Reviewable |
b0c2c34
to
c538baf
Compare
Review status: 5 of 6 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/sql/sqlbase/structured.proto, line 71 at r1 (raw file): Previously, knz (kena) wrote…
I'm answering both this and your comment above here. I'm thinking that changing DInt should be in a follow up PR. I looked at DOidWrapper and that looks like the right way to go. The question is do we want to add that complexity? We don't currently do anything for decimal precision beyond update and insert. Comments from Reviewable |
Before this patch we would discard more precise type informations for types such as INT8 and INT64. SHOW CREATE TABLE would show INT even if the user specified either of those. After this patch we'll save this information. SHOW CREATE TABLE will now display the correct type.
Everything is passing! I'll send out the the next pr for type checking. Review status: 5 of 6 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. Comments from Reviewable |
Before this patch we would discard more precise type informations for types
such as INT8 and INT64. SHOW CREATE TABLE would show INT even if the user
specified either of those.
After this patch we'll save this information. SHOW CREATE TABLE will now
display the correct type.