-
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
opt: fix BPCHAR type and CASE typing #129007
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! Assuming the test cases check out,
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)
pkg/sql/logictest/testdata/logic_test/case
line 71 at r1 (raw file):
ba subtest end
I'd be curious to see a few additional tests:
SELECT CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END;
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::CHAR;
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::BPCHAR;
In Postgres:
postgres=# SELECT CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END;
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::CHAR;
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::BPCHAR;
case
------
foo
(1 row)
bpchar
--------
f
(1 row)
bpchar
--------
foo
(1 row)
8a0a160
to
6c9f9e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball)
pkg/sql/logictest/testdata/logic_test/case
line 71 at r1 (raw file):
Previously, DrewKimball (Drew Kimball) wrote…
I'd be curious to see a few additional tests:
SELECT CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END; SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::CHAR; SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::BPCHAR;
In Postgres:
postgres=# SELECT CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END; SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::CHAR; SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::BPCHAR; case ------ foo (1 row) bpchar -------- f (1 row) bpchar -------- foo (1 row)
Done.
6c9f9e8
to
2860e1c
Compare
I realized this is related to #108360. I'll have a follow-up PR to address a few more things I found (mentioned in that issue). |
I actually need to do the follow-up work in this same PR to get the tests to pass. We need to represent a |
2860e1c
to
d310e8a
Compare
9913264
to
35086d0
Compare
3867c68
to
7db5e7c
Compare
7db5e7c
to
98e33e2
Compare
I had to adjust some of the UDF resolution logic to find overloads with |
This commit addresses inconsistencies from Postgres' behavior. First, it makes the `BPCHAR` type distinct from `CHAR`. The former is a blank-padded character type with no type width, meaning that it could have any length. The latter is a blank-padded character type with a type width of exactly 1 - it is essentially an alias of `CHAR(1)`. Previously, a column of type `BPCHAR` behaved the same as a column of type `CHAR(1)` - it enforced a length limit of 1. Second, the typing of `CASE` and `CASE`-like expressions has been fixed. The branches of these conditionals is no longer forced to have the same type-width. Fixes cockroachdb#127889 Fixes cockroachdb#108360 Release note (bug fix): A bug has been fixed that caused incorrect evaluation of `CASE`, `COALESCE`, and `IF` expressions with branches producing fixed-width string-like types, such as `CHAR`. In addition, the `BPCHAR` type has been fixed so that it no longer incorrectly imposes a length limit of 1.
98e33e2
to
4a11c7d
Compare
@DrewKimball mind taking one more quick look? |
Friendly ping @DrewKimball. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r2, 10 of 22 files at r3, 16 of 16 files at r4, 2 of 2 files at r5, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)
TFTR! bors r+ |
Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches. Issue #127889: branch-release-23.1. Issue #108360: branch-release-23.1, branch-release-23.2, branch-release-24.1, branch-release-24.2. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from 4a11c7d to blathers/backport-release-23.1-129007: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 23.1.x failed. See errors above. error creating merge commit from 4a11c7d to blathers/backport-release-23.2-129007: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 23.2.x failed. See errors above. error creating merge commit from 4a11c7d to blathers/backport-release-24.1-129007: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 24.1.x failed. See errors above. error creating merge commit from 4a11c7d to blathers/backport-release-24.2-129007: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 24.2.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
A TODO that was addressed in cockroachdb#129007 has been removed. Release note: None
132338: pgwire: reduce allocations when writing CHAR(N) datums r=mgartner a=mgartner `ResolveBlankPaddedCharBytes` has been replaced with a more efficient method of padding `CHAR(N)` datums with trailing spaces. Epic: None Release note: None 132501: opt: remove outdated TODO r=mgartner a=mgartner A TODO that was addressed in #129007 has been removed. Release note: None 132563: kvserver: skip empty RACv1 dispatches r=kvoli a=pav-kv This commit skips creating a `RaftMessageRequest` in the fallback RAC admission dispatch code if there are no pending RACv1 dispatches. Previously, it would send an empty `RaftMessageRequest` which would cause an error in the receiver's `handleRaftRequest`, [message drops](https://github.com/cockroachdb/cockroach/blob/9e12f67ff4ad860651c40dcef489a1556d1d11b7/pkg/kv/kvserver/raft_transport.go#L451-L456), and the receiver's message queue to restart after the following warning: ``` unable to accept Raft message from (n0,s0):?: no handler registered for (n0,s0):? ``` Related to #129508 Co-authored-by: Marcus Gartner <[email protected]> Co-authored-by: Pavel Kalinnikov <[email protected]>
A TODO that was addressed in cockroachdb#129007 has been removed. Release note: None
This commit addresses inconsistencies from Postgres' behavior. First, it
makes the
BPCHAR
type distinct fromCHAR
. The former is ablank-padded character type with no type width, meaning that it could
have any length. The latter is a blank-padded character type with a type
width of exactly 1 - it is essentially an alias of
CHAR(1)
.Previously, a column of type
BPCHAR
behaved the same as a column oftype
CHAR(1)
- it enforced a length limit of 1.Second, the typing of
CASE
andCASE
-like expressions has been fixed.The branches of these conditionals is no longer forced to have the same
type-width.
Fixes #127889
Fixes #108360
Release note (bug fix): A bug has been fixed that caused incorrect
evaluation of
CASE
,COALESCE
, andIF
expressions with branchesproducing fixed-width string-like types, such as
CHAR
. In addition,the
BPCHAR
type has been fixed so that it no longer incorrectlyimposes a length limit of 1.