-
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: support Postgres syntax names for all types #14493
Comments
|
There are a few questions here. I have opinions on some. First, do we care to implement right-sized backing encodings for smaller datatypes, or is backing these datatypes by full-sized ones sufficient? I think that for now the latter is okay. Second, if we choose to not have different backing encodings for these types, do we care to preserve the user's intention when creating a table, or is it okay to just make them aliases at the parser level? In other words, if a user creates a table with an Third, if we are going to preserve the user-intended types (as I think we have to), do we need to have separate type tags (ColumnType.Kind) for these types, or should we introduce some kind of aliasing mechanism at the ColumnType proto level? I don't know the answer to this - either would work okay. The downside to having separate type tags is that it's ugly (in my opinion) to have a lot of repeated, similar values there. The upside is that it might make the code cleaner and provide an easier migration path if we do decide to eventually store these values right-sized. Fourth, are we going to truncate inputs to smaller datatypes? I think we probably should. |
I agree on 1-3, if I understand what you mean for 4 it's also an option to just error out if a value is out of range. It's what Postgres does:
I suspect if someone cares to explicitly use |
Oh, yeah - that makes a lot more sense. Forget truncation - let's just error! 👍 |
I agree on 1-3 too and error is a great idea! If we choose to go this way vs making them aliases, what would be the logic for mathematical operations on them? If int4*int4 can't fit into an int4, do we error or return the value? |
Good question, FWIW, Postgres errors:
But I think either sounds fine to me? Since we'd still error if we try to actually tried to insert it into a column. |
Good question. There's another decision we have to make about this project that I didn't mention about: are we going to represent all of these types differently at the Currently, we only have one kind of integer datum: I think that adding new datum types for all of these will be a pretty big pain - I advise against it. The reason that it'll be painful has to do with the way we've implemented comparison and binary operators - check out Instead, I think that ignoring potential smaller-type overflows during math operations is the way to go. It will produce different behavior from Postgres in certain cases, but I think it's an acceptable tradeoff. For example, the following errors in Postgres, but wouldn't error in our implementation:
|
I agree that adding new datums or wrapping DInt into something like OidWrapper might not be worth it for math operations. I was however planning on enforcing the types on Insert and Update because we do have the column descriptors at that stage. @knz what are your thoughts? |
I think I am seeing wisdom in TiDB's approach, where all the datums are implemented via the same struct. In that struct there is a SQL type field and then next to this multiple fields of each Go type, with only one that carry the value per SQL type.
How would this make you feel? (I suggest you have a brief look at the TiDB source code to see what I mean) |
(incidentally, this would be walking a path towards a common endpoint with the IR work David was undertaking) |
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
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
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
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
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
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
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
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
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
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
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
We should consider supporting the Postgres syntax for all of the types whose Postgres OID we support via pgwire and claim to support via
pg_catalog.pg_type
.For instance, our integer type is named
INT
, but we support theint2
,int4
, andint8
types via their OID in pgwire and inpg_type
. We should consider supporting using the type namesINT2
,INT4
, andINT8
as syntax in SQL statements. They would just be aliases for ourINT
type, the same way their OIDs are, since we don't support storing integers smaller thanint8
.The text was updated successfully, but these errors were encountered: