Details
Description
Dear MariaDB Developer:
I found a performance bug that seems different from the usual 'Impossible WHERE' cases. The query plan does not show the typical 'Impossible WHERE' hint, but the query still behaves inefficiently when it logically shouldn’t execute at all.
q1: SELECT * FROM TABLES CROSS JOIN VIEWS WHERE TABLES.TABLE_NAME != 'accounts'
q2: SELECT * FROM TABLES CROSS JOIN VIEWS WHERE TABLES.TABLE_NAME = 'accounts';
Since q1 and q2 have opposite WHERE clause, q1 INTERSECT q2 should always produce empty set and without physical read.
MariaDB [information_schema]> FLUSH STATUS;
Query OK, 0 rows affected (0.000 sec)
MariaDB [information_schema]> SELECT * FROM TABLES CROSS JOIN VIEWS WHERE TABLES.TABLE_NAME != 'accounts' INTERSECT SELECT * FROM TABLES CROSS JOIN VIEWS WHERE TABLES.TABLE_NAME = 'accounts';
Empty set (4.121 sec)
MariaDB [information_schema]> SHOW SESSION STATUS LIKE 'Handler_read%';
--------------------------------+
| Variable_name | Value |
--------------------------------+
| Handler_read_first | 0 |
| Handler_read_key | 228 |
| Handler_read_last | 0 |
| Handler_read_next | 0 |
| Handler_read_prev | 0 |
| Handler_read_retry | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_deleted | 0 |
| Handler_read_rnd_next | 146838 |
--------------------------------+
9 rows in set (0.001 sec)
MariaDB [information_schema]> EXPLAIN format=json SELECT * FROM TABLES CROSS JOIN VIEWS WHERE TABLES.TABLE_NAME != 'accounts' INTERSECT SELECT * FROM TABLES CROSS
JOIN VIEWS WHERE TABLES.TABLE_NAME = 'accounts';
{
"query_block": {
"union_result": {
"table_name": "<intersect1,2>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
"select_id": 1,
"cost": 1.09287406,
"nested_loop": [
{
"table":
},
{
"block-nl-join": {
"table":
,
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL"
}
}
]
}
},
{
"query_block": {
"select_id": 2,
"operation": "INTERSECT",
"cost": 1.09287406,
"nested_loop": [
{
"table":
},
{
"block-nl-join": {
"table":
,
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL"
}
}
]
}
}
]
}
}
}
Thank you for your time and attention to this issue. I greatly appreciate your assistance and look forward to hearing your thoughts.
Best regards,
Attachments
Issue Links
- relates to
-
MDEV-36658 EXCEPT with identical left/right queries isn't eliminated
-
- Confirmed
-
-
MDEV-36687 The opposite HAVING clause intersects and is always an empty set.
-
- Confirmed
-