From 5673cbe0941e105eb73b5ecf651a529f8e717b52 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 4 Oct 2024 12:49:37 +0300 Subject: [PATCH] MDEV-35074: selectivity_notembedded fails with --view-protocol Make the test view-protocol proof: save the contents of optimizer_trace and then we can do many queries against it. Also removed end-of-line spaces. --- .../selectivity_innodb_notembedded.result | 40 ++++++++++------- .../main/selectivity_notembedded.result | 40 ++++++++++------- mysql-test/main/selectivity_notembedded.test | 45 +++++++++++-------- 3 files changed, 73 insertions(+), 52 deletions(-) diff --git a/mysql-test/main/selectivity_innodb_notembedded.result b/mysql-test/main/selectivity_innodb_notembedded.result index 0ed8908063e..cf47b58b8b3 100644 --- a/mysql-test/main/selectivity_innodb_notembedded.result +++ b/mysql-test/main/selectivity_innodb_notembedded.result @@ -218,26 +218,28 @@ index (key1, pk), primary key (pk) ); insert into t1 -select +select seq, FLOOR(seq/100), 'filler' -from +from seq_1_to_1000; analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK set optimizer_trace=1; -explain select * from t1 +explain select * from t1 where pk in (1,2,3,4,5) and key1 <= 4; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY,key1 PRIMARY 4 NULL 5 Using where +create temporary table opt_trace as +select * from information_schema.optimizer_trace; # Must have a note that "multiplier is too high": -select +select json_detailed(json_extract(trace,'$**.selectivity_for_indexes')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ [ @@ -255,10 +257,10 @@ JS ] ] # Must not include 1.79...e308 as cost: -select +select json_detailed(json_extract(trace,'$**.best_access_path')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ { @@ -280,20 +282,22 @@ JS } } ] +drop table opt_trace; # Disable the fix and try the same: set @@optimizer_adjust_secondary_key_costs=''; -explain select * from t1 +explain select * from t1 where pk in (1,2,3,4,5) and key1 <= 4; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY,key1 PRIMARY 4 NULL 5 Using where -drop table t1; +create temporary table opt_trace as +select * from information_schema.optimizer_trace; # Shows a high multiplier, without a "note": -select +select json_detailed(json_extract(trace,'$**.selectivity_for_indexes')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ [ @@ -309,10 +313,10 @@ JS ] ] # Includes 1.79...e308 as cost: -select +select json_detailed(json_extract(trace,'$**.best_access_path')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ { @@ -334,7 +338,9 @@ JS } } ] +drop table opt_trace; set optimizer_adjust_secondary_key_costs=default; +drop table t1; # # Clean up # diff --git a/mysql-test/main/selectivity_notembedded.result b/mysql-test/main/selectivity_notembedded.result index 77ae626f567..02d557ca793 100644 --- a/mysql-test/main/selectivity_notembedded.result +++ b/mysql-test/main/selectivity_notembedded.result @@ -213,26 +213,28 @@ index (key1, pk), primary key (pk) ); insert into t1 -select +select seq, FLOOR(seq/100), 'filler' -from +from seq_1_to_1000; analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status Table is already up to date set optimizer_trace=1; -explain select * from t1 +explain select * from t1 where pk in (1,2,3,4,5) and key1 <= 4; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY,key1 PRIMARY 4 NULL 5 Using index condition; Using where +create temporary table opt_trace as +select * from information_schema.optimizer_trace; # Must have a note that "multiplier is too high": -select +select json_detailed(json_extract(trace,'$**.selectivity_for_indexes')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ [ @@ -250,10 +252,10 @@ JS ] ] # Must not include 1.79...e308 as cost: -select +select json_detailed(json_extract(trace,'$**.best_access_path')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ { @@ -275,20 +277,22 @@ JS } } ] +drop table opt_trace; # Disable the fix and try the same: set @@optimizer_adjust_secondary_key_costs=''; -explain select * from t1 +explain select * from t1 where pk in (1,2,3,4,5) and key1 <= 4; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY,key1 PRIMARY 4 NULL 5 Using index condition; Using where -drop table t1; +create temporary table opt_trace as +select * from information_schema.optimizer_trace; # Shows a high multiplier, without a "note": -select +select json_detailed(json_extract(trace,'$**.selectivity_for_indexes')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ [ @@ -304,10 +308,10 @@ JS ] ] # Includes 1.79...e308 as cost: -select +select json_detailed(json_extract(trace,'$**.best_access_path')) as JS -from -information_schema.optimizer_trace; +from +opt_trace; JS [ { @@ -329,7 +333,9 @@ JS } } ] +drop table opt_trace; set optimizer_adjust_secondary_key_costs=default; +drop table t1; # # Clean up # diff --git a/mysql-test/main/selectivity_notembedded.test b/mysql-test/main/selectivity_notembedded.test index 2c4431adb23..d53cb8db7b4 100644 --- a/mysql-test/main/selectivity_notembedded.test +++ b/mysql-test/main/selectivity_notembedded.test @@ -233,50 +233,59 @@ create table t1 ( ); insert into t1 -select +select seq, FLOOR(seq/100), 'filler' -from +from seq_1_to_1000; analyze table t1; set optimizer_trace=1; -explain select * from t1 +explain select * from t1 where pk in (1,2,3,4,5) and key1 <= 4; +create temporary table opt_trace as +select * from information_schema.optimizer_trace; + --echo # Must have a note that "multiplier is too high": -select +select json_detailed(json_extract(trace,'$**.selectivity_for_indexes')) as JS -from - information_schema.optimizer_trace; +from + opt_trace; --echo # Must not include 1.79...e308 as cost: -select +select json_detailed(json_extract(trace,'$**.best_access_path')) as JS -from - information_schema.optimizer_trace; +from + opt_trace; +drop table opt_trace; --echo # Disable the fix and try the same: set @@optimizer_adjust_secondary_key_costs=''; -explain select * from t1 +explain select * from t1 where pk in (1,2,3,4,5) and key1 <= 4; -drop table t1; + +create temporary table opt_trace as +select * from information_schema.optimizer_trace; + --echo # Shows a high multiplier, without a "note": -select +select json_detailed(json_extract(trace,'$**.selectivity_for_indexes')) as JS -from - information_schema.optimizer_trace; +from + opt_trace; --echo # Includes 1.79...e308 as cost: -select +select json_detailed(json_extract(trace,'$**.best_access_path')) as JS -from - information_schema.optimizer_trace; -set optimizer_adjust_secondary_key_costs=default; +from + opt_trace; +drop table opt_trace; +set optimizer_adjust_secondary_key_costs=default; +drop table t1; --echo # --echo # Clean up --echo #