1set @innodb_stats_persistent_save= @@innodb_stats_persistent; 2set @innodb_stats_persistent_sample_pages_save= 3@@innodb_stats_persistent_sample_pages; 4set global innodb_stats_persistent= 1; 5set global innodb_stats_persistent_sample_pages=100; 6create table t1 7( 8pk1 int not null, 9pk2 int not null, 10key1 int not null, 11key2 int not null, 12key (key1), 13key (key2), 14primary key (pk1, pk2) 15)engine=Innodb; 16analyze table t1; 17Table Op Msg_type Msg_text 18test.t1 analyze status Engine-independent statistics collected 19test.t1 analyze status OK 20set optimizer_trace="enabled=on"; 21set @tmp_index_merge_ror_cpk=@@optimizer_switch; 22set optimizer_switch='extended_keys=off'; 23explain select * from t1 where pk1 != 0 and key1 = 1; 24id select_type table type possible_keys key key_len ref rows Extra 251 SIMPLE t1 ref PRIMARY,key1 key1 4 const 1 Using index condition 26select * from information_schema.OPTIMIZER_TRACE; 27QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 28explain select * from t1 where pk1 != 0 and key1 = 1 { 29 "steps": [ 30 { 31 "join_preparation": { 32 "select_id": 1, 33 "steps": [ 34 { 35 "expanded_query": "select t1.pk1 AS pk1,t1.pk2 AS pk2,t1.key1 AS key1,t1.key2 AS key2 from t1 where t1.pk1 <> 0 and t1.key1 = 1" 36 } 37 ] 38 } 39 }, 40 { 41 "join_optimization": { 42 "select_id": 1, 43 "steps": [ 44 { 45 "condition_processing": { 46 "condition": "WHERE", 47 "original_condition": "t1.pk1 <> 0 and t1.key1 = 1", 48 "steps": [ 49 { 50 "transformation": "equality_propagation", 51 "resulting_condition": "t1.pk1 <> 0 and multiple equal(1, t1.key1)" 52 }, 53 { 54 "transformation": "constant_propagation", 55 "resulting_condition": "t1.pk1 <> 0 and multiple equal(1, t1.key1)" 56 }, 57 { 58 "transformation": "trivial_condition_removal", 59 "resulting_condition": "t1.pk1 <> 0 and multiple equal(1, t1.key1)" 60 } 61 ] 62 } 63 }, 64 { 65 "table_dependencies": [ 66 { 67 "table": "t1", 68 "row_may_be_null": false, 69 "map_bit": 0, 70 "depends_on_map_bits": [] 71 } 72 ] 73 }, 74 { 75 "ref_optimizer_key_uses": [ 76 { 77 "table": "t1", 78 "field": "key1", 79 "equals": "1", 80 "null_rejecting": false 81 } 82 ] 83 }, 84 { 85 "rows_estimation": [ 86 { 87 "table": "t1", 88 "range_analysis": { 89 "table_scan": { 90 "rows": 1000, 91 "cost": 206.1 92 }, 93 "potential_range_indexes": [ 94 { 95 "index": "PRIMARY", 96 "usable": true, 97 "key_parts": ["pk1", "pk2"] 98 }, 99 { 100 "index": "key1", 101 "usable": true, 102 "key_parts": ["key1"] 103 }, 104 { 105 "index": "key2", 106 "usable": false, 107 "cause": "not applicable" 108 } 109 ], 110 "setup_range_conditions": [], 111 "group_index_range": { 112 "chosen": false, 113 "cause": "no group by or distinct" 114 }, 115 "analyzing_range_alternatives": { 116 "range_scan_alternatives": [ 117 { 118 "index": "PRIMARY", 119 "ranges": ["(pk1) < (0)", "(0) < (pk1)"], 120 "rowid_ordered": true, 121 "using_mrr": false, 122 "index_only": false, 123 "rows": 1000, 124 "cost": 204.01, 125 "chosen": true 126 }, 127 { 128 "index": "key1", 129 "ranges": ["(1) <= (key1) <= (1)"], 130 "rowid_ordered": true, 131 "using_mrr": false, 132 "index_only": false, 133 "rows": 1, 134 "cost": 2.3751, 135 "chosen": true 136 } 137 ], 138 "analyzing_roworder_intersect": { 139 "intersecting_indexes": [ 140 { 141 "index": "key1", 142 "index_scan_cost": 1.0001, 143 "cumulated_index_scan_cost": 1.0001, 144 "disk_sweep_cost": 1.0042, 145 "cumulative_total_cost": 2.0043, 146 "usable": true, 147 "matching_rows_now": 1, 148 "intersect_covering_with_this_index": false, 149 "chosen": true 150 } 151 ], 152 "clustered_pk": { 153 "clustered_pk_added_to_intersect": false, 154 "cause": "cost" 155 }, 156 "chosen": false, 157 "cause": "too few indexes to merge" 158 }, 159 "analyzing_index_merge_union": [] 160 }, 161 "chosen_range_access_summary": { 162 "range_access_plan": { 163 "type": "range_scan", 164 "index": "key1", 165 "rows": 1, 166 "ranges": ["(1) <= (key1) <= (1)"] 167 }, 168 "rows_for_plan": 1, 169 "cost_for_plan": 2.3751, 170 "chosen": true 171 } 172 } 173 }, 174 { 175 "table": "t1", 176 "rowid_filters": [ 177 { 178 "key": "key1", 179 "build_cost": 1.1801, 180 "rows": 1 181 } 182 ] 183 }, 184 { 185 "selectivity_for_indexes": [ 186 { 187 "index_name": "key1", 188 "selectivity_from_index": 0.001 189 }, 190 { 191 "index_name": "PRIMARY", 192 "selectivity_from_index": 1 193 } 194 ], 195 "selectivity_for_columns": [], 196 "cond_selectivity": 0.001 197 } 198 ] 199 }, 200 { 201 "considered_execution_plans": [ 202 { 203 "plan_prefix": [], 204 "table": "t1", 205 "best_access_path": { 206 "considered_access_paths": [ 207 { 208 "access_type": "ref", 209 "index": "key1", 210 "used_range_estimates": true, 211 "rows": 1, 212 "cost": 2, 213 "chosen": true 214 }, 215 { 216 "type": "scan", 217 "chosen": false, 218 "cause": "cost" 219 } 220 ], 221 "chosen_access_method": { 222 "type": "ref", 223 "records": 1, 224 "cost": 2, 225 "uses_join_buffering": false 226 } 227 }, 228 "rows_for_plan": 1, 229 "cost_for_plan": 2.2, 230 "estimated_join_cardinality": 1 231 } 232 ] 233 }, 234 { 235 "best_join_order": ["t1"] 236 }, 237 { 238 "attaching_conditions_to_tables": { 239 "original_condition": "t1.key1 = 1 and t1.pk1 <> 0", 240 "attached_conditions_computation": [], 241 "attached_conditions_summary": [ 242 { 243 "table": "t1", 244 "attached": "t1.pk1 <> 0" 245 } 246 ] 247 } 248 } 249 ] 250 } 251 }, 252 { 253 "join_execution": { 254 "select_id": 1, 255 "steps": [] 256 } 257 } 258 ] 259} 0 0 260drop table t1; 261set @@optimizer_switch= @tmp_index_merge_ror_cpk; 262set global innodb_stats_persistent= @innodb_stats_persistent_save; 263set global innodb_stats_persistent_sample_pages= 264@innodb_stats_persistent_sample_pages_save; 265# 266# MDEV-18962: ASAN heap-buffer-overflow in Single_line_formatting_helper::on_add_str with optimizer trace 267# 268CREATE TABLE t1 (a date not null, b time, key(a), key(b)) ENGINE=InnoDB; 269INSERT INTO t1 VALUES ('1991-09-09','00:00:00'),('2032-08-24','02:22:24'); 270SET SESSION optimizer_trace = 'enabled=on'; 271SELECT * FROM t1 WHERE b IS NULL AND a = '2000-01-01'; 272a b 273DROP TABLE t1; 274set optimizer_trace="enabled=off"; 275