Skip to content
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
6 changes: 6 additions & 0 deletions mysql-test/include/get_rec_idx_ranges_from_opt_ctx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ select *from json_table(
num_rows int path '$.num_rows',
max_index_blocks int path '$.max_index_blocks',
max_row_blocks int path '$.max_row_blocks')) as jt;
set @table_contexts=
(select JSON_DETAILED(JSON_EXTRACT(@opt_context, '$**.list_contexts')));
select *from json_table(
@table_contexts,
'$[*][*]' columns(table_name text path '$.name',
count_agg int path '$.count_agg')) as jt;
3 changes: 3 additions & 0 deletions mysql-test/include/opt_context_schema.inc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ let $opt_context_schema=
"copy_cost"
]
}
},
"count_agg": {
"type": "number"
}
},
"required": [
Expand Down
46 changes: 41 additions & 5 deletions mysql-test/main/opt_context_load_stats_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ index_name ranges num_rows max_index_blocks max_row_blocks
t1_idx_a ["(NULL) < (a) < (3)"] 12 1 1
t1_idx_b ["(6) < (b)"] 2 1 1
t1_idx_ab ["(NULL) < (a) < (3)"] 12 1 1
set @table_contexts=
(select JSON_DETAILED(JSON_EXTRACT(@opt_context, '$**.list_contexts')));
select *from json_table(
@table_contexts,
'$[*][*]' columns(table_name text path '$.name',
count_agg int path '$.count_agg')) as jt;
table_name count_agg
db1.t1 NULL
set @saved_opt_context_1=@opt_context;
set @saved_records_1=@records;
set @saved_indexes_1=@indexes;
Expand Down Expand Up @@ -355,11 +363,6 @@ select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "file_stat_records" element not present at offset 1380.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].file_stat_records');
select * from t1 where a > 10;
a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "file_stat_records" element not present at offset 1380.
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].indexes[0].index_name');
select * from t1 where a > 10;
a b
Expand Down Expand Up @@ -488,4 +491,37 @@ a b
Warnings:
Warning 4253 Failed to parse saved optimizer context: "copy_cost" element not present at offset 514.
drop table t1;
set optimizer_replay_context="";
create table t1 (a int primary key, b int not null, c varchar(10));
insert into t1 select seq, seq%5, concat('a-', seq) from seq_1_to_10;
set optimizer_record_context=1;
explain
select count(a), count(b), count(c) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
set @opt_context=
(select REGEXP_SUBSTR(
context,
'(?<=set @opt_context=\')([\n\r].*)*(?=\'\;#opt_context_ends)')
from information_schema.optimizer_context);
set @saved_opt_context_1= @opt_context;
set optimizer_replay_context=@opt_context_var_name;
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].count_agg');
explain
select count(a) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
Warnings:
Warning 4254 Failed to match the stats from replay context with the optimizer stats: db1.t1 with count_agg: doesn't exist in list_contexts
explain
select count(b) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
Warnings:
Warning 4254 Failed to match the stats from replay context with the optimizer stats: db1.t1 with count_agg: doesn't exist in list_contexts
explain
select count(c) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
drop table t1;
drop database db1;
28 changes: 25 additions & 3 deletions mysql-test/main/opt_context_load_stats_basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].file_stat_records');
select * from t1 where a > 10;

set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].file_stat_records');
select * from t1 where a > 10;

set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].indexes[0].index_name');
select * from t1 where a > 10;

Expand Down Expand Up @@ -300,5 +297,30 @@ select * from t1 where a > 10;
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;

drop table t1;
set optimizer_replay_context="";

create table t1 (a int primary key, b int not null, c varchar(10));
insert into t1 select seq, seq%5, concat('a-', seq) from seq_1_to_10;

set optimizer_record_context=1;

explain
select count(a), count(b), count(c) from t1;

--source include/get_opt_context.inc
set @saved_opt_context_1= @opt_context;

set optimizer_replay_context=@opt_context_var_name;
set @opt_context=json_remove(@saved_opt_context_1, '$.list_contexts[0].count_agg');
explain
select count(a) from t1;

explain
select count(b) from t1;

explain
select count(c) from t1;

drop table t1;
drop database db1;
4 changes: 2 additions & 2 deletions mysql-test/main/opt_context_replay_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ SET optimizer_where_cost=0.032000;

SET sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

SET timestamp=1780212030.000000;
SET timestamp=1780203030.000000;


select count(*) from t1;
Expand Down Expand Up @@ -205,7 +205,7 @@ SET optimizer_trace_max_mem_size=1048576;
SET optimizer_use_condition_selectivity=4;
SET optimizer_where_cost=0.032000;
SET sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SET timestamp=1780212030.000000;
SET timestamp=1780203030.000000;
CREATE DATABASE IF NOT EXISTS db1;
Warnings:
Note 1007 Can't create database 'db1'; database exists
Expand Down
Loading
Loading