Details
-
Bug
-
Status: Open (View Workflow)
-
Minor
-
Resolution: Unresolved
-
12.0.2
-
None
-
None
-
ubuntu 22.04
Description
Hi, MariaDB developers.
Thanks for reading my report.
Since "FALSE and any_expr" is FALSE. MariaDB can apply short-circuit evaluation to it. When the false expression is "0", "false", or "2<1", etc., the optimizer can rewrite it to "FALSE" directly. In another scenario, the executor can short-circuit when determining that one expression is false after scanning one table, and skip scanning another table.
You can reproduce these issues as follows:
-- Create table t1 with 1 row and t2 with 10,000,000 rows
|
CREATE TABLE t1(c0 INT8); |
CREATE TABLE t2(c0 INT8); |
|
INSERT INTO t1 VALUES(1); |
INSERT INTO t2 SELECT seq FROM seq_1_to_10000000; |
|
|
-- The optimizer can rewrite such a SQL statement to "SELECT FALSE" directly
|
SELECT false AND (SELECT MIN(c0) FROM t2)<0; |
+--------------------------------------+ |
| false AND (SELECT MIN(c0) FROM t2)<0 | |
+--------------------------------------+ |
| 0 |
|
+--------------------------------------+ |
1 row in set (0.002 sec) |
|
SELECT (SELECT MIN(c0) FROM t2)<0 AND false; |
+--------------------------------------+ |
| (SELECT MIN(c0) FROM t2)<0 AND false | |
+--------------------------------------+ |
| 0 |
|
+--------------------------------------+ |
1 row in set (1.793 sec) |
|
-- The executor can short-circuit when determining that one expression is false after scanning one table, and skip scanning another table.
|
SELECT (SELECT MIN(c0) FROM t1)<0 AND (SELECT MIN(c0) FROM t2)<0; |
+-----------------------------------------------------------+ |
| (SELECT MIN(c0) FROM t1)<0 AND (SELECT MIN(c0) FROM t2)<0 | |
+-----------------------------------------------------------+ |
| 0 |
|
+-----------------------------------------------------------+ |
1 row in set (0.016 sec) |
|
SELECT (SELECT MIN(c0) FROM t2)>0 AND (SELECT MIN(c0) FROM t1)<0; |
+-----------------------------------------------------------+ |
| (SELECT MIN(c0) FROM t2)>0 AND (SELECT MIN(c0) FROM t1)<0 | |
+-----------------------------------------------------------+ |
| 0 |
|
+-----------------------------------------------------------+ |
1 row in set (1.657 sec) |
Best regards,
Jinhui Lai
Attachments
Issue Links
- relates to
-
MDEV-37713 Missed optimization opportunities of "TRUE OR any_expr" in SELECT clause
-
- Open
-