Skip to content

Commit 05721a3

Browse files
MDEV-21510: In Optimizer Trace, print index name in chosen_access_method
1 parent 820114b commit 05721a3

6 files changed

+36
-6
lines changed

mysql-test/main/opt_trace.result

+13
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
12851285
],
12861286
"chosen_access_method": {
12871287
"type": "ref",
1288+
"index": "a",
12881289
"rows_read": 1,
12891290
"rows_out": 1,
12901291
"cost": 0.1821659,
@@ -1340,6 +1341,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
13401341
],
13411342
"chosen_access_method": {
13421343
"type": "ref",
1344+
"index": "a",
13431345
"rows_read": 1,
13441346
"rows_out": 1,
13451347
"cost": 0.1821659,
@@ -2533,6 +2535,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
25332535
],
25342536
"chosen_access_method": {
25352537
"type": "ref",
2538+
"index": "a_b",
25362539
"rows_read": 41,
25372540
"rows_out": 41,
25382541
"cost": 0.051379171,
@@ -3012,6 +3015,7 @@ explain select * from t1 left join t2 on t2.a=t1.a {
30123015
],
30133016
"chosen_access_method": {
30143017
"type": "eq_ref",
3018+
"index": "PRIMARY",
30153019
"rows_read": 1,
30163020
"rows_out": 1,
30173021
"cost": 0.007120904,
@@ -3980,6 +3984,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
39803984
],
39813985
"chosen_access_method": {
39823986
"type": "ref",
3987+
"index": "pk_a_b",
39833988
"rows_read": 1,
39843989
"rows_out": 1,
39853990
"cost": 0.000928812,
@@ -4676,6 +4681,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
46764681
],
46774682
"chosen_access_method": {
46784683
"type": "range",
4684+
"index": "a",
46794685
"rows_read": 3,
46804686
"rows_out": 3,
46814687
"cost": 0.001755494,
@@ -4702,6 +4708,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
47024708
],
47034709
"chosen_access_method": {
47044710
"type": "range",
4711+
"index": "a",
47054712
"rows_read": 3,
47064713
"rows_out": 3,
47074714
"cost": 0.001755494,
@@ -4744,6 +4751,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
47444751
],
47454752
"chosen_access_method": {
47464753
"type": "ref",
4754+
"index": "a",
47474755
"rows_read": 1,
47484756
"rows_out": 1,
47494757
"cost": 0.002376836,
@@ -4795,6 +4803,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
47954803
],
47964804
"chosen_access_method": {
47974805
"type": "ref",
4806+
"index": "a",
47984807
"rows_read": 1.166666667,
47994808
"rows_out": 1.166666667,
48004809
"cost": 0.002392836,
@@ -11275,6 +11284,7 @@ JS
1127511284
"chosen_access_method":
1127611285
{
1127711286
"type": "ref",
11287+
"index": "b",
1127811288
"rows_read": 1,
1127911289
"rows_out": 1,
1128011290
"cost": 0.01901531,
@@ -11521,6 +11531,7 @@ JS
1152111531
"chosen_access_method":
1152211532
{
1152311533
"type": "ref",
11534+
"index": "a",
1152411535
"rows_read": 1,
1152511536
"rows_out": 1,
1152611537
"cost": 0.01840091,
@@ -12906,6 +12917,7 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
1290612917
"chosen_access_method":
1290712918
{
1290812919
"type": "ref",
12920+
"index": "idx_a",
1290912921
"rows_read": 1.8367,
1291012922
"rows_out": 1.8367,
1291112923
"cost": 0.002051185,
@@ -13201,6 +13213,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
1320113213
],
1320213214
"chosen_access_method": {
1320313215
"type": "range",
13216+
"index": "a",
1320413217
"rows_read": 0.189,
1320513218
"rows_out": 0.017766,
1320613219
"cost": 0.006364199,

mysql-test/main/opt_trace_index_merge_innodb.result

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
227227
],
228228
"chosen_access_method": {
229229
"type": "ref",
230+
"index": "key1",
230231
"rows_read": 1,
231232
"rows_out": 1,
232233
"cost": 0.00345856,

mysql-test/main/opt_trace_selectivity.result

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ JS
186186
"chosen_access_method":
187187
{
188188
"type": "ref",
189+
"index": "a",
189190
"rows_read": 6,
190191
"rows_out": 0.6,
191192
"cost": 0.005388489,

mysql-test/main/selectivity_innodb_notembedded.result

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ JS
298298
"chosen_access_method":
299299
{
300300
"type": "range",
301+
"index": "PRIMARY",
301302
"rows_read": 5,
302303
"rows_out": 2.490196078,
303304
"cost": 0.00948507,

mysql-test/main/selectivity_notembedded.result

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ JS
293293
"chosen_access_method":
294294
{
295295
"type": "range",
296+
"index": "PRIMARY",
296297
"rows_read": 5,
297298
"rows_out": 2.490196078,
298299
"cost": 0.010014472,

sql/opt_trace.cc

+19-6
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,25 @@ void print_best_access_for_table(THD *thd, POSITION *pos)
712712
DBUG_ASSERT(thd->trace_started());
713713

714714
Json_writer_object obj(thd, "chosen_access_method");
715-
obj.
716-
add("type", pos->type == JT_ALL ? "scan" : join_type_str[pos->type]).
717-
add("rows_read", pos->records_read).
718-
add("rows_out", pos->records_out).
719-
add("cost", pos->read_time).
720-
add("uses_join_buffering", pos->use_join_buffer);
715+
716+
obj.add("type", pos->type == JT_ALL ? "scan" : join_type_str[pos->type]);
717+
718+
if (pos->type == JT_EQ_REF || pos->type == JT_REF || pos->type == JT_FT)
719+
{
720+
obj.add("index", pos->key->table->key_info[pos->key->key].name);
721+
}
722+
723+
if (pos->type == JT_RANGE)
724+
{
725+
obj.add("index",
726+
pos->table->table->key_info[pos->table->quick->index].name);
727+
}
728+
729+
obj.add("rows_read", pos->records_read)
730+
.add("rows_out", pos->records_out)
731+
.add("cost", pos->read_time)
732+
.add("uses_join_buffering", pos->use_join_buffer);
733+
721734
if (pos->range_rowid_filter_info)
722735
{
723736
uint key_no= pos->range_rowid_filter_info->get_key_no();

0 commit comments

Comments
 (0)