-
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
Mistakenly assumes Long value as INT4 on update #67605
Comments
Hello, I am Blathers. I am here to help you get the issue triaged. Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here. I was unable to automatically find someone to ping. If we have not gotten back to your issue within a few business days, you can try the following:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Thanks for this report @jorgeacetozi! The example you gave is really helpful. It looks like this is related to the fact that in v21.1 we started using our new vectorized execution engine in more places. Specifically, in this case, the vectorized This is confirmed by adding the following lines to your example before inserting data:
I used a debugger and tracked down the source of the error to this line of code: cockroach/pkg/sql/colexec/colexecbase/cast.eg.go Line 3119 in 1fd13c9
We'll work more to see if it can be fixed. cc @jordanlewis |
@rafiss on a quick glance I don't think that the vectorized cast is to blame - more likely the typing information obtained during the planning of the query says that the value must be INT4, and the vectorized engine simply follows that. |
@yuzefovich the one extra detail that is relevant here is that there is no error if you remove this part of the code:
In other words, remove line 3 of:
Do you know why any type-checking logic would depend on whether this UPDATE statement ran or not? By the way, I confirmed that the non-vectorized engine does not attempt to perform this cast. So I don't see how this would be a planning issue. Could you point me to the code where the vectorized engine does the type-checking you are referring to? Or could you point me to where the vectorized engine decides that it needs to include a |
OK, I was able to track it down a bit further and find the places to look. In this part of the optimizer: cockroach/pkg/sql/opt/optbuilder/update.go Line 226 in 31cdc0e
We have a cockroach/pkg/sql/sem/tree/type_check.go Lines 1533 to 1552 in 31cdc0e
Again, in that code I think the problem is that right after this, another There's a couple things I'd say:
I think the problem would have existed in 20.2 as well, but the issue just surfaced because 21.1 changed the vectorized engine to on by default. |
Could you share your JDBI code? I see that JDBI does have an ArgumentFactory that should handle But it looks like the |
I figured out my first point about re-preparing the statement: #67651 I tested locally and confirmed that your example works with this change. |
The SQL type `INTEGER` often (always?) maps to integer types which are only 32 bits (4 bytes) long while `BIGINT` maps to integer types which are 64 bits (8 bytes) long. Considering this, mapping `long` and `Long` to `BIGINT` instead of `INTEGER` seems to make more sense. FWIW, this is motivated by a bug we discovered in CockroachDB when sending `NULL` values which were sent as `NULL::INT4` by Jdbi 3.20.1 instead of `NULL::INT8` for a column declared as `INT8`. cockroachdb/cockroach#67605
It indeed works for us in the case described (tested against a locally-built SNAPSHOT version of Jdbi with the necessary changes). The respective PR against Jdbi is here: jdbi/jdbi#1902 |
Thanks Rafi for the investigation!
The row-by-row engine doesn't respect widths of integers and always operates as if on INT8 whereas the vectorized engine does respect the widths and is strict about them. |
The SQL type `INTEGER` often (always?) maps to integer types which are only 32 bits (4 bytes) long while `BIGINT` maps to integer types which are 64 bits (8 bytes) long. Considering this, mapping `long` and `Long` to `BIGINT` instead of `INTEGER` seems to make more sense. FWIW, this is motivated by a bug we discovered in CockroachDB when sending `NULL` values which were sent as `NULL::INT4` by Jdbi 3.20.1 instead of `NULL::INT8` for a column declared as `INT8`. cockroachdb/cockroach#67605
Thank you for reporting and sending a PR to fix this bug! Jdbi 3.21.0 was just released with the fix and should be available on Maven Central shortly. |
Describe the problem
After updating CockroachDB from version
20.2.10
to21.1.5
, we started getting this exception when issuing an update:Unexpected Exception during request processing - return 500 Internal Server Error org.jdbi.v3.core.statement.UnableToExecuteStatementException: org.postgresql.util.PSQLException: ERROR: integer out of range for type int4
After some debugging, we were able to figured out that the issue happens when:
To Reproduce
We set up a simple unit test that spins up a CockroachDB container (version
21.1.5
) and uses Postgres JDBC Driver (version42.2.23
) to reproduce the steps described:If the CockroachDB container version in this test is set to
20.2.10
, then the test work as expected and the issue does not happen.Expected behavior
The expectation is that the last update works properly since the value being sent is a Long and the column type is a INT8.
Environment:
Additional context
Unexpected behavior in update queries.
The text was updated successfully, but these errors were encountered: