Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions mysql-test/main/opt_trace_load_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -367,62 +367,62 @@ set @opt_context=json_remove(@saved_opt_context_1, '$.current_database');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "current_database" element not present at offset 1613.
Warning 4253 Failed to parse saved optimizer context: "current_database" element not present at offset 1669.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].name');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "name" element not present at offset 1620.
Warning 4253 Failed to parse saved optimizer context: "name" element not present at offset 1676.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].ddl');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "ddl" element not present at offset 1400.
Warning 4253 Failed to parse saved optimizer context: "ddl" element not present at offset 1456.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].num_of_records');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "num_of_records" element not present at offset 1616.
Warning 4253 Failed to parse saved optimizer context: "num_of_records" element not present at offset 1672.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].indexes[0].index_name');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "index_name" element not present at offset 406.
Warning 4253 Failed to parse saved optimizer context: "index_name" element not present at offset 433.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].indexes[0].rec_per_key');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "rec_per_key" element not present at offset 410.
Warning 4253 Failed to parse saved optimizer context: "rec_per_key" element not present at offset 437.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_ranges[0].index_name');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "index_name" element not present at offset 883.
Warning 4253 Failed to parse saved optimizer context: "index_name" element not present at offset 910.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_ranges[0].ranges');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "ranges" element not present at offset 875.
Warning 4253 Failed to parse saved optimizer context: "ranges" element not present at offset 902.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_ranges[0].num_rows');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "num_rows" element not present at offset 893.
Warning 4253 Failed to parse saved optimizer context: "num_rows" element not present at offset 920.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_ranges[0].cost');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "cost" element not present at offset 677.
Warning 4253 Failed to parse saved optimizer context: "cost" element not present at offset 704.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_ranges[0].max_index_blocks');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "max_index_blocks" element not present at offset 886.
Warning 4253 Failed to parse saved optimizer context: "max_index_blocks" element not present at offset 913.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_ranges[0].max_row_blocks');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "max_row_blocks" element not present at offset 888.
Warning 4253 Failed to parse saved optimizer context: "max_row_blocks" element not present at offset 915.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].indexes[0]');
select * from t1 where a > 10;
a b
Expand Down Expand Up @@ -461,51 +461,51 @@ set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_inde
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "key_number" element not present at offset 775.
Warning 4253 Failed to parse saved optimizer context: "key_number" element not present at offset 802.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].num_records');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "num_records" element not present at offset 774.
Warning 4253 Failed to parse saved optimizer context: "num_records" element not present at offset 801.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].eq_ref');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "eq_ref" element not present at offset 779.
Warning 4253 Failed to parse saved optimizer context: "eq_ref" element not present at offset 806.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].index_cost_io');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "index_cost_io" element not present at offset 772.
Warning 4253 Failed to parse saved optimizer context: "index_cost_io" element not present at offset 799.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].index_cost_cpu');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "index_cost_cpu" element not present at offset 761.
Warning 4253 Failed to parse saved optimizer context: "index_cost_cpu" element not present at offset 788.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].row_cost_io');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "row_cost_io" element not present at offset 774.
Warning 4253 Failed to parse saved optimizer context: "row_cost_io" element not present at offset 801.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].row_cost_cpu');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "row_cost_cpu" element not present at offset 763.
Warning 4253 Failed to parse saved optimizer context: "row_cost_cpu" element not present at offset 790.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].max_index_blocks');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "max_index_blocks" element not present at offset 769.
Warning 4253 Failed to parse saved optimizer context: "max_index_blocks" element not present at offset 796.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].max_row_blocks');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "max_row_blocks" element not present at offset 771.
Warning 4253 Failed to parse saved optimizer context: "max_row_blocks" element not present at offset 798.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].list_index_read_costs[0].copy_cost');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "copy_cost" element not present at offset 776.
Warning 4253 Failed to parse saved optimizer context: "copy_cost" element not present at offset 803.
drop table t1;
drop database db1;
97 changes: 97 additions & 0 deletions mysql-test/main/opt_trace_load_stats_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -1301,5 +1301,102 @@ JSON_EQUALS(@saved_explain_output, @explain_output)
1
set optimizer_replay_context="";
drop table t1;
#
# Index-Merge query on a single table having 2 indexes with overlapping keys
#
set optimizer_replay_context="";
create table t1 (
a int,
b int,
c int,
index idx_ab(a, b),
index idx_ac(a, c)
) ENGINE=InnoDB;
insert into t1 select seq%2, seq%3, seq%5 from seq_1_to_20;
set optimizer_replay_context="";
explain format=json select * from t1 where a=1 and b=1 and c=1
set @trace= (select trace from information_schema.optimizer_trace);
set @saved_opt_context=
(select json_pretty(json_extract(
json_extract(@trace, "$**.optimizer_context"),
'$[0]'
)
));
set @saved_opt_context_var_name='saved_opt_context';
set @explain_output='$explain_output';
set @explain_output= (select json_pretty(round_cost(@explain_output)));
select @explain_output;
@explain_output
{
"query_block":
{
"select_id": 1,
"cost": 0.0038076,
"nested_loop":
[
{
"table":
{
"table_name": "t1",
"access_type": "index_merge",
"possible_keys":
[
"idx_ab",
"idx_ac"
],
"key_length": "10,10",
"index_merge":
{
"intersect":
[
{
"range":
{
"key": "idx_ac",
"used_key_parts":
[
"a",
"c"
]
}
},
{
"range":
{
"key": "idx_ab",
"used_key_parts":
[
"a",
"b"
]
}
}
]
},
"loops": 1,
"rows": 1,
"cost": 0.0038076,
"filtered": 100,
"attached_condition": "t1.a = 1 and t1.b = 1 and t1.c = 1",
"using_index": true
}
}
]
}
}
set @saved_explain_output=@explain_output;
set optimizer_replay_context="";
delete from t1;
analyze table t1;
Table Op Msg_type Msg_text
db1.t1 analyze status OK
set optimizer_replay_context=@saved_opt_context_var_name;
set @explain_output='$explain_output';
set @explain_output= (select json_pretty(round_cost(@explain_output)));
select JSON_EQUALS(@saved_explain_output, @explain_output);
JSON_EQUALS(@saved_explain_output, @explain_output)
1
set optimizer_replay_context="";
drop table t1;
drop function round_cost;
drop database db1;
24 changes: 24 additions & 0 deletions mysql-test/main/opt_trace_load_stats_innodb.test
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,30 @@ let $table_update_query=delete from t1;

