Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Minor
-
Resolution: Unresolved
-
12.3, 13.0, 12.3.3
-
None
-
Linux x86_64 with lower_case_table_names=0
Description
With optimizer_record_context enabled, an optimizer trace for a join between two tables whose names differ only by letter case contains only one table DDL. Both tables participate in the query and return the correct result.
Reproducer
Run the following SQL on a case-sensitive installation where @@lower_case_table_names is 0:
CREATE DATABASE ctx; |
USE ctx; |
CREATE TABLE item (a INT) ENGINE=InnoDB; |
CREATE TABLE Item (b INT) ENGINE=InnoDB; |
INSERT INTO item VALUES (1); |
INSERT INTO Item VALUES (2); |
|
|
SELECT @@lower_case_table_names AS case_mode; |
SET optimizer_record_context=1; |
SET optimizer_trace='enabled=on'; |
|
|
SELECT l.a + r.b AS joined_value |
FROM item AS l |
CROSS JOIN Item AS r; |
|
|
SELECT JSON_LENGTH(JSON_EXTRACT(trace, '$**.ddl')) AS ddl_count, |
JSON_EXTRACT(trace, '$**.ddl') AS ddls, |
MISSING_BYTES_BEYOND_MAX_MEM_SIZE AS missing_bytes |
FROM information_schema.optimizer_trace; |
|
|
RENAME TABLE Item TO item2; |
|
|
SELECT l.a + r.b AS control_joined_value |
FROM item AS l |
CROSS JOIN item2 AS r; |
|
|
SELECT JSON_LENGTH(JSON_EXTRACT(trace, '$**.ddl')) AS control_ddl_count, |
MISSING_BYTES_BEYOND_MAX_MEM_SIZE AS missing_bytes |
FROM information_schema.optimizer_trace; |
|
|
SET optimizer_record_context=0; |
DROP DATABASE ctx; |
Decisive observation
For the case-distinct names, the query reads both tables and returns 3, but the trace reports one DDL and no truncation. The sole captured DDL is for Item:
case_mode
|
0
|
joined_value
|
3
|
ddl_count ddls missing_bytes
|
1 ["CREATE TABLE `Item` (\n `b` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci"] 0
|
After renaming Item to the noncolliding name item2, the otherwise equivalent join still returns 3 and the trace contains both DDL entries:
control_joined_value
|
3
|
control_ddl_count missing_bytes
|
2 0
|
Semantic mismatch
The first join has two distinct participating database objects, so its captured context should contain two DDL entries. A DDL count of 1 makes the recorded context incomplete. The zero missing_bytes value shows that trace truncation does not account for the omission, while the renamed control demonstrates that both entries are captured when their names do not collide under case-insensitive comparison.
This occurs when optimizer context is recorded for a query using distinct table names that differ only by letter case on a case-sensitive installation.
Attachments
Issue Links
- is caused by
-
MDEV-36483 Optimizer Trace Replay step #1: dump DDLs of tables/views
-
- Closed
-
- relates to
-
MDEV-17558 Problems with INFORMATION_SCHEMA.TABLES.TABLE_NAME and --lower-case-table-names=0
-
- Open
-