|
|
|
|
Quelle opt_context_load_stats_basic.test Sprache: unbekannt
|
|
Spracherkennung für: .test vermutete Sprache: SQL {SQL[68] VDM[68] ABAP[64]} [Methode: maximale Elemente, drei Dimensionen]
--source include/not_embedded.inc
--source include/have_sequence.inc
--echo #enable optimizer_record_context
--disable_replay testfile Don't replay a replay test
set optimizer_record_context=ON;
set @saved_opt_context_var_name_1= 'saved_opt_context_1';
set @saved_opt_context_var_name_2= 'saved_opt_context_2';
set @opt_context_var_name= 'opt_context';
create database db1;
use db1;
create table t1
(
a int, b int,
index t1_idx_a (a),
index t1_idx_b (b),
index t1_idx_ab (a, b)
) ENGINE=MyISAM;
insert into t1 select seq%5, seq%8 from seq_1_to_20;
set session use_stat_tables='COMPLEMENTARY';
analyze table t1 persistent for all;
--echo #
--echo # simple query after analyzing the table
--echo # planner should pick the analyzed table stats
--echo #
select * from t1 where a < 3 and b > 6;
--source include/opt_context_list_tables_and_ranges.inc
set @saved_opt_context_1=@opt_context;
set @saved_table_contexts= @table_contexts;
set @saved_list_ranges_1=@list_ranges;
--echo #
--echo # load stats in JSON format into variable optimizer_replay_context
--echo # and rerun the query.
--echo # These loaded stats are same as the analyzed stats
--echo #
set optimizer_replay_context=@saved_opt_context_var_name_1;
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_1, @opt_context);
--echo #
--echo # set the variable optimizer_replay_context to blank data
--echo # and rerun the query.
--echo # Analyzed table stats should be used for query planning
--echo #
set optimizer_replay_context="";
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_1, @opt_context);
--echo #
--echo # now update the table without running analyze table, and then rerun the queries
--echo #
insert into t1 select seq%5, seq%8 from seq_1_to_20;
--echo #
--echo # Only range stats are different, as the table wasn't re-analyzed
--echo #
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_1, @opt_context);
set @list_ranges= (select JSON_DETAILED(
JSON_EXTRACT(@opt_context,
'$**.multi_range_read_info_const_calls')));
set @saved_list_ranges_2 = @list_ranges;
select JSON_EQUALS(@saved_list_ranges_2, @saved_list_ranges_1);
select * from json_table(
@list_ranges,
'$[*][*]' columns(
index_name text path '$.index_name',
ranges json path '$.ranges',
num_rows int path '$.num_rows',
max_index_blocks int path '$.max_index_blocks',
max_row_blocks int path '$.max_row_blocks'
)
) as jt;
--echo #
--echo # Now, load stats in JSON format into variable optimizer_replay_context
--echo # and rerun the query.
--echo # Loaded stats (including range stats) should be picked by the planner
--echo #
set optimizer_replay_context=@saved_opt_context_var_name_1;
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_1, @opt_context);
--echo #
--echo # with optimizer_record_context OFF,
--echo # nothing gets printed to the trace
--echo #
set optimizer_record_context=OFF;
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select @opt_context;
--echo #
--echo # Now, after re-enabling optimizer_record_context,
--echo # Loaded stats should be picked by the planner instead of the analyzed table stats,
--echo # as the optimizer_replay_context is still set to a valid json containing other stats
--echo #
set optimizer_record_context=ON;
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_1, @opt_context);
--echo #
--echo # Now, set the variable optimizer_replay_context to blank data
--echo # and rerun the query.
--echo # Analyzed stats with updated range stats should be picked by the planner
--echo #
set optimizer_replay_context="";
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_1, @opt_context);
set @list_ranges= (select JSON_DETAILED(
JSON_EXTRACT(@opt_context,
'$**.multi_range_read_info_const_calls')));
select JSON_EQUALS(@saved_list_ranges_2, @list_ranges);
--echo #
--echo # now re-analyze the table, and then rerun the queries
--echo #
analyze table t1 persistent for all;
--echo #
--echo # All the stats are updated as the table is re-analyzed
--echo #
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
set @list_ranges= (select JSON_DETAILED(JSON_EXTRACT(@opt_context, '$**.multi_range_read_info_const_calls')));
select JSON_EQUALS(@saved_list_ranges_2, @list_ranges);
set @saved_opt_context_2 = @opt_context;
--echo #
--echo # Now, load stats in JSON format into variable optimizer_replay_context
--echo # and rerun the query.
--echo # Loaded stats (including range stats) should be picked by the planner
--echo #
set optimizer_replay_context=@saved_opt_context_var_name_1;
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_1, @opt_context);
--echo #
--echo # Now, set the variable optimizer_replay_context to blank data
--echo # and rerun the query.
--echo # All the re-analyzed stats should be picked by the planner
--echo #
set optimizer_replay_context="";
select * from t1 where a < 3 and b > 6;
--source include/opt_context_save_in_var.inc
select JSON_EQUALS(@saved_opt_context_2, @opt_context);
--echo #
--echo # The following tests check how Optimzer Context Parser reacts
--echo # to JSON elements missing in the optimizer_replay_context variable
--echo #
set optimizer_replay_context=@opt_context_var_name;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].name');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].ddl');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].file_stat_records');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].indexes[0].index_name');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].indexes[0].rec_per_key');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0].index_name');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0].ranges');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0].num_rows');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0].cost');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0].max_index_blocks');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0].max_row_blocks');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0].call_number');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].indexes[0]');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].multi_range_read_info_const_calls[0]');
select * from t1 where a > 10;
set @opt_context=json_replace(@saved_opt_context_1, '$.tables[0].name', 'db2.t1');
select * from t1 where a > 10;
set optimizer_replay_context="";
explain select tt1.a, tt2.b from t1 tt1, t1 tt2 where tt1.a = tt2.a;
--source include/opt_context_save_in_var.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, '$.tables[0].cost_for_index_read_calls[0].index_name');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].num_records');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].eq_ref');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].index_cost_io');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].index_cost_cpu');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].row_cost_io');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].row_cost_cpu');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].max_index_blocks');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].max_row_blocks');
select * from t1 where a > 10;
set @opt_context=json_remove(@saved_opt_context_1, '$.tables[0].cost_for_index_read_calls[0].copy_cost');
select * from t1 where a > 10;
drop table t1;
drop database db1;
[Dauer der Verarbeitung: 0.14 Sekunden, vorverarbeitet 2026-10-08]
|
2026-10-09
|
|
|
|
|
Neuigkeiten |
| Aktuelles |
| Motto des Tages |
|
Open Source Software |
|
|
|
Jenseits des Üblichen ....
|
|
Besucherstatistik |
|
|
| Statistik |
| #Sources=1126438 |
| #Domains=1867298 |
|
|