Skip to content

Commit a0cb755

Browse files
author
Varun
committed
MDEV-18880: Optimizer trace prints date in hexadecimal
Introduced a print_key_value function to makes sure that the trace prints data in readable format for readable characters and the rest of the characters are printed as hexadecimal.
1 parent 40ff801 commit a0cb755

File tree

9 files changed

+501
-31
lines changed

9 files changed

+501
-31
lines changed

mysql-test/main/opt_trace.result

Lines changed: 292 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
14461446
{
14471447
"index": "id",
14481448
"covering": true,
1449-
"ranges": ["(0x24a20f) <= (a)"],
1449+
"ranges": ["(2001-01-04) <= (a)"],
14501450
"rows": 9,
14511451
"cost": 2.35
14521452
}
@@ -1462,7 +1462,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
14621462
"rows": 9,
14631463
"cost": 2.35,
14641464
"key_parts_used_for_access": ["id"],
1465-
"ranges": ["(0x24a20f) <= (a)"],
1465+
"ranges": ["(2001-01-04) <= (a)"],
14661466
"chosen": false,
14671467
"cause": "cost"
14681468
},
@@ -1624,7 +1624,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
16241624
{
16251625
"index": "id",
16261626
"covering": true,
1627-
"ranges": ["(0x24a20f) <= (a) <= (0x24a20f)"],
1627+
"ranges": ["(2001-01-04) <= (a) <= (2001-01-04)"],
16281628
"rows": 9,
16291629
"cost": 2.35
16301630
}
@@ -1640,7 +1640,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
16401640
"rows": 9,
16411641
"cost": 2.35,
16421642
"key_parts_used_for_access": ["id", "a"],
1643-
"ranges": ["(0x24a20f) <= (a) <= (0x24a20f)"],
1643+
"ranges": ["(2001-01-04) <= (a) <= (2001-01-04)"],
16441644
"chosen": false,
16451645
"cause": "cost"
16461646
},
@@ -6130,7 +6130,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
61306130
"index": "start_date",
61316131
"ranges":
61326132
[
6133-
"(0x4ac60f,NULL) < (start_date,end_date)"
6133+
"(2019-02-10,NULL) < (start_date,end_date)"
61346134
],
61356135
"rowid_ordered": false,
61366136
"using_mrr": false,
@@ -6214,7 +6214,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
62146214
"index": "i_b",
62156215
"ranges":
62166216
[
6217-
"(0xd95b94336a9946a39cf5b58cfe772d8c) <= (b) <= (0xd95b94336a9946a39cf5b58cfe772d8c)"
6217+
"(\xD9[\x943j\x99F\xA3\x9C\xF5\xB5\x8C\xFEw-\x8C) <= (b) <= (\xD9[\x943j\x99F\xA3\x9C\xF5\xB5\x8C\xFEw-\x8C)"
62186218
],
62196219
"rowid_ordered": true,
62206220
"using_mrr": false,
@@ -6268,4 +6268,290 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
62686268
}
62696269
]
62706270
drop table t1;
6271+
#
6272+
# MDEV-18880: Optimizer trace prints date in hexadecimal
6273+
#
6274+
CREATE TABLE t1(i INT PRIMARY KEY, b VARCHAR(10) CHARSET BINARY , INDEX i_b(b));
6275+
INSERT INTO t1 VALUES (1, 'ab\n');
6276+
INSERT INTO t1 VALUES (2, NULL);
6277+
set optimizer_trace=1;
6278+
EXPLAIN SELECT * FROM t1 WHERE b='ab\n';
6279+
id select_type table type possible_keys key key_len ref rows Extra
6280+
1 SIMPLE t1 ref i_b i_b 13 const 1 Using index condition
6281+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6282+
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
6283+
[
6284+
6285+
{
6286+
"range_scan_alternatives":
6287+
[
6288+
6289+
{
6290+
"index": "i_b",
6291+
"ranges":
6292+
[
6293+
"(ab\x0A) <= (b) <= (ab\x0A)"
6294+
],
6295+
"rowid_ordered": true,
6296+
"using_mrr": false,
6297+
"index_only": false,
6298+
"rows": 1,
6299+
"cost": 2.3787,
6300+
"chosen": true
6301+
}
6302+
],
6303+
"analyzing_roworder_intersect":
6304+
{
6305+
"cause": "too few roworder scans"
6306+
},
6307+
"analyzing_index_merge_union":
6308+
[
6309+
]
6310+
}
6311+
]
6312+
ALTER TABLE t1 modify column b BINARY(10) AFTER i;
6313+
EXPLAIN SELECT * FROM t1 WHERE b='ab\n';
6314+
id select_type table type possible_keys key key_len ref rows Extra
6315+
1 SIMPLE t1 ref i_b i_b 11 const 1 Using index condition
6316+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6317+
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
6318+
[
6319+
6320+
{
6321+
"range_scan_alternatives":
6322+
[
6323+
6324+
{
6325+
"index": "i_b",
6326+
"ranges":
6327+
[
6328+
"(ab\x0A\x00\x00\x00\x00\x00\x00\x00) <= (b) <= (ab\x0A\x00\x00\x00\x00\x00\x00\x00)"
6329+
],
6330+
"rowid_ordered": true,
6331+
"using_mrr": false,
6332+
"index_only": false,
6333+
"rows": 1,
6334+
"cost": 2.3785,
6335+
"chosen": true
6336+
}
6337+
],
6338+
"analyzing_roworder_intersect":
6339+
{
6340+
"cause": "too few roworder scans"
6341+
},
6342+
"analyzing_index_merge_union":
6343+
[
6344+
]
6345+
}
6346+
]
6347+
ALTER TABLE t1 modify column b VARBINARY(10) AFTER i;
6348+
EXPLAIN SELECT * FROM t1 WHERE b='ab\n';
6349+
id select_type table type possible_keys key key_len ref rows Extra
6350+
1 SIMPLE t1 ref i_b i_b 13 const 1 Using index condition
6351+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6352+
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
6353+
[
6354+
6355+
{
6356+
"range_scan_alternatives":
6357+
[
6358+
6359+
{
6360+
"index": "i_b",
6361+
"ranges":
6362+
[
6363+
"(ab\x0A) <= (b) <= (ab\x0A)"
6364+
],
6365+
"rowid_ordered": true,
6366+
"using_mrr": false,
6367+
"index_only": false,
6368+
"rows": 1,
6369+
"cost": 2.3787,
6370+
"chosen": true
6371+
}
6372+
],
6373+
"analyzing_roworder_intersect":
6374+
{
6375+
"cause": "too few roworder scans"
6376+
},
6377+
"analyzing_index_merge_union":
6378+
[
6379+
]
6380+
}
6381+
]
6382+
drop table t1;
6383+
CREATE TABLE t1(i INT PRIMARY KEY, b CHAR(10), INDEX i_b(b));
6384+
INSERT INTO t1 VALUES (1, 'ab\n');
6385+
INSERT INTO t1 VALUES (2, NULL);
6386+
EXPLAIN SELECT * FROM t1 WHERE b='ab\n';
6387+
id select_type table type possible_keys key key_len ref rows Extra
6388+
1 SIMPLE t1 ref i_b i_b 11 const 1 Using index condition
6389+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6390+
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
6391+
[
6392+
6393+
{
6394+
"range_scan_alternatives":
6395+
[
6396+
6397+
{
6398+
"index": "i_b",
6399+
"ranges":
6400+
[
6401+
"(ab\n) <= (b) <= (ab\n)"
6402+
],
6403+
"rowid_ordered": true,
6404+
"using_mrr": false,
6405+
"index_only": false,
6406+
"rows": 1,
6407+
"cost": 2.3785,
6408+
"chosen": true
6409+
}
6410+
],
6411+
"analyzing_roworder_intersect":
6412+
{
6413+
"cause": "too few roworder scans"
6414+
},
6415+
"analyzing_index_merge_union":
6416+
[
6417+
]
6418+
}
6419+
]
6420+
drop table t1;
6421+
CREATE TABLE t1(i INT PRIMARY KEY, b blob , INDEX i_b(b));
6422+
Warnings:
6423+
Note 1071 Specified key was too long; max key length is 1000 bytes
6424+
INSERT INTO t1 VALUES (1, 'ab\n');
6425+
INSERT INTO t1 VALUES (2, NULL);
6426+
set optimizer_trace=1;
6427+
EXPLAIN SELECT * FROM t1 WHERE b= 'ab\n';
6428+
id select_type table type possible_keys key key_len ref rows Extra
6429+
1 SIMPLE t1 ref i_b i_b 1003 const 1 Using where
6430+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6431+
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
6432+
[
6433+
6434+
{
6435+
"range_scan_alternatives":
6436+
[
6437+
6438+
{
6439+
"index": "i_b",
6440+
"ranges":
6441+
[
6442+
"(ab\x0A) <= (b) <= (ab\x0A)"
6443+
],
6444+
"rowid_ordered": false,
6445+
"using_mrr": false,
6446+
"index_only": false,
6447+
"rows": 1,
6448+
"cost": 3.5719,
6449+
"chosen": true
6450+
}
6451+
],
6452+
"analyzing_roworder_intersect":
6453+
{
6454+
"cause": "too few roworder scans"
6455+
},
6456+
"analyzing_index_merge_union":
6457+
[
6458+
]
6459+
}
6460+
]
6461+
drop table t1;
6462+
CREATE TABLE t1(i INT PRIMARY KEY, b VARCHAR(10), INDEX i_b(b));
6463+
INSERT INTO t1 VALUES (1, 'ab\n');
6464+
INSERT INTO t1 VALUES (2, 'ab\n');
6465+
set optimizer_trace=1;
6466+
EXPLAIN SELECT * FROM t1 WHERE b='ab\n';
6467+
id select_type table type possible_keys key key_len ref rows Extra
6468+
1 SIMPLE t1 ref i_b i_b 13 const 2 Using index condition
6469+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6470+
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
6471+
[
6472+
6473+
{
6474+
"range_scan_alternatives":
6475+
[
6476+
6477+
{
6478+
"index": "i_b",
6479+
"ranges":
6480+
[
6481+
"(ab\n) <= (b) <= (ab\n)"
6482+
],
6483+
"rowid_ordered": true,
6484+
"using_mrr": false,
6485+
"index_only": false,
6486+
"rows": 2,
6487+
"cost": 3.6324,
6488+
"chosen": true
6489+
}
6490+
],
6491+
"analyzing_roworder_intersect":
6492+
{
6493+
"cause": "too few roworder scans"
6494+
},
6495+
"analyzing_index_merge_union":
6496+
[
6497+
]
6498+
}
6499+
]
6500+
drop table t1;
6501+
create table t0(a int);
6502+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
6503+
create table one_k (a int);
6504+
insert into one_k select A.a + B.a*10 + C.a*100 from t0 A, t0 B, t0 C;
6505+
create table t1 (start_date date, end_date date, filler char(100), key(start_date, end_date)) ;
6506+
insert into t1 select date_add(now(), interval a day), date_add(now(), interval (a+7) day), 'data' from one_k;
6507+
explain format=json select * from t1 force index(start_date) where start_date >= '2019-02-10' and end_date <'2019-04-01';
6508+
EXPLAIN
6509+
{
6510+
"query_block": {
6511+
"select_id": 1,
6512+
"table": {
6513+
"table_name": "t1",
6514+
"access_type": "range",
6515+
"possible_keys": ["start_date"],
6516+
"key": "start_date",
6517+
"key_length": "8",
6518+
"used_key_parts": ["start_date", "end_date"],
6519+
"rows": 1000,
6520+
"filtered": 100,
6521+
"index_condition": "t1.start_date >= '2019-02-10' and t1.end_date < '2019-04-01'"
6522+
}
6523+
}
6524+
}
6525+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6526+
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
6527+
[
6528+
6529+
{
6530+
"range_scan_alternatives":
6531+
[
6532+
6533+
{
6534+
"index": "start_date",
6535+
"ranges":
6536+
[
6537+
"(2019-02-10,NULL) < (start_date,end_date)"
6538+
],
6539+
"rowid_ordered": false,
6540+
"using_mrr": false,
6541+
"index_only": false,
6542+
"rows": 1000,
6543+
"cost": 1282.2,
6544+
"chosen": true
6545+
}
6546+
],
6547+
"analyzing_roworder_intersect":
6548+
{
6549+
"cause": "too few roworder scans"
6550+
},
6551+
"analyzing_index_merge_union":
6552+
[
6553+
]
6554+
}
6555+
]
6556+
drop table t1, t0, one_k;
62716557
set optimizer_trace='enabled=off';

0 commit comments

Comments
 (0)