SELECT table_name, column_name FROM information_schema.columns where table_name="OPTIMIZER_TRACE"; table_name column_name OPTIMIZER_TRACE QUERY OPTIMIZER_TRACE TRACE OPTIMIZER_TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE OPTIMIZER_TRACE INSUFFICIENT_PRIVILEGES show variables like 'optimizer_trace'; Variable_name Value optimizer_trace enabled=off set optimizer_trace="enabled=on"; show variables like 'optimizer_trace'; Variable_name Value optimizer_trace enabled=on set optimizer_trace="enabled=off"; create table t1 (a int, b int); insert into t1 values (1,2),(2,3); create table t2 (b int); insert into t2 values (1),(2); analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK analyze table t2; Table Op Msg_type Msg_text test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK create function f1 (a int) returns INT return 1; create view v1 as select * from t1 where t1.a=1; create view v2 as select * from t1 where t1.a=1 group by t1.b; set optimizer_trace="enabled=on"; # Mergeable views/derived tables select * from v1; a b 1 2 select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES select * from v1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "view": { "table": "v1", "select_id": 2, "algorithm": "merged" } }, { "join_preparation": { "select_id": 2, "steps": [ { "expanded_query": "/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1" } ] } }, { "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from v1" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.a = 1", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "multiple equal(1, t1.a)" }, { "transformation": "constant_propagation", "resulting_condition": "multiple equal(1, t1.a)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(1, t1.a)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "selectivity_for_indexes": [], "selectivity_for_columns": [ { "column_name": "a", "selectivity_from_histogram": 0.5 } ], "cond_selectivity": 0.5 }, { "table": "t1", "table_scan": { "rows": 2, "cost": 2.0044 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 1, "cost": 2.2044, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.a = 1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": "t1.a = 1" } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 select * from (select * from t1 where t1.a=1)q; a b 1 2 select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES select * from (select * from t1 where t1.a=1)q { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "derived": { "table": "q", "select_id": 2, "algorithm": "merged" } }, { "join_preparation": { "select_id": 2, "steps": [ { "expanded_query": "/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1" } ] } }, { "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from (/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1) q" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.a = 1", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "multiple equal(1, t1.a)" }, { "transformation": "constant_propagation", "resulting_condition": "multiple equal(1, t1.a)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(1, t1.a)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "selectivity_for_indexes": [], "selectivity_for_columns": [ { "column_name": "a", "selectivity_from_histogram": 0.5 } ], "cond_selectivity": 0.5 }, { "table": "t1", "table_scan": { "rows": 2, "cost": 2.0044 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 1, "cost": 2.2044, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.a = 1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": "t1.a = 1" } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 # Non-Mergeable views select * from v2; a b 1 2 select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES select * from v2 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "view": { "table": "v2", "select_id": 2, "algorithm": "materialized" } }, { "join_preparation": { "select_id": 2, "steps": [ { "expanded_query": "/* select#2 */ select t1.a AS a,t1.b AS b from t1 where t1.a = 1 group by t1.b" } ] } }, { "expanded_query": "/* select#1 */ select v2.a AS a,v2.b AS b from v2" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "join_optimization": { "select_id": 2, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.a = 1", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "multiple equal(1, t1.a)" }, { "transformation": "constant_propagation", "resulting_condition": "multiple equal(1, t1.a)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(1, t1.a)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "selectivity_for_indexes": [], "selectivity_for_columns": [ { "column_name": "a", "selectivity_from_histogram": 0.5 } ], "cond_selectivity": 0.5 }, { "table": "t1", "table_scan": { "rows": 2, "cost": 2.0044 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 1, "cost": 2.2044, "chosen": true, "use_tmp_table": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.a = 1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": "t1.a = 1" } ] } } ] } }, { "table_dependencies": [ { "table": "", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "", "table_scan": { "rows": 2, "cost": 2 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 2, "cost": 2, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [ { "join_execution": { "select_id": 2, "steps": [] } } ] } } ] } 0 0 drop table t1,t2; drop view v1,v2; drop function f1; create table t1(a int, b int); insert into t1 values (0,0),(1,1),(2,1),(3,2),(4,3), (5,3),(6,3),(7,3),(8,3),(9,3); create table t2(a int, b int); insert into t2 values (0,0),(1,1),(2,1),(3,2),(4,3), (5,3),(6,3),(7,3),(8,3),(9,3); ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK ANALYZE TABLE t2; Table Op Msg_type Msg_text test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK create view v1 as select a from t1 group by b; create view v2 as select a from t2; # Mergeable view explain select * from v2 ; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 10 select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from v2 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "view": { "table": "v2", "select_id": 2, "algorithm": "merged" } }, { "join_preparation": { "select_id": 2, "steps": [ { "expanded_query": "/* select#2 */ select t2.a AS a from t2" } ] } }, { "expanded_query": "/* select#1 */ select t2.a AS a from v2" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "table_dependencies": [ { "table": "t2", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "t2", "table_scan": { "rows": 10, "cost": 2.022 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 10, "cost": 2.022, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t2", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 # Non-Mergeable view explain select * from v1 ; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ALL NULL NULL NULL NULL 10 2 DERIVED t1 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from v1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "view": { "table": "v1", "select_id": 2, "algorithm": "materialized" } }, { "join_preparation": { "select_id": 2, "steps": [ { "expanded_query": "/* select#2 */ select t1.a AS a from t1 group by t1.b" } ] } }, { "expanded_query": "/* select#1 */ select v1.a AS a from v1" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "join_optimization": { "select_id": 2, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 10, "cost": 2.022 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 10, "cost": 2.022, "chosen": true, "use_tmp_table": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "table_dependencies": [ { "table": "", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "", "table_scan": { "rows": 10, "cost": 10 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 10, "cost": 10, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [ { "join_execution": { "select_id": 2, "steps": [] } } ] } } ] } 0 0 drop table t1,t2; drop view v1,v2; # # print ref-keyues array # create table t0 (a int); INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t1 (a int, b int, c int, key(a)); insert into t1 select A.a*10 + B.a, A.a*10 + B.a, A.a*10 + B.a from t0 A, t0 B; create table t2(a int, b int, c int , key(a)); insert into t2 select A.a*10 + B.a, A.a*10 + B.a, A.a*10 + B.a from t0 A, t0 B; 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 analyze table t2; Table Op Msg_type Msg_text test.t2 analyze status Engine-independent statistics collected test.t2 analyze status Table is already up to date explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL a NULL NULL NULL 100 Using where 1 SIMPLE t2 ref a a 5 test.t1.b 1 Using where select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.a AS a,t1.b AS b,t1.c AS c,t2.a AS a,t2.b AS b,t2.c AS c from t1 join t2 where t1.a = t2.b + 2 and t2.a = t1.b" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.a = t2.b + 2 and t2.a = t1.b", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "t1.a = t2.b + 2 and multiple equal(t2.a, t1.b)" }, { "transformation": "constant_propagation", "resulting_condition": "t1.a = t2.b + 2 and multiple equal(t2.a, t1.b)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "t1.a = t2.b + 2 and multiple equal(t2.a, t1.b)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t2", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [ { "table": "t1", "field": "a", "equals": "t2.b + 2", "null_rejecting": false }, { "table": "t2", "field": "a", "equals": "t1.b", "null_rejecting": true } ] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 100, "cost": 2.3174 } }, { "table": "t2", "table_scan": { "rows": 100, "cost": 2.3174 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 100, "cost": 2.3174, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t2", "best_access_path": { "considered_access_paths": [ { "access_type": "ref", "index": "a", "used_range_estimates": false, "cause": "not available", "rows": 1, "cost": 200, "chosen": true }, { "access_type": "scan", "resulting_rows": 100, "cost": 2.3174, "chosen": false } ] } } ] }, { "plan_prefix": [], "table": "t2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 100, "cost": 2.3174, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t2"], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "ref", "index": "a", "used_range_estimates": false, "cause": "not available", "rows": 1, "cost": 200, "chosen": true }, { "access_type": "scan", "resulting_rows": 100, "cost": 2.3174, "chosen": false } ] }, "pruned_by_cost": true } ] } ] }, { "attaching_conditions_to_tables": { "original_condition": "t2.a = t1.b and t1.a = t2.b + 2", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": "t1.b is not null" }, { "table": "t2", "attached": "t1.a = t2.b + 2" } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table t1,t2,t0; # # group_by min max optimization # CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, a INT NOT NULL, KEY(a)); analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT DISTINCT a FROM t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL a 4 NULL 5 Using index for group-by select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES EXPLAIN SELECT DISTINCT a FROM t1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select distinct t1.a AS a from t1" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "t1", "range_analysis": { "table_scan": { "rows": 65536, "cost": 13255 }, "potential_range_indexes": [ { "index": "PRIMARY", "usable": false, "cause": "not applicable" }, { "index": "a", "usable": true, "key_parts": ["a"] } ], "best_covering_index_scan": { "index": "a", "cost": 4812.5, "chosen": true }, "group_index_range": { "distinct_query": true, "potential_group_range_indexes": [ { "index": "a", "covering": true, "rows": 5, "cost": 6.75 } ] }, "best_group_range_summary": { "type": "index_group", "index": "a", "min_max_arg": null, "min_aggregate": false, "max_aggregate": false, "distinct_aggregate": false, "rows": 5, "cost": 6.75, "key_parts_used_for_access": ["a"], "ranges": [], "chosen": true }, "chosen_range_access_summary": { "range_access_plan": { "type": "index_group", "index": "a", "min_max_arg": null, "min_aggregate": false, "max_aggregate": false, "distinct_aggregate": false, "rows": 5, "cost": 6.75, "key_parts_used_for_access": ["a"], "ranges": [] }, "rows_for_plan": 5, "cost_for_plan": 6.75, "chosen": true } } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "range", "resulting_rows": 5, "cost": 6.75, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table t1; # # With group by , where clause and MIN/MAX function # CREATE TABLE t1 (a INT, b INT, c int, d int, KEY(a,b,c,d)); INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (1,0,1,1), (3,2,3,3), (4,5,4,4); ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL a 20 NULL 7 Using where; Using index select * from information_schema.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select min(t1.d) AS `MIN(d)` from t1 where t1.b = 2 and t1.c = 3 group by t1.a" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.b = 2 and t1.c = 3", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "multiple equal(2, t1.b) and multiple equal(3, t1.c)" }, { "transformation": "constant_propagation", "resulting_condition": "multiple equal(2, t1.b) and multiple equal(3, t1.c)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(2, t1.b) and multiple equal(3, t1.c)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "table": "t1", "range_analysis": { "table_scan": { "rows": 7, "cost": 5.5291 }, "potential_range_indexes": [ { "index": "a", "usable": true, "key_parts": ["a", "b", "c", "d"] } ], "best_covering_index_scan": { "index": "a", "cost": 1.3869, "chosen": true }, "setup_range_conditions": [], "group_index_range": { "potential_group_range_indexes": [ { "index": "a", "covering": true, "ranges": ["2 <= b <= 2 AND 3 <= c <= 3"], "rows": 8, "cost": 2.2 } ] }, "best_group_range_summary": { "type": "index_group", "index": "a", "min_max_arg": "d", "min_aggregate": true, "max_aggregate": false, "distinct_aggregate": false, "rows": 8, "cost": 2.2, "key_parts_used_for_access": ["a", "b", "c"], "ranges": ["2 <= b <= 2 AND 3 <= c <= 3"], "chosen": false, "cause": "cost" }, "analyzing_range_alternatives": { "range_scan_alternatives": [], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] } } }, { "selectivity_for_indexes": [], "selectivity_for_columns": [ { "column_name": "b", "selectivity_from_histogram": 0.2891 }, { "column_name": "c", "selectivity_from_histogram": 0.2891 } ], "cond_selectivity": 0.0836 } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 0.5849, "cost": 3.3121, "chosen": true, "use_tmp_table": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.b = 2 and t1.c = 3", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": "t1.b = 2 and t1.c = 3" } ] } }, { "reconsidering_access_paths_for_index_ordering": { "clause": "GROUP BY", "fanout": 1, "read_time": 3.3131, "table": "t1", "rows_estimation": 7, "possible_keys": [ { "index": "a", "can_resolve_order": true, "updated_limit": 7, "index_scan_time": 7, "records": 7, "chosen": true } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 DROP TABLE t1; CREATE TABLE t1 (id INT NOT NULL, a DATE, KEY(id,a)); INSERT INTO t1 values (1,'2001-01-01'),(1,'2001-01-02'), (1,'2001-01-03'),(1,'2001-01-04'), (2,'2001-01-01'),(2,'2001-01-02'), (2,'2001-01-03'),(2,'2001-01-04'), (3,'2001-01-01'),(3,'2001-01-02'), (3,'2001-01-03'),(3,'2001-01-04'), (4,'2001-01-01'),(4,'2001-01-02'), (4,'2001-01-03'),(4,'2001-01-04'); set optimizer_trace='enabled=on'; EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL id 8 NULL 16 Using where; Using index select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.`id` AS `id`,min(t1.a) AS `MIN(a)`,max(t1.a) AS `MAX(a)` from t1 where t1.a >= 20010104e0 group by t1.`id`" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.a >= 20010104e0", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "t1.a >= 20010104e0" }, { "transformation": "constant_propagation", "resulting_condition": "t1.a >= 20010104e0" }, { "transformation": "trivial_condition_removal", "resulting_condition": "t1.a >= 20010104e0" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "table": "t1", "range_analysis": { "table_scan": { "rows": 16, "cost": 7.3313 }, "potential_range_indexes": [ { "index": "id", "usable": true, "key_parts": ["id", "a"] } ], "best_covering_index_scan": { "index": "id", "cost": 1.8468, "chosen": true }, "setup_range_conditions": [], "group_index_range": { "potential_group_range_indexes": [ { "index": "id", "covering": true, "ranges": ["0x24a20f <= a"], "rows": 9, "cost": 2.35 } ] }, "best_group_range_summary": { "type": "index_group", "index": "id", "min_max_arg": "a", "min_aggregate": true, "max_aggregate": true, "distinct_aggregate": false, "rows": 9, "cost": 2.35, "key_parts_used_for_access": ["id"], "ranges": ["0x24a20f <= a"], "chosen": false, "cause": "cost" }, "analyzing_range_alternatives": { "range_scan_alternatives": [], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] } } }, { "selectivity_for_indexes": [], "selectivity_for_columns": [], "cond_selectivity": 1 } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 16, "cost": 2.0312, "chosen": true, "use_tmp_table": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.a >= 20010104e0", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": "t1.a >= 20010104e0" } ] } }, { "reconsidering_access_paths_for_index_ordering": { "clause": "GROUP BY", "fanout": 1, "read_time": 2.0322, "table": "t1", "rows_estimation": 9, "possible_keys": [ { "index": "id", "can_resolve_order": true, "updated_limit": 16, "index_scan_time": 16, "records": 16, "chosen": true } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL id 8 NULL 16 Using where; Using index select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.`id` AS `id`,t1.a AS a from t1 where t1.a = 20010104e0 group by t1.`id`" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.a = 20010104e0", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "t1.a = 20010104e0" }, { "transformation": "constant_propagation", "resulting_condition": "t1.a = 20010104e0" }, { "transformation": "trivial_condition_removal", "resulting_condition": "t1.a = 20010104e0" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "table": "t1", "range_analysis": { "table_scan": { "rows": 16, "cost": 7.3313 }, "potential_range_indexes": [ { "index": "id", "usable": true, "key_parts": ["id", "a"] } ], "best_covering_index_scan": { "index": "id", "cost": 1.8468, "chosen": true }, "setup_range_conditions": [], "group_index_range": { "potential_group_range_indexes": [ { "index": "id", "covering": true, "ranges": ["0x24a20f <= a <= 0x24a20f"], "rows": 9, "cost": 2.35 } ] }, "best_group_range_summary": { "type": "index_group", "index": "id", "min_max_arg": null, "min_aggregate": false, "max_aggregate": false, "distinct_aggregate": false, "rows": 9, "cost": 2.35, "key_parts_used_for_access": ["id", "a"], "ranges": ["0x24a20f <= a <= 0x24a20f"], "chosen": false, "cause": "cost" }, "analyzing_range_alternatives": { "range_scan_alternatives": [], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] } } }, { "selectivity_for_indexes": [], "selectivity_for_columns": [], "cond_selectivity": 1 } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 16, "cost": 2.0312, "chosen": true, "use_tmp_table": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.a = 20010104e0", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": "t1.a = 20010104e0" } ] } }, { "reconsidering_access_paths_for_index_ordering": { "clause": "GROUP BY", "fanout": 1, "read_time": 2.0322, "table": "t1", "rows_estimation": 9, "possible_keys": [ { "index": "id", "can_resolve_order": true, "updated_limit": 16, "index_scan_time": 16, "records": 16, "chosen": true } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table t1; # # Late ORDER BY optimization # create table ten(a int); insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table one_k(a int primary key); insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C; create table t1 ( pk int not null, a int, b int, c int, filler char(100), KEY a_a(c), KEY a_c(a,c), KEY a_b(a,b) ); insert into t1 select a, a,a,a, 'filler-dataaa' from test.one_k; update t1 set a=1 where pk between 0 and 180; update t1 set b=2 where pk between 0 and 20; 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='enabled=on'; explain select * from t1 where a=1 and b=2 order by c limit 1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a_c,a_b a_c 5 NULL 180 Using where select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1 where a=1 and b=2 order by c limit 1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.pk AS pk,t1.a AS a,t1.b AS b,t1.c AS c,t1.filler AS filler from t1 where t1.a = 1 and t1.b = 2 order by t1.c limit 1" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.a = 1 and t1.b = 2", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "multiple equal(1, t1.a) and multiple equal(2, t1.b)" }, { "transformation": "constant_propagation", "resulting_condition": "multiple equal(1, t1.a) and multiple equal(2, t1.b)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(1, t1.a) and multiple equal(2, t1.b)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [ { "table": "t1", "field": "a", "equals": "1", "null_rejecting": false }, { "table": "t1", "field": "a", "equals": "1", "null_rejecting": false }, { "table": "t1", "field": "b", "equals": "2", "null_rejecting": false } ] }, { "rows_estimation": [ { "table": "t1", "range_analysis": { "table_scan": { "rows": 1000, "cost": 232.66 }, "potential_range_indexes": [ { "index": "a_a", "usable": false, "cause": "not applicable" }, { "index": "a_c", "usable": true, "key_parts": ["a", "c"] }, { "index": "a_b", "usable": true, "key_parts": ["a", "b"] } ], "setup_range_conditions": [], "group_index_range": { "chosen": false, "cause": "no group by or distinct" }, "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "a_c", "ranges": ["1 <= a <= 1"], "rowid_ordered": false, "using_mrr": false, "index_only": false, "rows": 180, "cost": 231.72, "chosen": true }, { "index": "a_b", "ranges": ["1 <= a <= 1 AND 2 <= b <= 2"], "rowid_ordered": true, "using_mrr": false, "index_only": false, "rows": 21, "cost": 27.445, "chosen": true } ], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] }, "chosen_range_access_summary": { "range_access_plan": { "type": "range_scan", "index": "a_b", "rows": 21, "ranges": ["1 <= a <= 1 AND 2 <= b <= 2"] }, "rows_for_plan": 21, "cost_for_plan": 27.445, "chosen": true } } }, { "selectivity_for_indexes": [ { "index_name": "a_b", "selectivity_from_index": 0.021 } ], "selectivity_for_columns": [ { "column_name": "a", "selectivity_from_histogram": 0.1797 }, { "column_name": "b", "selectivity_from_histogram": 0.0156 } ], "cond_selectivity": 0.021 } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "ref", "index": "a_c", "used_range_estimates": true, "rows": 180, "cost": 92, "chosen": true }, { "access_type": "ref", "index": "a_b", "used_range_estimates": true, "rows": 21, "cost": 22, "chosen": true }, { "type": "scan", "chosen": false, "cause": "cost" } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.a = 1 and t1.b = 2", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } }, { "reconsidering_access_paths_for_index_ordering": { "clause": "ORDER BY", "fanout": 1, "read_time": 22.001, "table": "t1", "rows_estimation": 21, "possible_keys": [ { "index": "a_a", "can_resolve_order": true, "updated_limit": 47, "index_scan_time": 47, "usable": false, "cause": "cost" }, { "index": "a_c", "can_resolve_order": true, "updated_limit": 47, "range_scan_time": 4.324, "index_scan_time": 4.324, "records": 180, "chosen": true }, { "index": "a_b", "can_resolve_order": false, "cause": "not usable index for the query" } ] } }, { "table": "t1", "range_analysis": { "table_scan": { "rows": 1000, "cost": 1202 }, "potential_range_indexes": [ { "index": "a_a", "usable": false, "cause": "not applicable" }, { "index": "a_c", "usable": true, "key_parts": ["a", "c"] }, { "index": "a_b", "usable": false, "cause": "not applicable" } ], "setup_range_conditions": [], "group_index_range": { "chosen": false, "cause": "no group by or distinct" }, "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "a_c", "ranges": ["1 <= a <= 1"], "rowid_ordered": false, "using_mrr": false, "index_only": false, "rows": 180, "cost": 231.72, "chosen": true } ], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] }, "chosen_range_access_summary": { "range_access_plan": { "type": "range_scan", "index": "a_c", "rows": 180, "ranges": ["1 <= a <= 1"] }, "rows_for_plan": 180, "cost_for_plan": 231.72, "chosen": true } } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table t1,ten,one_k; # # TABLE ELIMINATION # create table t1 (a int); insert into t1 values (0),(1),(2),(3); create table t0 as select * from t1; create table t2 (a int primary key, b int) as select a, a as b from t1 where a in (1,2); create table t3 (a int primary key, b int) as select a, a as b from t1 where a in (1,3); set optimizer_trace='enabled=on'; analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK analyze table t2; Table Op Msg_type Msg_text test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK analyze table t3; Table Op Msg_type Msg_text test.t3 analyze status Engine-independent statistics collected test.t3 analyze status OK # table t2 should be eliminated explain select t1.a from t1 left join t2 on t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select t1.a from t1 left join t2 on t1.a=t2.a { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.a AS a from (t1 left join t2 on(t1.a = t2.a))" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t2", "row_may_be_null": true, "map_bit": 1, "depends_on_map_bits": ["0"] } ] }, { "ref_optimizer_key_uses": [ { "table": "t2", "field": "a", "equals": "t1.a", "null_rejecting": true } ] }, { "eliminated_tables": ["t2"] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 4, "cost": 2.0068 } }, { "table": "t2", "rows": 1, "cost": 1, "table_type": "const" } ] }, { "considered_execution_plans": [ { "plan_prefix": ["t2"], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 4, "cost": 2.0068, "chosen": true } ] } } ] }, { "condition_on_constant_tables": "1" }, { "attaching_conditions_to_tables": { "original_condition": "1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 # no tables should be eliminated explain select * from t1 left join t2 on t2.a=t1.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1 left join t2 on t2.a=t1.a { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.a AS a,t2.a AS a,t2.b AS b from (t1 left join t2 on(t2.a = t1.a))" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t2", "row_may_be_null": true, "map_bit": 1, "depends_on_map_bits": ["0"] } ] }, { "ref_optimizer_key_uses": [ { "table": "t2", "field": "a", "equals": "t1.a", "null_rejecting": true } ] }, { "eliminated_tables": [] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 4, "cost": 2.0068 } }, { "table": "t2", "table_scan": { "rows": 2, "cost": 2.0044 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 4, "cost": 2.0068, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t2", "best_access_path": { "considered_access_paths": [ { "access_type": "eq_ref", "index": "PRIMARY", "rows": 1, "cost": 4, "chosen": true }, { "access_type": "scan", "resulting_rows": 2, "cost": 8.0176, "chosen": false } ] } } ] } ] }, { "condition_on_constant_tables": "1" }, { "attaching_conditions_to_tables": { "original_condition": "1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null }, { "table": "t2", "attached": "trigcond(trigcond(t1.a is not null))" } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 # multiple tables are eliminated explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and t3.a=t1.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and t3.a=t1.a { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.a AS a from (t1 left join (t2 join t3 on(t2.b = t3.b)) on(t2.a = t1.a and t3.a = t1.a))" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t2", "row_may_be_null": true, "map_bit": 1, "depends_on_map_bits": ["0"] }, { "table": "t3", "row_may_be_null": true, "map_bit": 2, "depends_on_map_bits": ["0"] } ] }, { "ref_optimizer_key_uses": [ { "table": "t2", "field": "a", "equals": "t1.a", "null_rejecting": true }, { "table": "t2", "field": "a", "equals": "t3.a", "null_rejecting": true }, { "table": "t3", "field": "a", "equals": "t2.a", "null_rejecting": true }, { "table": "t3", "field": "a", "equals": "t1.a", "null_rejecting": true } ] }, { "eliminated_tables": ["t3", "t2"] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 4, "cost": 2.0068 } }, { "table": "t2", "rows": 1, "cost": 1, "table_type": "const" }, { "table": "t3", "rows": 1, "cost": 1, "table_type": "const" } ] }, { "considered_execution_plans": [ { "plan_prefix": ["t3", "t2"], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 4, "cost": 2.0068, "chosen": true } ] } } ] }, { "condition_on_constant_tables": "1" }, { "attaching_conditions_to_tables": { "original_condition": "1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table t0, t1, t2, t3; # # IN subquery to sem-join is traced # create table t0 (a int); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t1(a int, b int); insert into t1 values (0,0),(1,1),(2,2); create table t2 as select * from t1; create table t11(a int, b int); create table t10 (pk int, a int); insert into t10 select a,a from t0; create table t12 like t10; insert into t12 select * from t10; analyze table t1,t10; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK test.t10 analyze status Engine-independent statistics collected test.t10 analyze status OK set optimizer_trace='enabled=on'; explain extended select * from t1 where a in (select pk from t10); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 2 MATERIALIZED t10 ALL NULL NULL NULL NULL 10 100.00 Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t10`) where 1 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain extended select * from t1 where a in (select pk from t10) { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "join_preparation": { "select_id": 2, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "chosen": true } }, { "expanded_query": "/* select#2 */ select t10.pk from t10" } ] } }, { "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from t1 where t1.a in (/* select#2 */ select t10.pk from t10)" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "converted_to_semi_join": true } }, { "condition_processing": { "condition": "WHERE", "original_condition": "1 and t1.a = t10.pk", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "1 and multiple equal(t1.a, t10.pk)" }, { "transformation": "constant_propagation", "resulting_condition": "1 and multiple equal(t1.a, t10.pk)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(t1.a, t10.pk)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t10", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 3, "cost": 2.0066 } }, { "table": "t10", "table_scan": { "rows": 10, "cost": 2.022 } } ] }, { "execution_plan_for_potential_materialization": { "steps": [ { "considered_execution_plans": [ { "plan_prefix": [], "table": "t10", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 10, "cost": 2.022, "chosen": true } ] } } ] } ] } }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0066, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t10", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 10, "cost": 2.022, "chosen": true } ] } } ] }, { "plan_prefix": [], "table": "t10", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 10, "cost": 2.022, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "fix_semijoin_strategies_for_picked_join_order": [ { "semi_join_strategy": "sj_materialize", "join_order": [ { "table": "t10" } ] } ] }, { "condition_on_constant_tables": "1" }, { "attaching_conditions_to_tables": { "original_condition": "1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null }, { "table": "t10", "attached": null }, { "table": "", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table t0,t1,t11,t10,t12,t2; # # Selectivities for columns and indexes. # create table t0 (a int); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t1 ( pk int, a int, b int, key pk(pk), key pk_a(pk,a), key pk_a_b(pk,a,b)); insert into t1 select a,a,a from t0; ANALYZE TABLE t1 PERSISTENT FOR COLUMNS (a,b) INDEXES (); 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 @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; set @save_use_stat_tables= @@use_stat_tables; set @@optimizer_use_condition_selectivity=4; set @@use_stat_tables= PREFERABLY; set optimizer_trace='enabled=on'; explain select * from t1 where pk = 2 and a=5 and b=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref pk,pk_a,pk_a_b pk_a_b 15 const,const,const 1 Using index select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1 where pk = 2 and a=5 and b=1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select t1.pk AS pk,t1.a AS a,t1.b AS b from t1 where t1.pk = 2 and t1.a = 5 and t1.b = 1" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t1.pk = 2 and t1.a = 5 and t1.b = 1", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "multiple equal(2, t1.pk) and multiple equal(5, t1.a) and multiple equal(1, t1.b)" }, { "transformation": "constant_propagation", "resulting_condition": "multiple equal(2, t1.pk) and multiple equal(5, t1.a) and multiple equal(1, t1.b)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(2, t1.pk) and multiple equal(5, t1.a) and multiple equal(1, t1.b)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [ { "table": "t1", "field": "pk", "equals": "2", "null_rejecting": false }, { "table": "t1", "field": "pk", "equals": "2", "null_rejecting": false }, { "table": "t1", "field": "a", "equals": "5", "null_rejecting": false }, { "table": "t1", "field": "pk", "equals": "2", "null_rejecting": false }, { "table": "t1", "field": "a", "equals": "5", "null_rejecting": false }, { "table": "t1", "field": "b", "equals": "1", "null_rejecting": false } ] }, { "rows_estimation": [ { "table": "t1", "range_analysis": { "table_scan": { "rows": 10, "cost": 6.1317 }, "potential_range_indexes": [ { "index": "pk", "usable": true, "key_parts": ["pk"] }, { "index": "pk_a", "usable": true, "key_parts": ["pk", "a"] }, { "index": "pk_a_b", "usable": true, "key_parts": ["pk", "a", "b"] } ], "best_covering_index_scan": { "index": "pk_a_b", "cost": 1.5429, "chosen": true }, "setup_range_conditions": [], "group_index_range": { "chosen": false, "cause": "no group by or distinct" }, "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "pk", "ranges": ["2 <= pk <= 2"], "rowid_ordered": true, "using_mrr": false, "index_only": false, "rows": 1, "cost": 2.3773, "chosen": false, "cause": "cost" }, { "index": "pk_a", "ranges": ["2 <= pk <= 2 AND 5 <= a <= 5"], "rowid_ordered": true, "using_mrr": false, "index_only": false, "rows": 1, "cost": 2.3783, "chosen": false, "cause": "cost" }, { "index": "pk_a_b", "ranges": ["2 <= pk <= 2 AND 5 <= a <= 5 AND 1 <= b <= 1"], "rowid_ordered": true, "using_mrr": false, "index_only": true, "rows": 1, "cost": 1.1793, "chosen": true } ], "analyzing_roworder_intersect": { "intersecting_indexes": [ { "index": "pk", "index_scan_cost": 1.0023, "cumulateed_index_scan_cost": 1.0023, "disk_sweep_cost": 0.9008, "cumulative_total_cost": 1.9031, "usable": true, "matching_rows_now": 1, "intersect_covering_with_this_index": false, "chosen": true }, { "index": "pk_a", "usable": false, "cause": "does not reduce cost of intersect" }, { "index": "pk_a_b", "usable": false, "cause": "does not reduce cost of intersect" } ], "clustered_pk": { "clustered_pk_added_to_intersect": false, "cause": "no clustered pk index" }, "chosen": false, "cause": "cost" }, "analyzing_index_merge_union": [] }, "chosen_range_access_summary": { "range_access_plan": { "type": "range_scan", "index": "pk_a_b", "rows": 1, "ranges": ["2 <= pk <= 2 AND 5 <= a <= 5 AND 1 <= b <= 1"] }, "rows_for_plan": 1, "cost_for_plan": 1.1793, "chosen": true } } }, { "selectivity_for_indexes": [ { "index_name": "pk_a_b", "selectivity_from_index": 0.1 } ], "selectivity_for_columns": [ { "column_name": "a", "selectivity_from_histogram": 0.1 }, { "column_name": "b", "selectivity_from_histogram": 0.1 } ], "cond_selectivity": 0.1 } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "ref", "index": "pk", "used_range_estimates": true, "rows": 1, "cost": 2, "chosen": true }, { "access_type": "ref", "index": "pk_a", "used_range_estimates": true, "rows": 1, "cost": 2, "chosen": false, "cause": "cost" }, { "access_type": "ref", "index": "pk_a_b", "used_range_estimates": true, "rows": 1, "cost": 1.0043, "chosen": true }, { "type": "scan", "chosen": false, "cause": "cost" } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.pk = 2 and t1.a = 5 and t1.b = 1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; set @@use_stat_tables= @save_use_stat_tables; drop table t0,t1; set optimizer_trace="enabled=off"; # # Tests added to show that sub-statements are not traced # create table t1(a int); insert into t1 values (1),(2),(3),(4); create table t2(a int); insert into t2 values (1),(2),(3),(4); create function f1(a int) returns int begin declare a int default 0; set a= a+ (select count(*) from t2); return a; end| create function f2(a int) returns int begin declare a int default 0; select count(*) from t2 into a; return a; end| Warnings: Warning 1287 ' INTO FROM...' instead set optimizer_trace='enabled=on'; select f1(a) from t1; f1(a) 4 4 4 4 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES select f1(a) from t1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select f1(t1.a) AS `f1(a)` from t1" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 4, "cost": 2.0068 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 4, "cost": 2.0068, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 select f2(a) from t1; f2(a) 4 4 4 4 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES select f2(a) from t1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select f2(t1.a) AS `f2(a)` from t1" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 4, "cost": 2.0068 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 4, "cost": 2.0068, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table t1,t2; drop function f1; drop function f2; set optimizer_trace='enabled=off'; # # MDEV-18489: Limit the memory used by the optimizer trace # create table t1 (a int); insert into t1 values (1),(2); set optimizer_trace='enabled=on'; set @save_optimizer_trace_max_mem_size= @@optimizer_trace_max_mem_size; select * from t1; a 1 2 select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; length(trace) 1754 set optimizer_trace_max_mem_size=100; select * from t1; a 1 2 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES select * from t1 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ 1654 0 set optimizer_trace_max_mem_size=0; select * from t1; a 1 2 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES select * from t1 1754 0 drop table t1; set optimizer_trace='enabled=off'; set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size; # # MDEV-18527: Optimizer trace for DELETE query shows table:null # create table ten(a int); insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t0 (a int, b int); insert into t0 select a,a from ten; alter table t0 add key(a); set optimizer_trace=1; explain delete from t0 where t0.a<3; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t0 range a a 5 NULL 3 Using where select * from information_schema.optimizer_trace; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain delete from t0 where t0.a<3 { "steps": [ { "table": "t0", "range_analysis": { "table_scan": { "rows": 10, "cost": 6.122 }, "potential_range_indexes": [ { "index": "a", "usable": true, "key_parts": ["a"] } ], "setup_range_conditions": [], "group_index_range": { "chosen": false, "cause": "no join" }, "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "a", "ranges": ["NULL < a < 3"], "rowid_ordered": false, "using_mrr": false, "index_only": false, "rows": 3, "cost": 5.007, "chosen": true } ], "analyzing_index_merge_union": [] }, "chosen_range_access_summary": { "range_access_plan": { "type": "range_scan", "index": "a", "rows": 3, "ranges": ["NULL < a < 3"] }, "rows_for_plan": 3, "cost_for_plan": 5.007, "chosen": true } } } ] } 0 0 drop table ten,t0; set optimizer_trace='enabled=off'; # # MDEV-18528: Optimizer trace support for multi-table UPDATE and DELETE # set optimizer_trace=1; create table ten(a int); insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t0 (a int, b int); insert into t0 select a,a from ten; alter table t0 add key(a); create table t1 like t0; insert into t1 select * from t0; explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t0 range a a 5 NULL 3 Using where 1 SIMPLE t1 ref a a 5 test.t0.a 1 select * from information_schema.optimizer_trace; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "expanded_query": "select NULL AS `NULL` from t0 join t1 where t0.a = t1.a and t1.a < 3" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "condition_processing": { "condition": "WHERE", "original_condition": "t0.a = t1.a and t1.a < 3", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "t1.a < 3 and multiple equal(t0.a, t1.a)" }, { "transformation": "constant_propagation", "resulting_condition": "t1.a < 3 and multiple equal(t0.a, t1.a)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "t1.a < 3 and multiple equal(t0.a, t1.a)" } ] } }, { "table_dependencies": [ { "table": "t0", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t1", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [ { "table": "t0", "field": "a", "equals": "t1.a", "null_rejecting": true }, { "table": "t1", "field": "a", "equals": "t0.a", "null_rejecting": true } ] }, { "rows_estimation": [ { "table": "t0", "range_analysis": { "table_scan": { "rows": 10, "cost": 6.122 }, "potential_range_indexes": [ { "index": "a", "usable": true, "key_parts": ["a"] } ], "best_covering_index_scan": { "index": "a", "cost": 1.5234, "chosen": true }, "setup_range_conditions": [], "group_index_range": { "chosen": false, "cause": "not single_table" }, "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "a", "ranges": ["NULL < a < 3"], "rowid_ordered": false, "using_mrr": false, "index_only": true, "rows": 3, "cost": 1.407, "chosen": true } ], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] }, "chosen_range_access_summary": { "range_access_plan": { "type": "range_scan", "index": "a", "rows": 3, "ranges": ["NULL < a < 3"] }, "rows_for_plan": 3, "cost_for_plan": 1.407, "chosen": true } } }, { "selectivity_for_indexes": [ { "index_name": "a", "selectivity_from_index": 0.3 } ], "selectivity_for_columns": [], "cond_selectivity": 0.3 }, { "table": "t1", "range_analysis": { "table_scan": { "rows": 10, "cost": 6.122 }, "potential_range_indexes": [ { "index": "a", "usable": true, "key_parts": ["a"] } ], "best_covering_index_scan": { "index": "a", "cost": 1.5234, "chosen": true }, "setup_range_conditions": [], "group_index_range": { "chosen": false, "cause": "not single_table" }, "analyzing_range_alternatives": { "range_scan_alternatives": [ { "index": "a", "ranges": ["NULL < a < 3"], "rowid_ordered": false, "using_mrr": false, "index_only": true, "rows": 3, "cost": 1.407, "chosen": true } ], "analyzing_roworder_intersect": { "cause": "too few roworder scans" }, "analyzing_index_merge_union": [] }, "chosen_range_access_summary": { "range_access_plan": { "type": "range_scan", "index": "a", "rows": 3, "ranges": ["NULL < a < 3"] }, "rows_for_plan": 3, "cost_for_plan": 1.407, "chosen": true } } }, { "selectivity_for_indexes": [ { "index_name": "a", "selectivity_from_index": 0.3 } ], "selectivity_for_columns": [], "cond_selectivity": 0.3 } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t0", "best_access_path": { "considered_access_paths": [ { "access_type": "range", "resulting_rows": 3, "cost": 1.407, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t0"], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "ref", "index": "a", "used_range_estimates": false, "cause": "not better than ref estimates", "rows": 1, "cost": 3.007, "chosen": true }, { "type": "scan", "chosen": false, "cause": "cost" } ] } } ] }, { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "range", "resulting_rows": 3, "cost": 1.407, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t0", "best_access_path": { "considered_access_paths": [ { "access_type": "ref", "index": "a", "used_range_estimates": false, "cause": "not better than ref estimates", "rows": 2, "cost": 3.014, "chosen": true }, { "type": "scan", "chosen": false, "cause": "cost" } ] }, "pruned_by_cost": true } ] } ] }, { "attaching_conditions_to_tables": { "original_condition": "t1.a = t0.a and t0.a < 3", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t0", "attached": "t0.a < 3 and t0.a is not null" }, { "table": "t1", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 drop table ten,t0,t1; set optimizer_trace='enabled=off'; # # Merged to Materialized for derived tables # set optimizer_trace=1; create table t1 (a int); insert into t1 values (1),(2),(3); explain select * from (select rand() from t1)q; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ALL NULL NULL NULL NULL 3 2 DERIVED t1 ALL NULL NULL NULL NULL 3 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from (select rand() from t1)q { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "derived": { "table": "q", "select_id": 2, "algorithm": "merged" } }, { "join_preparation": { "select_id": 2, "steps": [ { "expanded_query": "/* select#2 */ select rand() AS `rand()` from t1" } ] } }, { "expanded_query": "/* select#1 */ select rand() AS `rand()` from (/* select#2 */ select rand() AS `rand()` from t1) q" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "derived": { "table": "q", "select_id": 2, "algorithm": "materialized", "cause": "Random function in the select" } }, { "join_optimization": { "select_id": 2, "steps": [ { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 3, "cost": 2.0051 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null } ] } } ] } }, { "table_dependencies": [ { "table": "", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] } ] }, { "rows_estimation": [ { "table": "", "table_scan": { "rows": 3, "cost": 3 } } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 3, "chosen": true } ] } } ] }, { "attaching_conditions_to_tables": { "original_condition": null, "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [ { "join_execution": { "select_id": 2, "steps": [] } } ] } } ] } 0 0 drop table t1; set optimizer_trace='enabled=off'; # # Semi-join nest # set optimizer_trace=1; create table t1 (a int); insert into t1 values (1),(2),(3); create table t2(a int); insert into t2 values (1),(2),(3),(1),(2),(3),(1),(2),(3); set @save_optimizer_switch= @@optimizer_switch; explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_inner_2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 2 MATERIALIZED t_inner_1 ALL NULL NULL NULL NULL 3 2 MATERIALIZED t_inner_2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_inner_2) { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "join_preparation": { "select_id": 2, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "chosen": true } }, { "expanded_query": "/* select#2 */ select t_inner_1.a from t1 t_inner_1 join t1 t_inner_2" } ] } }, { "expanded_query": "/* select#1 */ select t1.a AS a from t1 where t1.a in (/* select#2 */ select t_inner_1.a from t1 t_inner_1 join t1 t_inner_2)" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "converted_to_semi_join": true } }, { "condition_processing": { "condition": "WHERE", "original_condition": "1 and t1.a = t_inner_1.a", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "1 and multiple equal(t1.a, t_inner_1.a)" }, { "transformation": "constant_propagation", "resulting_condition": "1 and multiple equal(t1.a, t_inner_1.a)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(t1.a, t_inner_1.a)" } ] } }, { "table_dependencies": [ { "table": "t1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t_inner_1", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] }, { "table": "t_inner_2", "row_may_be_null": false, "map_bit": 2, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "table": "t1", "table_scan": { "rows": 3, "cost": 2.0051 } }, { "table": "t_inner_1", "table_scan": { "rows": 3, "cost": 2.0051 } }, { "table": "t_inner_2", "table_scan": { "rows": 3, "cost": 2.0051 } } ] }, { "execution_plan_for_potential_materialization": { "steps": [ { "considered_execution_plans": [ { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_inner_1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] } } ] }, { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true } ] } ] } }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t1", "t_inner_1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] } } ] }, { "plan_prefix": ["t1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "fix_semijoin_strategies_for_picked_join_order": [ { "semi_join_strategy": "sj_materialize", "join_order": [ { "table": "t_inner_1" }, { "table": "t_inner_2" } ] } ] }, { "condition_on_constant_tables": "1" }, { "attaching_conditions_to_tables": { "original_condition": "1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t1", "attached": null }, { "table": "t_inner_1", "attached": null }, { "table": "t_inner_2", "attached": null }, { "table": "", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 # with Firstmatch, mostly for tracing fix_semijoin_strategies_for_picked_join_order set optimizer_switch='materialization=off'; explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3 1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 FirstMatch(t_outer_1); Using join buffer (incremental, BNL join) 1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (incremental, BNL join) 1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) 1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; FirstMatch(t_outer_2); Using join buffer (incremental, BNL join) select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "join_preparation": { "select_id": 2, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "chosen": true } }, { "expanded_query": "/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1" } ] } }, { "join_preparation": { "select_id": 3, "steps": [ { "transformation": { "select_id": 3, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "transformation": { "select_id": 3, "from": "IN (SELECT)", "to": "semijoin", "chosen": true } }, { "expanded_query": "/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4" } ] } }, { "expanded_query": "/* select#1 */ select t_outer_1.a AS a,t_outer_2.a AS a from t1 t_outer_1 join t2 t_outer_2 where t_outer_1.a in (/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1) and t_outer_2.a in (/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4)" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "converted_to_semi_join": true } }, { "transformation": { "select_id": 3, "from": "IN (SELECT)", "to": "semijoin", "converted_to_semi_join": true } }, { "condition_processing": { "condition": "WHERE", "original_condition": "1 and 1 and t_outer_1.a = t_inner_1.a and t_outer_2.a = t_inner_3.a", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" }, { "transformation": "constant_propagation", "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" } ] } }, { "table_dependencies": [ { "table": "t_outer_1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t_outer_2", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] }, { "table": "t_inner_2", "row_may_be_null": false, "map_bit": 2, "depends_on_map_bits": [] }, { "table": "t_inner_1", "row_may_be_null": false, "map_bit": 3, "depends_on_map_bits": [] }, { "table": "t_inner_3", "row_may_be_null": false, "map_bit": 4, "depends_on_map_bits": [] }, { "table": "t_inner_4", "row_may_be_null": false, "map_bit": 5, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "table": "t_outer_1", "table_scan": { "rows": 3, "cost": 2.0051 } }, { "table": "t_outer_2", "table_scan": { "rows": 9, "cost": 2.0154 } }, { "table": "t_inner_2", "table_scan": { "rows": 9, "cost": 2.0154 } }, { "table": "t_inner_1", "table_scan": { "rows": 3, "cost": 2.0051 } }, { "table": "t_inner_3", "table_scan": { "rows": 9, "cost": 2.0154 } }, { "table": "t_inner_4", "table_scan": { "rows": 3, "cost": 2.0051 } } ] }, { "execution_plan_for_potential_materialization": { "steps": [] } }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t_outer_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1"], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_outer_2" ], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_outer_2", "t_inner_4" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] } } ] }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_outer_2" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_inner_4" ], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_inner_4", "t_outer_2" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_inner_4" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_outer_2", "t_inner_4" ], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_outer_2", "t_inner_4" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_4", "t_outer_2" ], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_4", "t_outer_2" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_3", "t_outer_2" ], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_cost": true }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_3", "t_outer_2" ], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_3", "t_inner_4" ], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_3", "t_inner_4" ], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] } ] }, { "plan_prefix": ["t_outer_1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "fix_semijoin_strategies_for_picked_join_order": [ { "semi_join_strategy": "firstmatch", "join_order": [ { "table": "t_inner_4" }, "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 162.42, "chosen": true } ] }, { "table": "t_inner_3" }, "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 489.74, "chosen": true } ] } ] }, { "semi_join_strategy": "firstmatch", "join_order": [ { "table": "t_inner_1" }, "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 18.046, "chosen": true } ] }, { "table": "t_inner_2" }, "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 54.415, "chosen": true } ] } ] } ] }, { "attaching_conditions_to_tables": { "original_condition": "t_inner_1.a = t_outer_1.a and t_inner_3.a = t_outer_2.a", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t_outer_1", "attached": null }, { "table": "t_inner_1", "attached": "t_inner_1.a = t_outer_1.a" }, { "table": "t_inner_2", "attached": null }, { "table": "t_outer_2", "attached": null }, { "table": "t_inner_4", "attached": null }, { "table": "t_inner_3", "attached": "t_inner_3.a = t_outer_2.a" } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 set optimizer_switch='materialization=on'; explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join) 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 2 MATERIALIZED t_inner_1 ALL NULL NULL NULL NULL 3 2 MATERIALIZED t_inner_2 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join) 3 MATERIALIZED t_inner_4 ALL NULL NULL NULL NULL 3 3 MATERIALIZED t_inner_3 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join) select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "steps": [ { "join_preparation": { "select_id": 1, "steps": [ { "join_preparation": { "select_id": 2, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "chosen": true } }, { "expanded_query": "/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1" } ] } }, { "join_preparation": { "select_id": 3, "steps": [ { "transformation": { "select_id": 3, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "transformation": { "select_id": 3, "from": "IN (SELECT)", "to": "semijoin", "chosen": true } }, { "expanded_query": "/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4" } ] } }, { "expanded_query": "/* select#1 */ select t_outer_1.a AS a,t_outer_2.a AS a from t1 t_outer_1 join t2 t_outer_2 where t_outer_1.a in (/* select#2 */ select t_inner_1.a from t2 t_inner_2 join t1 t_inner_1) and t_outer_2.a in (/* select#3 */ select t_inner_3.a from t2 t_inner_3 join t1 t_inner_4)" } ] } }, { "join_optimization": { "select_id": 1, "steps": [ { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "semijoin", "converted_to_semi_join": true } }, { "transformation": { "select_id": 3, "from": "IN (SELECT)", "to": "semijoin", "converted_to_semi_join": true } }, { "condition_processing": { "condition": "WHERE", "original_condition": "1 and 1 and t_outer_1.a = t_inner_1.a and t_outer_2.a = t_inner_3.a", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" }, { "transformation": "constant_propagation", "resulting_condition": "1 and 1 and multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(t_outer_1.a, t_inner_1.a) and multiple equal(t_outer_2.a, t_inner_3.a)" } ] } }, { "table_dependencies": [ { "table": "t_outer_1", "row_may_be_null": false, "map_bit": 0, "depends_on_map_bits": [] }, { "table": "t_outer_2", "row_may_be_null": false, "map_bit": 1, "depends_on_map_bits": [] }, { "table": "t_inner_2", "row_may_be_null": false, "map_bit": 2, "depends_on_map_bits": [] }, { "table": "t_inner_1", "row_may_be_null": false, "map_bit": 3, "depends_on_map_bits": [] }, { "table": "t_inner_3", "row_may_be_null": false, "map_bit": 4, "depends_on_map_bits": [] }, { "table": "t_inner_4", "row_may_be_null": false, "map_bit": 5, "depends_on_map_bits": [] } ] }, { "ref_optimizer_key_uses": [] }, { "rows_estimation": [ { "table": "t_outer_1", "table_scan": { "rows": 3, "cost": 2.0051 } }, { "table": "t_outer_2", "table_scan": { "rows": 9, "cost": 2.0154 } }, { "table": "t_inner_2", "table_scan": { "rows": 9, "cost": 2.0154 } }, { "table": "t_inner_1", "table_scan": { "rows": 3, "cost": 2.0051 } }, { "table": "t_inner_3", "table_scan": { "rows": 9, "cost": 2.0154 } }, { "table": "t_inner_4", "table_scan": { "rows": 3, "cost": 2.0051 } } ] }, { "execution_plan_for_potential_materialization": { "steps": [ { "considered_execution_plans": [ { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_inner_1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] } } ] }, { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_inner_4"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] } } ] }, { "plan_prefix": [], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] } ] } }, { "considered_execution_plans": [ { "plan_prefix": [], "table": "t_outer_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1"], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_outer_2" ], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_outer_2", "t_inner_4" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] } } ] }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_outer_2" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "rest_of_plan": [ { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_inner_4" ], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true }, { "plan_prefix": [ "t_outer_1", "t_inner_1", "t_inner_2", "t_inner_4" ], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true }, { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_cost": true } ] }, { "plan_prefix": ["t_outer_1"], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1"], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1"], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": ["t_outer_1"], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_outer_2", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_inner_4", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 3, "cost": 2.0051, "chosen": true } ] }, "pruned_by_heuristic": true }, { "plan_prefix": [], "table": "t_inner_3", "best_access_path": { "considered_access_paths": [ { "access_type": "scan", "resulting_rows": 9, "cost": 2.0154, "chosen": true } ] }, "pruned_by_heuristic": true } ] }, { "fix_semijoin_strategies_for_picked_join_order": [ { "semi_join_strategy": "sj_materialize", "join_order": [ { "table": "t_inner_4" }, { "table": "t_inner_3" } ] }, { "semi_join_strategy": "sj_materialize", "join_order": [ { "table": "t_inner_1" }, { "table": "t_inner_2" } ] } ] }, { "condition_on_constant_tables": "1" }, { "attaching_conditions_to_tables": { "original_condition": "1", "attached_conditions_computation": [], "attached_conditions_summary": [ { "table": "t_outer_1", "attached": null }, { "table": "t_inner_1", "attached": null }, { "table": "t_inner_2", "attached": null }, { "table": "", "attached": null }, { "table": "t_outer_2", "attached": null }, { "table": "t_inner_4", "attached": null }, { "table": "t_inner_3", "attached": null }, { "table": "", "attached": null } ] } } ] } }, { "join_execution": { "select_id": 1, "steps": [] } } ] } 0 0 set @@optimizer_switch= @save_optimizer_switch; drop table t1,t2; set optimizer_trace='enabled=off';