drop table t1;

--echo #
--echo # Index-Merge query on a single table having 2 indexes with overlapping keys
--echo #

set optimizer_replay_context="";

create table t1 (
a int,
b int,
c int,
index idx_ab(a, b),
index idx_ac(a, c)
) ENGINE=InnoDB;

insert into t1 select seq%2, seq%3, seq%5 from seq_1_to_20;

let $explain_query=explain format=json select * from t1 where a=1 and b=1 and c=1;

let $table_update_query=delete from t1;

--source include/run_query_twice_and_compare_stats.inc

drop table t1;

drop function round_cost;

drop database db1;
35 changes: 35 additions & 0 deletions mysql-test/main/opt_trace_store_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,39 @@ t1_idx_b ["(6) <= (b) <= (10)"] 1
drop view view1;
drop table t1;
drop table t2;
#
# union query with const tables
# testing the INSERT statements
#
set optimizer_record_context=OFF;
create table t1 (a int not null auto_increment,
b int,
primary key (a)
);
insert into t1 select seq, seq%5 from seq_1_to_20;
analyze table t1 persistent for all;
Table Op Msg_type Msg_text
db1.t1 analyze status Engine-independent statistics collected
db1.t1 analyze status OK
set optimizer_record_context=ON;
analyze select * from t1 where t1.a=5 and t1.b=0 union select * from t1 where t1.a=4 and t1.b=4;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 NULL 100.00 NULL
2 UNION t1 const PRIMARY PRIMARY 4 const 1 NULL 100.00 NULL
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 2.00 NULL NULL
set @trace= (select trace from information_schema.optimizer_trace);
set @const_table_inserts= (select JSON_DETAILED(JSON_EXTRACT(@trace, '$**.const_table_inserts')));
select @const_table_inserts;
@const_table_inserts
[
[
"REPLACE INTO db1.t1(a, b) VALUES (5, 0)",
"REPLACE INTO db1.t1(a, b) VALUES (4, 4)"
]
]
select * from json_table(@const_table_inserts, '$[*][*]' columns(insert_stmt text path '$')) as jt;
insert_stmt
REPLACE INTO db1.t1(a, b) VALUES (5, 0)
REPLACE INTO db1.t1(a, b) VALUES (4, 4)
drop table t1;
drop database db1;
25 changes: 25 additions & 0 deletions mysql-test/main/opt_trace_store_stats.test
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,29 @@ select * from json_table(
drop view view1;
drop table t1;
drop table t2;

--echo #
--echo # union query with const tables
--echo # testing the INSERT statements
--echo #
set optimizer_record_context=OFF;

create table t1 (a int not null auto_increment,
b int,
primary key (a)
);

insert into t1 select seq, seq%5 from seq_1_to_20;

analyze table t1 persistent for all;

set optimizer_record_context=ON;
analyze select * from t1 where t1.a=5 and t1.b=0 union select * from t1 where t1.a=4 and t1.b=4;

set @trace= (select trace from information_schema.optimizer_trace);
set @const_table_inserts= (select JSON_DETAILED(JSON_EXTRACT(@trace, '$**.const_table_inserts')));
select @const_table_inserts;
select * from json_table(@const_table_inserts, '$[*][*]' columns(insert_stmt text path '$')) as jt;

drop table t1;
drop database db1;
Loading