-
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 int2, int8, float4 and float8 to be in line with postgres support of numerical types. #16720
Conversation
Reviewed 12 of 12 files at r1. pkg/sql/logictest/testdata/logic_test/table, line 309 at r1 (raw file):
I'm really sorry that you had to perform this renumbering of the variables, and I am sorry in advance for the sentence that follows, but please do it just once more, so that nobody else will have to do it again in the future: rename all the columns with the form Then sort the definitions in alphabetical order. pkg/sql/parser/col_types.go, line 97 at r1 (raw file):
Huh I now see this parameter "N". Why not reuse this for int types throughout instead of "precision"? pkg/sql/parser/col_types.go, line 124 at r1 (raw file):
Yeah I think what "N" does is exactly what you need here, no need for a new field. Also as revealed in package Note that this comment is compatible with the concepts in postgres: in pg only types numeric and float have a "precision"; the integer types have a "size". pkg/sql/parser/col_types.go, line 147 at r1 (raw file):
There's a conceptual mistake here:
So you need two separate fields "width" and "prec" in FloatColType and handle them properly here, in Format and in computations. pkg/sql/sqlbase/table.go, line 1641 at r1 (raw file):
look 5 lines above this is equivalent to what's done with the field Comments from Reviewable |
Review status: all files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. pkg/sql/parser/col_types.go, line 147 at r1 (raw file): Previously, knz (kena) wrote…
note that in computations perhaps right now we don't need to do anything, because we do not have separate DFloat32 and DFloat64. But the correct way would be to have both and use the width field to select one or another (https://stackoverflow.com/questions/16889042/postgresql-what-is-the-difference-between-float1-and-float24#16889190) Comments from Reviewable |
51450b9
to
309fbaf
Compare
Review status: 7 of 12 files reviewed at latest revision, 5 unresolved discussions, some commit checks pending. pkg/sql/logictest/testdata/logic_test/table, line 309 at r1 (raw file): Previously, knz (kena) wrote…
Column Selection mode FTW! pkg/sql/parser/col_types.go, line 97 at r1 (raw file): Previously, knz (kena) wrote…
I changed both to width. pkg/sql/parser/col_types.go, line 124 at r1 (raw file): Previously, knz (kena) wrote…
Changed both to width. pkg/sql/sqlbase/table.go, line 1641 at r1 (raw file): Previously, knz (kena) wrote…
I see what you mean about bit strings, but the definition for integer types is here: Comments from Reviewable |
Reviewed 5 of 5 files at r2. pkg/sql/logictest/testdata/logic_test/table, line 309 at r1 (raw file): Previously, m-schneider (Masha Schneider) wrote…
👍 pkg/sql/sqlbase/table.go, line 1641 at r1 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Comments from Reviewable |
Just for the sake of clarity, some of the many reasons why the math appears wrong:
|
FP function removed. Review status: 9 of 12 files reviewed at latest revision, 2 unresolved discussions, some commit checks pending. pkg/sql/sqlbase/table.go, line 1641 at r1 (raw file): Previously, knz (kena) wrote…
I simplified the code for both bits and integers. I don't quite understand the need for the loop for bits. Using a loop for negative numbers would just be incorrect because Go uses 2s compliment to store negative numbers so our internal int64 representation would overflow for any negative number by definition. Comments from Reviewable |
Reviewed 3 of 3 files at r3. pkg/sql/parser/col_types.go, line 171 at r3 (raw file):
I think you should remove the second part of the conditional. pkg/sql/parser/col_types_test.go, line 45 at r3 (raw file):
Drop "Prec" (using the default here) pkg/sql/parser/col_types_test.go, line 46 at r3 (raw file):
Drop "Prec" (using the default) pkg/sql/parser/col_types_test.go, line 47 at r3 (raw file):
Add a test for FLOAT4(10) and FLOAT8(30) pkg/sql/sqlbase/table.go, line 1641 at r1 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Yes you are right. See my other comment for the followup. pkg/sql/sqlbase/table.go, line 1621 at r3 (raw file):
Scratch this entire conditional and its if col.Type.Width > 0 {
shifted := v >> uint(col.Type.Width-1)
if (v >= 0 && shifted != 0) || (v < 0 && shifted != -1) {
return fmt.Errorf("integer out of range for type %s (column %q)", col.Type.VisibleType, col.Name)
}
} Add tests for the boundary values: all combinations of Width = 0, 1, 63, 64, values = 0, 1, -1, MaxInt64, MinInt64. Comments from Reviewable |
6cf57bf
to
6912f05
Compare
Review status: 5 of 12 files reviewed at latest revision, 7 unresolved discussions. pkg/sql/parser/col_types.go, line 147 at r1 (raw file): Previously, knz (kena) wrote…
So should we do anything extra in this PR to support all of this correctly, or wait for the change at the datum level when we support float32 and float64. pkg/sql/parser/col_types.go, line 171 at r3 (raw file): Previously, knz (kena) wrote…
Removed! pkg/sql/parser/col_types_test.go, line 45 at r3 (raw file): Previously, knz (kena) wrote…
Dropped pkg/sql/parser/col_types_test.go, line 46 at r3 (raw file): Previously, knz (kena) wrote…
Dropped. pkg/sql/parser/col_types_test.go, line 47 at r3 (raw file): Previously, knz (kena) wrote…
I'm not convinced that we should add support for that. As of now those two string won't be parsed by sql.go. pkg/sql/sqlbase/table.go, line 1621 at r3 (raw file): Previously, knz (kena) wrote…
I have those tests in Scale already for int2, int4 and the bit strings. I also needed to add another check for BITs specifically because they're unsigned so using the same check would fail. Comments from Reviewable |
Reviewed 2 of 2 files at r4, 5 of 5 files at r5. pkg/sql/parser/col_types.go, line 147 at r1 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Up to you. However I do still believe the two types here should be initialized with Width 32 and 64 respectively not 16 and 32. pkg/sql/parser/col_types_test.go, line 45 at r3 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Width: 32 pkg/sql/parser/col_types_test.go, line 46 at r3 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Width: 64 pkg/sql/parser/col_types_test.go, line 47 at r3 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Ack. I'm good with that. pkg/sql/sqlbase/table.go, line 1621 at r3 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Ack, thanks! Comments from Reviewable |
Review status: 10 of 12 files reviewed at latest revision, 5 unresolved discussions. pkg/sql/parser/col_types.go, line 147 at r1 (raw file): Previously, knz (kena) wrote…
Fixed! pkg/sql/parser/col_types_test.go, line 45 at r3 (raw file): Previously, knz (kena) wrote…
That's right thanks! pkg/sql/parser/col_types_test.go, line 46 at r3 (raw file): Previously, knz (kena) wrote…
Don.e Comments from Reviewable |
Reviewed 2 of 2 files at r6. pkg/sql/parser/col_types.go, line 144 at r6 (raw file):
Why not populate pkg/sql/sqlbase/structured.go, line 1722 at r6 (raw file):
I still think you do not need the 2nd part of this conditional, even if you decide to not support the corresponding input syntax. Comments from Reviewable |
4fb89ec
to
a46cb81
Compare
Review status: 8 of 12 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/sql/parser/col_types.go, line 144 at r6 (raw file): Previously, knz (kena) wrote…
Sure. pkg/sql/sqlbase/structured.go, line 1722 at r6 (raw file): Previously, knz (kena) wrote…
Agreed, this is before I was using default precision for the new types. Comments from Reviewable |
Reviewed 4 of 4 files at r7. Comments from Reviewable |
Nice work so far! There is a little bit more to be done to make this complete, however. The missing feature is related to type identifiers on pgwire. With this patch, even though we can create tables with e.g. To demonstrate this problem, observe the difference between the following queries: CockroachDB:
Postgres:
(Ignore the bottom 6 rows, those are Postgres internals that we don't care about). You can see the difference - Postgres reflects a different To fix this we'll need to propagate the additional column type information that you added up into the SQL type defined in Review status: 12 of 14 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. pkg/sql/logictest/testdata/logic_test/scale, line 61 at r7 (raw file):
Can you add a test that demonstrates that pkg/sql/logictest/testdata/logic_test/scale, line 76 at r7 (raw file):
We might want to consider adding a test case like pkg/sql/sqlbase/structured.proto, line 74 at r7 (raw file):
I think we don't want pkg/sql/sqlbase/table.go, line 1629 at r7 (raw file):
s/unsigend/unsigned/ pkg/sql/sqlbase/table.go, line 1636 at r7 (raw file):
nit: comment is too long - while you're in here could you please make it less than 80 characters? thanks! Comments from Reviewable |
f780027
to
e102474
Compare
Being tracked on #16769, but will split into another PR. Review status: 10 of 15 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. pkg/sql/logictest/testdata/logic_test/scale, line 61 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
That's already in logictest/table. It's a bit hard to see because I refactored it a little. pkg/sql/logictest/testdata/logic_test/scale, line 76 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. pkg/sql/sqlbase/structured.proto, line 74 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
SMALLINT is an alias for INT4 in Postgres, so not having it here would break the show create table behavior. pkg/sql/sqlbase/table.go, line 1629 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. pkg/sql/sqlbase/table.go, line 1636 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. Comments from Reviewable |
Review status: 10 of 15 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. pkg/sql/logictest/testdata/logic_test/scale, line 61 at r7 (raw file): Previously, m-schneider (Masha Schneider) wrote…
D'oh! Thanks. pkg/sql/sqlbase/structured.proto, line 74 at r7 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Right - but actually we're okay with Furthermore, only adding Comments from Reviewable |
Review status: 10 of 15 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. pkg/sql/sqlbase/structured.proto, line 74 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Comments from Reviewable |
Review status: 10 of 15 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. pkg/sql/sqlbase/structured.proto, line 74 at r7 (raw file): Previously, knz (kena) wrote…
Comments from Reviewable |
Review status: 10 of 15 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. pkg/sql/sqlbase/structured.proto, line 74 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
aw, ok thanks for explaining. Aye, good to choose a single canonical name. I'm in favor of the standard sql names: bigint/smallint Comments from Reviewable |
Review status: 3 of 15 files reviewed at latest revision, 3 unresolved discussions, some commit checks pending. pkg/sql/sqlbase/structured.proto, line 74 at r7 (raw file): Previously, knz (kena) wrote…
I added a mapping from type name to canonical type in table.go, I can move it if either of you think it should go somewhere else. Int is not the postgres canonical type for int, but I left it as such because a lot of our own code uses that. Comments from Reviewable |
I'm comfortable with the result here, but will defer to Jordan for a green light. Reviewed 12 of 12 files at r8. pkg/sql/logictest/testdata/logic_test/pg_catalog, line 1138 at r8 (raw file):
Why are these commented out? If it's intentional, add a comment above to explain why they are commented out. pkg/sql/sqlbase/table.go, line 1639 at r8 (raw file):
nit: we usually separate the comment prefix from the text with a space. Comments from Reviewable |
mod the little typo and nit comments left! Review status: 14 of 15 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. pkg/sql/logictest/testdata/logic_test/pg_catalog, line 1138 at r8 (raw file): Previously, knz (kena) wrote…
Yeah this should just have above it: ## TODO(masha): #16769 pkg/sql/sqlbase/table.go, line 1629 at r7 (raw file): Previously, m-schneider (Masha Schneider) wrote…
Hmm maybe you didn't repush these latest changes? I still see the typo and the long line unless reviewable is malfunctioning. Comments from Reviewable |
something weird happened with your branch, I'm not sure you want to see the merge commits in there? |
with postgres support of numerical types. Before this change we didn't support any of the types mentioned above. After this change we'll support those types as alias and we will check for overflow on INSERT and UPDATE. We currently won't support type checking on mathematical operations, inline with how decimals are currently implemented. Support for those operations would require a change to Datums, which is outside of the scope for this change. Closes cockroachdb#12481 Closes cockroachdb#14493
Rebase gone badly, I'm pretty sure I fixed it now. Review status: 11 of 15 files reviewed at latest revision, 4 unresolved discussions. pkg/sql/logictest/testdata/logic_test/pg_catalog, line 1138 at r8 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. pkg/sql/sqlbase/table.go, line 1629 at r7 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
I must have reverted something on my end. Fixed now! pkg/sql/sqlbase/table.go, line 1639 at r8 (raw file): Previously, knz (kena) wrote…
Done. Comments from Reviewable |
Reviewed 4 of 4 files at r10. Comments from Reviewable |
Reviewed 1 of 12 files at r1, 2 of 4 files at r7, 8 of 12 files at r8, 4 of 4 files at r10. Comments from Reviewable |
Before this change we didn't support any of the types mentioned above.
After this change we'll support those types as alias and we will check
for overflow on INSERT and UPDATE. We currently won't support type checking
on mathematical operations, inline with how decimals are currently implemented.
Support for those operations would require a change to Datums, which is outside
of the scope for this change.
Closes #12481
Closes #14493