forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: fix BPCHAR type and CASE typing
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.
- Loading branch information
Showing
31 changed files
with
6,552 additions
and
66 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
pkg/ccl/kvccl/kvtenantccl/upgradeinterlockccl/generated_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
query T | ||
SELECT 'foo'::BPCHAR | ||
---- | ||
foo | ||
|
||
statement ok | ||
CREATE TABLE t (c BPCHAR PRIMARY KEY, FAMILY (c)) | ||
|
||
statement ok | ||
INSERT INTO t VALUES ('foo'), ('ba'), ('c'), ('foobarbaz') | ||
|
||
query T rowsort | ||
SELECT c FROM t | ||
---- | ||
foo | ||
ba | ||
c | ||
foobarbaz | ||
|
||
query T | ||
SELECT create_statement FROM [SHOW CREATE TABLE t] | ||
---- | ||
CREATE TABLE public.t ( | ||
c BPCHAR NOT NULL, | ||
CONSTRAINT t_pkey PRIMARY KEY (c ASC), | ||
FAMILY fam_0_c (c) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# LogicTest: local | ||
|
||
# Regression test for #127889. CASE-like expressions should not impose type | ||
# widths of one branch on other branches. | ||
subtest regression_127889 | ||
|
||
query T | ||
SELECT CASE WHEN true THEN 'foo'::TEXT ELSE 'b'::CHAR END | ||
---- | ||
foo | ||
|
||
query T | ||
SELECT COALESCE(NULL::CHAR, 'bar'::CHAR(2)) | ||
---- | ||
ba | ||
|
||
query T | ||
SELECT IF(false, 'foo'::CHAR, 'bar'::CHAR(2)) | ||
---- | ||
ba | ||
|
||
query T | ||
SELECT CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END | ||
---- | ||
foo | ||
|
||
query T | ||
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::CHAR | ||
---- | ||
f | ||
|
||
query T | ||
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::BPCHAR | ||
---- | ||
foo | ||
|
||
query R | ||
SELECT CASE WHEN true THEN 1.2345::DECIMAL(5, 4) ELSE NULL::DECIMAL(10, 2) END | ||
---- | ||
1.2345 | ||
|
||
query R | ||
SELECT CASE WHEN false THEN NULL::DECIMAL(10, 2) ELSE 1.2345::DECIMAL(5, 4) END | ||
---- | ||
1.2345 | ||
|
||
subtest end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.