summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <sergey@mariadb.com>2022-05-07 19:10:59 +0300
committerSergei Petrunia <sergey@mariadb.com>2022-05-12 22:24:37 +0300
commit353746918b3dcc0835adb9159376904cc6d01b43 (patch)
tree63fc0450db014829ff56717a5ce33f8a4d09d8b3
parentb9adaeb491a36170a140799bce0de911d654c2d6 (diff)
downloadmariadb-git-353746918b3dcc0835adb9159376904cc6d01b43.tar.gz
Optimizer trace: Make ref_optimizer_key_uses[*] show the index namebb-10.9-spetrunia
-rw-r--r--mysql-test/main/opt_trace.result19
-rw-r--r--mysql-test/main/opt_trace_index_merge_innodb.result1
-rw-r--r--sql/sql_test.cc4
3 files changed, 24 insertions, 0 deletions
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index d3021a2b395..54ec5edd0c4 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -963,12 +963,14 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"ref_optimizer_key_uses": [
{
"table": "t1",
+ "index": "a",
"field": "a",
"equals": "t2.b + 2",
"null_rejecting": true
},
{
"table": "t2",
+ "index": "a",
"field": "a",
"equals": "t1.b",
"null_rejecting": true
@@ -1975,18 +1977,21 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"ref_optimizer_key_uses": [
{
"table": "t1",
+ "index": "a_c",
"field": "a",
"equals": "1",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "a_b",
"field": "a",
"equals": "1",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "a_b",
"field": "b",
"equals": "2",
"null_rejecting": true
@@ -2346,6 +2351,7 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
"ref_optimizer_key_uses": [
{
"table": "t2",
+ "index": "PRIMARY",
"field": "a",
"equals": "t1.a",
"null_rejecting": true
@@ -2484,6 +2490,7 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"ref_optimizer_key_uses": [
{
"table": "t2",
+ "index": "PRIMARY",
"field": "a",
"equals": "t1.a",
"null_rejecting": true
@@ -2670,24 +2677,28 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
"ref_optimizer_key_uses": [
{
"table": "t2",
+ "index": "PRIMARY",
"field": "a",
"equals": "t1.a",
"null_rejecting": true
},
{
"table": "t2",
+ "index": "PRIMARY",
"field": "a",
"equals": "t3.a",
"null_rejecting": true
},
{
"table": "t3",
+ "index": "PRIMARY",
"field": "a",
"equals": "t2.a",
"null_rejecting": true
},
{
"table": "t3",
+ "index": "PRIMARY",
"field": "a",
"equals": "t1.a",
"null_rejecting": true
@@ -3187,36 +3198,42 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"ref_optimizer_key_uses": [
{
"table": "t1",
+ "index": "pk",
"field": "pk",
"equals": "2",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "pk_a",
"field": "pk",
"equals": "2",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "pk_a",
"field": "a",
"equals": "5",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "pk_a_b",
"field": "pk",
"equals": "2",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "pk_a_b",
"field": "a",
"equals": "5",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "pk_a_b",
"field": "b",
"equals": "1",
"null_rejecting": true
@@ -3867,12 +3884,14 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"ref_optimizer_key_uses": [
{
"table": "t0",
+ "index": "a",
"field": "a",
"equals": "t1.a",
"null_rejecting": true
},
{
"table": "t1",
+ "index": "a",
"field": "a",
"equals": "t0.a",
"null_rejecting": true
diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result
index fbc7faa0d04..57a6c72e52f 100644
--- a/mysql-test/main/opt_trace_index_merge_innodb.result
+++ b/mysql-test/main/opt_trace_index_merge_innodb.result
@@ -75,6 +75,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"ref_optimizer_key_uses": [
{
"table": "t1",
+ "index": "key1",
"field": "key1",
"equals": "1",
"null_rejecting": false
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index 0d1a8313564..b85b37b1726 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -694,6 +694,10 @@ void print_keyuse_array_for_trace(THD *thd, DYNAMIC_ARRAY *keyuse_array)
KEYUSE *keyuse= (KEYUSE*)dynamic_array_ptr(keyuse_array, i);
Json_writer_object keyuse_elem(thd);
keyuse_elem.add_table_name(keyuse->table->reginfo.join_tab);
+ if (keyuse->keypart != FT_KEYPART && !keyuse->is_for_hash_join())
+ {
+ keyuse_elem.add("index", keyuse->table->key_info[keyuse->key].name);
+ }
keyuse_elem.add("field", (keyuse->keypart == FT_KEYPART) ? "<fulltext>":
(keyuse->is_for_hash_join() ?
keyuse->table->field[keyuse->keypart]