-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
33221: sql: always use typed expressions for shift on int r=mjibson a=mjibson Previously the expressions 1 << 63 and 1::int << 63 would return positive and negative results, respectively. This was because constant folding in the first case is not subject to 2s complent that causes negative ints in the second case. Change shift on int to not fold. This prevents the surprising behavior described above in addition to other bugs where shifting by a large amount could allocate huge amounts of memory and crash the process. Fixes #32682 Release note (sql change): Shift operators on integers now always operate on explicit types instead of possibly an untyped constant. They also now return an error if the right-side operand is out of range. 33222: pgwire: test \u0001 in JSON pgwire encoding r=mjibson a=mjibson Verify that we handle "\u0001" JSON strings identically to postgres. The printing of \u0001 instead of some other character is correct, and the same as what postgres does. (We do not test \u0000 here because postgres rejects it as a valid string, even though we accept it.) Closes #33165 Release note: None Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
- Loading branch information
Showing
6 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# LogicTest: local local-opt local-parallel-stmts fakedist fakedist-opt fakedist-metadata | ||
|
||
# Check non-constant eval | ||
|
||
statement ok | ||
CREATE TABLE t AS SELECT 1 AS i | ||
|
||
statement error shift argument out of range | ||
SELECT i << 64 FROM t | ||
|
||
statement error shift argument out of range | ||
SELECT i >> 64 FROM t | ||
|
||
statement error shift argument out of range | ||
SELECT i << -1 FROM t | ||
|
||
statement error shift argument out of range | ||
SELECT i >> -1 FROM t | ||
|
||
query II | ||
SELECT i << 63 >> 63, i << 62 >> 62 FROM t | ||
---- | ||
-1 1 | ||
|
||
# Check constant folding | ||
|
||
statement error shift argument out of range | ||
SELECT 1 << 64 | ||
|
||
statement error shift argument out of range | ||
SELECT 1 >> 64 | ||
|
||
statement error shift argument out of range | ||
SELECT 1 << -1 | ||
|
||
statement error shift argument out of range | ||
SELECT 1 >> -1 | ||
|
||
query II | ||
SELECT 1 << 63 >> 63, 1 << 62 >> 62 | ||
---- | ||
-1 1 | ||
|
||
# Ensure that shift returns the same result as an int or a constant | ||
|
||
query II | ||
SELECT 1 << 63 >> 63, 1::INT << 63 >> 63 | ||
---- | ||
-1 -1 |
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
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