-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-37713/MDEV-37714 Fold boolean literals in SELECT-list #4754
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
Open
jaeheonshim
wants to merge
1
commit into
MariaDB:main
Choose a base branch
from
jaeheonshim:MDEV-37713
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,95 @@ | ||
| # | ||
| # MDEV-37713/MDEV-37714: Test correctness of boolean folding | ||
| # | ||
| SELECT TRUE AND TRUE; | ||
| TRUE AND TRUE | ||
| 1 | ||
| SELECT TRUE AND FALSE; | ||
| TRUE AND FALSE | ||
| 0 | ||
| SELECT FALSE AND TRUE; | ||
| FALSE AND TRUE | ||
| 0 | ||
| SELECT FALSE AND FALSE; | ||
| FALSE AND FALSE | ||
| 0 | ||
| SELECT TRUE OR TRUE; | ||
| TRUE OR TRUE | ||
| 1 | ||
| SELECT TRUE OR FALSE; | ||
| TRUE OR FALSE | ||
| 1 | ||
| SELECT TRUE OR TRUE; | ||
| TRUE OR TRUE | ||
| 1 | ||
| SELECT FALSE OR FALSE; | ||
| FALSE OR FALSE | ||
| 0 | ||
| SELECT TRUE AND NULL; | ||
| TRUE AND NULL | ||
| NULL | ||
| SELECT NULL AND TRUE; | ||
| NULL AND TRUE | ||
| NULL | ||
| SELECT FALSE AND NULL; | ||
| FALSE AND NULL | ||
| 0 | ||
| SELECT NULL AND FALSE; | ||
| NULL AND FALSE | ||
| 0 | ||
| SELECT TRUE OR NULL; | ||
| TRUE OR NULL | ||
| 1 | ||
| SELECT NULL OR TRUE; | ||
| NULL OR TRUE | ||
| 1 | ||
| SELECT FALSE OR NULL; | ||
| FALSE OR NULL | ||
| NULL | ||
| SELECT NULL OR FALSE; | ||
| NULL OR FALSE | ||
| NULL | ||
| SELECT NULL AND NULL; | ||
| NULL AND NULL | ||
| NULL | ||
| SELECT NULL OR NULL; | ||
| NULL OR NULL | ||
| NULL | ||
| SELECT NOT NULL OR TRUE, NOT NULL AND FALSE; | ||
| NOT NULL OR TRUE NOT NULL AND FALSE | ||
| 1 0 | ||
| SELECT NULL AND TRUE, NULL OR FALSE; | ||
| NULL AND TRUE NULL OR FALSE | ||
| NULL NULL | ||
| PREPARE s FROM 'SELECT NOT NULL OR TRUE, NOT NULL AND FALSE'; | ||
| EXECUTE s; | ||
| NOT NULL OR TRUE NOT NULL AND FALSE | ||
| 1 0 | ||
| EXECUTE s; | ||
| NOT NULL OR TRUE NOT NULL AND FALSE | ||
| 1 0 | ||
| DEALLOCATE PREPARE s; | ||
| CREATE TABLE t1(c0 INT); | ||
| CREATE TABLE t2(c0 INT); | ||
| INSERT INTO t1 VALUES(1),(2),(3); | ||
| INSERT INTO t2 VALUES(4),(5),(6); | ||
| SELECT (SELECT MIN(c0) FROM t2)<0 OR true; | ||
| (SELECT MIN(c0) FROM t2)<0 OR true | ||
| 1 | ||
| SELECT ((SELECT MIN(c0) FROM t2)<0 AND false) OR (SELECT MAX(c0) FROM t1)>0 AS f; | ||
| f | ||
| 1 | ||
| ANALYZE SELECT (SELECT MIN(c0) FROM t2)<0 OR true; | ||
| id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra | ||
| 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used | ||
| ANALYZE SELECT ((SELECT MIN(c0) FROM t2)<0 AND false) OR (SELECT MAX(c0) FROM t1)>0; | ||
| id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra | ||
| 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used | ||
| 3 SUBQUERY t1 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 | ||
| CREATE VIEW v1 AS SELECT (SELECT MIN(c0) FROM t2)<0 OR true FROM t1; | ||
| SHOW CREATE VIEW v1; | ||
| View Create View character_set_client collation_connection | ||
| v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (select min(`t2`.`c0`) from `t2`) < 0 or 1 AS `(SELECT MIN(c0) FROM t2)<0 OR true` from `t1` latin1 latin1_swedish_ci | ||
| DROP VIEW v1; | ||
| DROP TABLE t1,t2; | ||
| # End of 13.1 tests |
This file contains hidden or 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,55 @@ | ||
| --echo # | ||
| --echo # MDEV-37713/MDEV-37714: Test correctness of boolean folding | ||
| --echo # | ||
|
|
||
| SELECT TRUE AND TRUE; | ||
| SELECT TRUE AND FALSE; | ||
| SELECT FALSE AND TRUE; | ||
| SELECT FALSE AND FALSE; | ||
| SELECT TRUE OR TRUE; | ||
| SELECT TRUE OR FALSE; | ||
| SELECT TRUE OR TRUE; | ||
| SELECT FALSE OR FALSE; | ||
|
|
||
| SELECT TRUE AND NULL; | ||
| SELECT NULL AND TRUE; | ||
| SELECT FALSE AND NULL; | ||
| SELECT NULL AND FALSE; | ||
| SELECT TRUE OR NULL; | ||
| SELECT NULL OR TRUE; | ||
| SELECT FALSE OR NULL; | ||
| SELECT NULL OR FALSE; | ||
|
|
||
| SELECT NULL AND NULL; | ||
| SELECT NULL OR NULL; | ||
|
|
||
| SELECT NOT NULL OR TRUE, NOT NULL AND FALSE; | ||
| SELECT NULL AND TRUE, NULL OR FALSE; | ||
|
|
||
| PREPARE s FROM 'SELECT NOT NULL OR TRUE, NOT NULL AND FALSE'; | ||
| EXECUTE s; | ||
| EXECUTE s; | ||
| DEALLOCATE PREPARE s; | ||
|
|
||
| CREATE TABLE t1(c0 INT); | ||
| CREATE TABLE t2(c0 INT); | ||
| INSERT INTO t1 VALUES(1),(2),(3); | ||
| INSERT INTO t2 VALUES(4),(5),(6); | ||
|
|
||
| SELECT (SELECT MIN(c0) FROM t2)<0 OR true; | ||
| SELECT ((SELECT MIN(c0) FROM t2)<0 AND false) OR (SELECT MAX(c0) FROM t1)>0 AS f; | ||
|
|
||
| # Folds to constant true, t2 subselect is eliminated | ||
| ANALYZE SELECT (SELECT MIN(c0) FROM t2)<0 OR true; | ||
|
|
||
| # (... AND false) folds to false and is dropped; only the t1 subselect remains | ||
| ANALYZE SELECT ((SELECT MIN(c0) FROM t2)<0 AND false) OR (SELECT MAX(c0) FROM t1)>0; | ||
|
|
||
| # Check that views are not malformed by the folding | ||
| CREATE VIEW v1 AS SELECT (SELECT MIN(c0) FROM t2)<0 OR true FROM t1; | ||
| SHOW CREATE VIEW v1; | ||
|
|
||
| DROP VIEW v1; | ||
| DROP TABLE t1,t2; | ||
|
|
||
| --echo # End of 13.1 tests | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.