Commit e4fbec14 authored by Sergei Petrunia's avatar Sergei Petrunia

Make tests work with --view-protocol

parent 15298815
......@@ -12960,7 +12960,8 @@ select * from t10 where a<3 and b!=5 and c<10;
a b c
1 1 1
2 2 2
select json_detailed(json_extract(trace, '$**.attaching_conditions_to_tables')) as out1 from information_schema.optimizer_trace;
select json_detailed(json_extract(trace, '$**.attaching_conditions_to_tables')) as out1
from information_schema.optimizer_trace;
out1
[
{
......@@ -12979,7 +12980,6 @@ drop table t10;
#
# MDEV-21092: EXISTS to IN is not reflected in the optimizer trace
#
set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
set optimizer_trace='enabled=on';
create table t1 (cn_c int, cn_n char(10), cn_a int );
create table t2 (ci_p int, ci_c int );
......@@ -12988,8 +12988,12 @@ SELECT cn_n FROM t1 WHERE (EXISTS (select 1 from t2 where ci_p > 100000 and cn_c
OR (cn_n LIKE 'L%') )
AND cn_a > 1000000;
cn_n
select json_detailed(json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation')) from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation'))
select
json_detailed(
json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation')
) as out1
from information_schema.optimizer_trace;
out1
[
{
"select_id": 2,
......@@ -13011,8 +13015,9 @@ explain partitions select * from t2,t3 where t2.a in (2,3,4) and t3.a in (4,5);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t3 p4,p5 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t2 p2,p3,p4 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.prune_partitions'))
select json_detailed(json_extract(trace, '$**.prune_partitions')) as out1
from information_schema.optimizer_trace;
out1
[
{
"table": "t2",
......@@ -13035,8 +13040,9 @@ insert into t1 values (5),(15),(22);
explain select * from t1 where a = 28;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.prune_partitions'))
select json_detailed(json_extract(trace, '$**.prune_partitions')) as out1
from information_schema.optimizer_trace;
out1
[
{
"table": "t1",
......
......@@ -940,13 +940,15 @@ insert into t10 select seq, seq, seq from seq_1_to_10000;
explain format=json select * from t10 where a<3 and b!=5 and c<10;
set optimizer_trace='enabled=on';
select * from t10 where a<3 and b!=5 and c<10;
select json_detailed(json_extract(trace, '$**.attaching_conditions_to_tables')) as out1 from information_schema.optimizer_trace;
select json_detailed(json_extract(trace, '$**.attaching_conditions_to_tables')) as out1
from information_schema.optimizer_trace;
drop table t10;
--echo #
--echo # MDEV-21092: EXISTS to IN is not reflected in the optimizer trace
--echo #
set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
# EXISTS-to-IN conversion is traced on PREPARE so won't be visible with a VIEW:
--disable_view_protocol
set optimizer_trace='enabled=on';
create table t1 (cn_c int, cn_n char(10), cn_a int );
......@@ -957,8 +959,13 @@ SELECT cn_n FROM t1 WHERE (EXISTS (select 1 from t2 where ci_p > 100000 and cn_c
OR (cn_n LIKE 'L%') )
AND cn_a > 1000000;
select json_detailed(json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation')) from information_schema.optimizer_trace;
select
json_detailed(
json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation')
) as out1
from information_schema.optimizer_trace;
--enable_view_protocol
drop table t1, t2, t3;
--echo #
......@@ -972,7 +979,8 @@ INSERT INTO t3 SELECT seq, seq from seq_1_to_10;
set optimizer_trace='enabled=on';
explain partitions select * from t2,t3 where t2.a in (2,3,4) and t3.a in (4,5);
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
select json_detailed(json_extract(trace, '$**.prune_partitions')) as out1
from information_schema.optimizer_trace;
drop table t2,t3;
create table t1 (
......@@ -985,7 +993,8 @@ create table t1 (
insert into t1 values (5),(15),(22);
explain select * from t1 where a = 28;
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
select json_detailed(json_extract(trace, '$**.prune_partitions')) as out1
from information_schema.optimizer_trace;
drop table t1;
set @@optimizer_switch= @save_optimizer_switch;
......
......@@ -20,35 +20,67 @@ select count(*) from t1 where c=5 and b=5;
set optimizer_trace="enabled=on";
select count(*) from t1 where a=2 and b=5 and c=10;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
set @trace=(select trace from INFORMATION_SCHEMA.OPTIMIZER_TRACE);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
# The second JSON_EXTRACT is for --view-protocol which wraps every select:
select
JSON_DETAILED(
JSON_EXTRACT(
JSON_EXTRACT(@trace, '$**.considered_execution_plans'),
'$[0]'
)
) as JS;
select JSON_DETAILED(JSON_EXTRACT(@trace, '$**.selectivity_for_indexes')) as JS;
select count(*) from t1 where a=2 and b=5 and c=5;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
set @trace=(select trace from INFORMATION_SCHEMA.OPTIMIZER_TRACE);
# The second JSON_EXTRACT is for --view-protocol which wraps every select:
select
JSON_DETAILED(
JSON_EXTRACT(
JSON_EXTRACT(@trace, '$**.considered_execution_plans'),
'$[0]'
)
) as JS;
select JSON_DETAILED(JSON_EXTRACT(@trace, '$**.selectivity_for_indexes')) as JS;
--echo # Ensure that we only use selectivity from non used index for simple cases
select count(*) from t1 where (a=2 and b= 5);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
--echo # All of the following should have selectivity=1 for index 'b'
select count(*) from t1 where (a=2 and b between 0 and 100);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select count(*) from t1 where (a in (2,3) and b between 0 and 100);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select count(*) from t1 where (a>2 and b between 0 and 100);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select count(*) from t1 where (a>=2 and b between 0 and 100);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select count(*) from t1 where (a<=2 and b between 0 and 100);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select count(*) from t1 where (a<2 and b between 0 and 100);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select count(*) from t1 where (a between 2 and 3 and b between 0 and 100);
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) as JS
from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
drop table t1;
set optimizer_trace='enabled=off';
......@@ -157,16 +157,24 @@ f0 f1 f2
9701 0 0
9801 0 0
9901 0 0
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name Value
Sort_merge_passes 0
Sort_priority_queue_sorts 1
Sort_range 0
Sort_rows 100
Sort_scan 1
SHOW STATUS LIKE 'Handler_read_rnd%';
Variable_name Value
Handler_read_rnd 100
Handler_read_rnd_deleted 0
Handler_read_rnd_next 87701
DROP TABLE t1, tmp;
create table t2
select * from information_schema.SESSION_STATUS
where
variable_name like 'handler_read_rnd%' or
variable_name like 'Sort%';
select * from t2 where variable_name like 'Sort%';
VARIABLE_NAME VARIABLE_VALUE
SORT_MERGE_PASSES 0
SORT_PRIORITY_QUEUE_SORTS 1
SORT_RANGE 0
SORT_ROWS 100
SORT_SCAN 1
select * from t2 where variable_name='HANDLER_READ_RND';
VARIABLE_NAME VARIABLE_VALUE
HANDLER_READ_RND 100
select
if(variable_value in (87701, 87802), 'OK', 'FAIL') as RES
from t2 where variable_name='HANDLER_READ_RND_NEXT';
RES
OK
DROP TABLE t1, tmp, t2;
......@@ -61,9 +61,21 @@ SHOW SESSION STATUS LIKE 'Sort%';
explain SELECT * FROM t1 ORDER BY f2 LIMIT 100;
SELECT * FROM t1 ORDER BY f2 LIMIT 100;
create table t2
select * from information_schema.SESSION_STATUS
where
variable_name like 'handler_read_rnd%' or
variable_name like 'Sort%';
# Check that Sort_priority_queue_sorts is used
SHOW SESSION STATUS LIKE 'Sort%';
select * from t2 where variable_name like 'Sort%';
# Check that we did scan the whole table and did LIMIT lookups
SHOW STATUS LIKE 'Handler_read_rnd%';
select * from t2 where variable_name='HANDLER_READ_RND';
select
if(variable_value in (87701, 87802), 'OK', 'FAIL') as RES
from t2 where variable_name='HANDLER_READ_RND_NEXT';
DROP TABLE t1, tmp;
DROP TABLE t1, tmp, t2;
......@@ -981,6 +981,8 @@ ANALYZE TABLE t1_part,t2;
EXPLAIN SELECT a, MAX(b) FROM t1_part WHERE a IN (10,100) GROUP BY a;
EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
# view protocol will cause changed table counters
--disable_view_protocol
FLUSH status;
SELECT a, MAX(b) FROM t1_part WHERE a IN (10, 100) GROUP BY a;
SHOW status LIKE 'handler_read%';
......@@ -989,6 +991,7 @@ FLUSH status;
SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
SHOW status LIKE 'handler_read%';
--enable_view_protocol
insert into t2 select 100,seq from seq_1_to_100;
EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment