├── assets ├── join3-prepare-example.org ├── join3.mysqld.trace ├── join3_01_opt.sql ├── join3_01_opt.sql.json ├── join3_02_opt.sql ├── join3_02_opt.sql.json ├── join3_03_opt.sql ├── join3_03_opt.sql.json ├── join4.mysqld.trace ├── join5.mysqld.trace ├── mysqld.trace.exe01.log ├── mysqld.trace.select01.log ├── p12-opttrace-01.json ├── rewrite-insert-rule.sql ├── sdi-rtc-tt.json ├── subq01_scalar_exp.sql.json ├── subq01_scalar_opt.sql.json ├── subq02_unique_exp.sql.json ├── subq02_unique_opt.sql.json ├── subq03_non-unique_exp.sql.json ├── subq03_non-unique_opt.sql.json ├── subq04_exists_exp.sql.json ├── subq04_exists_opt.sql.json ├── subq05_not-in_exp.sql.json ├── subq05_not-in_opt.sql.json ├── subq06_derived-table_exp.sql.json ├── subq06_derived-table_opt.sql.json ├── subq10_sj_default_exp.sql.json ├── subq10_sj_default_opt.sql.json ├── subq11_sj_duplicate-weedout_exp.sql.json ├── subq11_sj_duplicate-weedout_opt.sql.json ├── subq12_sj_first-match_exp.sql.json ├── subq12_sj_first-match_opt.sql.json ├── subq13_sj_loose-scan_exp.sql.json ├── subq13_sj_loose-scan_opt.sql.json ├── subq14_sj_materialization_exp.sql.json ├── subq14_sj_materialization_opt.sql.json ├── subq20_sj_default_exp.sql.json ├── subq20_sj_default_opt.sql.json ├── subq21_sj_duplicate-weedout_exp.sql.json ├── subq21_sj_duplicate-weedout_opt.sql.json ├── subq22_sj_first-match_exp.sql.json ├── subq23_sj_loose-scan_exp.sql.json ├── subq23_sj_loose-scan_opt.sql.json ├── subq24_sj_materialization_exp.sql.json ├── subq24_sj_materialization_opt.sql.json ├── subquery-examples.org └── thd-name-ref.org ├── figures └── mysql-poster.svg ├── lab ├── docker-compose.yml ├── p22.sql ├── t10w.sql └── t500w.sql ├── notes ├── n22.pdf ├── n23.pdf ├── n24.pdf ├── n25.pdf ├── n26.pdf ├── n27.pdf ├── n28.pdf └── n29.pdf ├── query ├── exe01.sql ├── exe02.sql ├── init-record-list.sql ├── join3.sql ├── join3_straight.sql ├── join4.sql ├── join5.sql ├── pfs_setup.sql ├── q.sql ├── subq01.sql ├── subq02.sql ├── subq03.sql ├── subq04.sql ├── subq05.sql └── subq06.sql ├── readme.org ├── scripts ├── dbg-attach-gdb.sh ├── dbg-attach-lldb.sh ├── dbg-start-lldb.sh ├── rtc-index-source-code.sh ├── rtc-step1-install-depends.sh ├── rtc-step2-setup-boost.sh ├── rtc-step3-build-mysql-server-27.sh ├── rtc-step3-build-mysql-server.sh ├── rtc-step4-create-user.sh ├── sys-print-threads.sh ├── sys-top-threads.sh └── tra-list-query.sh ├── slides ├── p01-introduction-to-RDMS.pdf ├── p02-build-mysql-from-source.pdf ├── p03-mysql-architecture.pdf ├── p04-mysql-startup.pdf ├── p05-mysql-thread-model.pdf ├── p06-server-connection-manager.pdf ├── p07-server-thd-manager.pdf ├── p08-net-dispatch-command.pdf ├── p09-lexical-scanner.pdf ├── p10-syntax-parser.pdf ├── p11-contextualize-parse-tree.pdf ├── p12-introduction-to-optimizer.pdf ├── p13-rewrite-and-prepare.pdf ├── p14-enter-optimizer.pdf ├── p15-optimizer-and-cost-model.pdf ├── p16-join-order-optimizer.pdf ├── p17-subquery-optimizer.pdf ├── p18-enter-executor.pdf ├── p19-profile-handlerton.pdf ├── p20-innodb-datafile.pdf ├── p21-innodb-row-format.pdf ├── p22-innobase-reader-cli.pdf ├── p23-parse-record.pdf ├── p24-online-ddl-development.pdf ├── p25-datafile-physical-struct.pdf ├── p26-index-btree.pdf ├── p27-undo-log.pdf ├── p28-redo-log.pdf ├── p29-mvcc-trx-iso.pdf └── p30-buffer-pool.pdf └── version /assets/join3-prepare-example.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 三表连接不同查询写法的 Opt_trace 对比 2 | #+AUTHOR: Jinghui Hu 3 | #+EMAIL: hujinghui@buaa.edu.cn 4 | #+DATE: <2024-06-29 Sat> 5 | #+STARTUP: overview num indent 6 | #+OPTIONS: ^:nil 7 | 8 | 9 | * join3_01 10 | - [[file:join3_01_opt.sql][sql]] | [[file:join3_01_opt.sql.json][opt_trace]] 11 | #+BEGIN_SRC sql 12 | select 13 | e.first_name, e.last_name, a.from_date 14 | from 15 | dept_manager a 16 | join departments d on a.dept_no = d.dept_no 17 | join employees e on a.emp_no = e.emp_no 18 | where 19 | d.dept_no = 'd001'; 20 | #+END_SRC 21 | - preparation 22 | #+BEGIN_EXAMPLE 23 | "join_preparation": { 24 | "select#": 1, 25 | "steps": [ 26 | { 27 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS 28 | `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` 29 | from ((`dept_manager` `a` join `departments` `d` on((`a`.`dept_no` = 30 | `d`.`dept_no`))) join `employees` `e` on((`a`.`emp_no` = `e`.`emp_no`))) 31 | where (`d`.`dept_no` = 'd001')" 32 | }, 33 | { 34 | "transformations_to_nested_joins": { 35 | "transformations": [ 36 | "JOIN_condition_to_WHERE", 37 | "parenthesis_removal" 38 | ], 39 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS 40 | `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS 41 | `from_date` from `dept_manager` `a` join `departments` `d` join 42 | `employees` `e` where ((`d`.`dept_no` = 'd001') and (`a`.`emp_no` = 43 | `e`.`emp_no`) and (`a`.`dept_no` = `d`.`dept_no`))" 44 | 45 | } 46 | ] 47 | } 48 | #+END_EXAMPLE 49 | 50 | * join3_02 51 | - [[file:join3_02_opt.sql][sql]] | [[file:join3_02_opt.sql.json][opt_trace]] 52 | #+BEGIN_SRC sql 53 | select 54 | e.first_name, e.last_name, a.from_date 55 | from 56 | dept_manager a join departments d join employees e 57 | where 58 | a.dept_no = d.dept_no and a.emp_no = e.emp_no and d.dept_no = 'd001'; 59 | #+END_SRC 60 | - preparation 61 | #+BEGIN_EXAMPLE 62 | "join_preparation": { 63 | "select#": 1, 64 | "steps": [ 65 | { 66 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS 67 | `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` 68 | from ((`dept_manager` `a` join `departments` `d`) join `employees` `e`) 69 | where ((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` = `e`.`emp_no`) 70 | and (`d`.`dept_no` = 'd001'))" 71 | }, 72 | { 73 | "transformations_to_nested_joins": { 74 | "transformations": [ 75 | "parenthesis_removal" 76 | ], 77 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS 78 | `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS 79 | `from_date` from `dept_manager` `a` join `departments` `d` join 80 | `employees` `e` where ((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` 81 | = `e`.`emp_no`) and (`d`.`dept_no` = 'd001'))" 82 | } 83 | } 84 | ] 85 | } 86 | #+END_EXAMPLE 87 | 88 | * join3_03 89 | - [[file:join3_03_opt.sql][sql]] | [[file:join3_03_opt.sql.json][opt_trace]] 90 | #+BEGIN_SRC sql 91 | select 92 | e.first_name, e.last_name, a.from_date 93 | from 94 | dept_manager a, departments d, employees e 95 | where 96 | a.dept_no = d.dept_no and a.emp_no = e.emp_no and d.dept_no = 'd001'; 97 | #+END_SRC 98 | - preparation 99 | #+BEGIN_EXAMPLE 100 | "join_preparation": { 101 | "select#": 1, 102 | "steps": [ 103 | { 104 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS 105 | `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` 106 | from `dept_manager` `a` join `departments` `d` join `employees` `e` where 107 | ((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` = `e`.`emp_no`) and 108 | (`d`.`dept_no` = 'd001'))" 109 | } 110 | ] 111 | } 112 | #+END_EXAMPLE 113 | -------------------------------------------------------------------------------- /assets/join3_01_opt.sql: -------------------------------------------------------------------------------- 1 | use employees; 2 | 3 | set optimizer_trace="enabled=on"; 4 | 5 | select 6 | e.first_name, e.last_name, a.from_date 7 | from 8 | dept_manager a 9 | join departments d on a.dept_no = d.dept_no 10 | join employees e on a.emp_no = e.emp_no 11 | where 12 | d.dept_no = 'd001'; 13 | 14 | select trace from information_schema.optimizer_trace\G 15 | -------------------------------------------------------------------------------- /assets/join3_01_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` from ((`dept_manager` `a` join `departments` `d` on((`a`.`dept_no` = `d`.`dept_no`))) join `employees` `e` on((`a`.`emp_no` = `e`.`emp_no`))) where (`d`.`dept_no` = 'd001')" 9 | }, 10 | { 11 | "transformations_to_nested_joins": { 12 | "transformations": [ 13 | "JOIN_condition_to_WHERE", 14 | "parenthesis_removal" 15 | ], 16 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` from `dept_manager` `a` join `departments` `d` join `employees` `e` where ((`d`.`dept_no` = 'd001') and (`a`.`emp_no` = `e`.`emp_no`) and (`a`.`dept_no` = `d`.`dept_no`))" 17 | } 18 | } 19 | ] 20 | } 21 | }, 22 | { 23 | "join_optimization": { 24 | "select#": 1, 25 | "steps": [ 26 | { 27 | "condition_processing": { 28 | "condition": "WHERE", 29 | "original_condition": "((`d`.`dept_no` = 'd001') and (`a`.`emp_no` = `e`.`emp_no`) and (`a`.`dept_no` = `d`.`dept_no`))", 30 | "steps": [ 31 | { 32 | "transformation": "equality_propagation", 33 | "resulting_condition": "(multiple equal('d001', `d`.`dept_no`, `a`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 34 | }, 35 | { 36 | "transformation": "constant_propagation", 37 | "resulting_condition": "(multiple equal('d001', `d`.`dept_no`, `a`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 38 | }, 39 | { 40 | "transformation": "trivial_condition_removal", 41 | "resulting_condition": "(multiple equal('d001', `d`.`dept_no`, `a`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 42 | } 43 | ] 44 | } 45 | }, 46 | { 47 | "substitute_generated_columns": {} 48 | }, 49 | { 50 | "table_dependencies": [ 51 | { 52 | "table": "`dept_manager` `a`", 53 | "row_may_be_null": false, 54 | "map_bit": 0, 55 | "depends_on_map_bits": [] 56 | }, 57 | { 58 | "table": "`departments` `d`", 59 | "row_may_be_null": false, 60 | "map_bit": 1, 61 | "depends_on_map_bits": [] 62 | }, 63 | { 64 | "table": "`employees` `e`", 65 | "row_may_be_null": false, 66 | "map_bit": 2, 67 | "depends_on_map_bits": [] 68 | } 69 | ] 70 | }, 71 | { 72 | "ref_optimizer_key_uses": [ 73 | { 74 | "table": "`dept_manager` `a`", 75 | "field": "emp_no", 76 | "equals": "`e`.`emp_no`", 77 | "null_rejecting": true 78 | }, 79 | { 80 | "table": "`dept_manager` `a`", 81 | "field": "dept_no", 82 | "equals": "'d001'", 83 | "null_rejecting": true 84 | }, 85 | { 86 | "table": "`dept_manager` `a`", 87 | "field": "dept_no", 88 | "equals": "'d001'", 89 | "null_rejecting": true 90 | }, 91 | { 92 | "table": "`dept_manager` `a`", 93 | "field": "emp_no", 94 | "equals": "`e`.`emp_no`", 95 | "null_rejecting": true 96 | }, 97 | { 98 | "table": "`departments` `d`", 99 | "field": "dept_no", 100 | "equals": "'d001'", 101 | "null_rejecting": true 102 | }, 103 | { 104 | "table": "`employees` `e`", 105 | "field": "emp_no", 106 | "equals": "`a`.`emp_no`", 107 | "null_rejecting": true 108 | } 109 | ] 110 | }, 111 | { 112 | "rows_estimation": [ 113 | { 114 | "table": "`dept_manager` `a`", 115 | "range_analysis": { 116 | "table_scan": { 117 | "rows": 24, 118 | "cost": 4.75 119 | }, 120 | "potential_range_indexes": [ 121 | { 122 | "index": "PRIMARY", 123 | "usable": false, 124 | "cause": "not_applicable" 125 | }, 126 | { 127 | "index": "dept_no", 128 | "usable": true, 129 | "key_parts": [ 130 | "dept_no", 131 | "emp_no" 132 | ] 133 | } 134 | ], 135 | "setup_range_conditions": [], 136 | "group_index_range": { 137 | "chosen": false, 138 | "cause": "not_single_table" 139 | }, 140 | "skip_scan_range": { 141 | "chosen": false, 142 | "cause": "not_single_table" 143 | }, 144 | "analyzing_range_alternatives": { 145 | "range_scan_alternatives": [ 146 | { 147 | "index": "dept_no", 148 | "ranges": [ 149 | "dept_no = 'd001'" 150 | ], 151 | "index_dives_for_eq_ranges": true, 152 | "rowid_ordered": true, 153 | "using_mrr": false, 154 | "index_only": false, 155 | "in_memory": 1, 156 | "rows": 2, 157 | "cost": 0.96, 158 | "chosen": true 159 | } 160 | ], 161 | "analyzing_roworder_intersect": { 162 | "usable": false, 163 | "cause": "too_few_roworder_scans" 164 | } 165 | }, 166 | "chosen_range_access_summary": { 167 | "range_access_plan": { 168 | "type": "range_scan", 169 | "index": "dept_no", 170 | "rows": 2, 171 | "ranges": [ 172 | "dept_no = 'd001'" 173 | ] 174 | }, 175 | "rows_for_plan": 2, 176 | "cost_for_plan": 0.96, 177 | "chosen": true 178 | } 179 | } 180 | }, 181 | { 182 | "table": "`departments` `d`", 183 | "rows": 1, 184 | "cost": 1, 185 | "table_type": "const", 186 | "empty": false 187 | }, 188 | { 189 | "table": "`employees` `e`", 190 | "table_scan": { 191 | "rows": 276023, 192 | "cost": 864.206 193 | } 194 | } 195 | ] 196 | }, 197 | { 198 | "considered_execution_plans": [ 199 | { 200 | "plan_prefix": [ 201 | "`departments` `d`" 202 | ], 203 | "table": "`dept_manager` `a`", 204 | "best_access_path": { 205 | "considered_access_paths": [ 206 | { 207 | "access_type": "ref", 208 | "index": "PRIMARY", 209 | "usable": false, 210 | "chosen": false 211 | }, 212 | { 213 | "access_type": "ref", 214 | "index": "dept_no", 215 | "rows": 2, 216 | "cost": 0.7, 217 | "chosen": true 218 | }, 219 | { 220 | "access_type": "range", 221 | "range_details": { 222 | "used_index": "dept_no" 223 | }, 224 | "chosen": false, 225 | "cause": "heuristic_index_cheaper" 226 | } 227 | ] 228 | }, 229 | "condition_filtering_pct": 100, 230 | "rows_for_plan": 2, 231 | "cost_for_plan": 0.7, 232 | "rest_of_plan": [ 233 | { 234 | "plan_prefix": [ 235 | "`departments` `d`", 236 | "`dept_manager` `a`" 237 | ], 238 | "table": "`employees` `e`", 239 | "best_access_path": { 240 | "considered_access_paths": [ 241 | { 242 | "access_type": "eq_ref", 243 | "index": "PRIMARY", 244 | "rows": 1, 245 | "cost": 2.19816, 246 | "chosen": true, 247 | "cause": "clustered_pk_chosen_by_heuristics" 248 | }, 249 | { 250 | "access_type": "scan", 251 | "cost": 28466.5, 252 | "rows": 276023, 253 | "chosen": false, 254 | "cause": "cost" 255 | } 256 | ] 257 | }, 258 | "condition_filtering_pct": 100, 259 | "rows_for_plan": 2, 260 | "cost_for_plan": 2.89816, 261 | "chosen": true 262 | } 263 | ] 264 | }, 265 | { 266 | "plan_prefix": [ 267 | "`departments` `d`" 268 | ], 269 | "table": "`employees` `e`", 270 | "best_access_path": { 271 | "considered_access_paths": [ 272 | { 273 | "access_type": "ref", 274 | "index": "PRIMARY", 275 | "usable": false, 276 | "chosen": false 277 | }, 278 | { 279 | "rows_to_scan": 276023, 280 | "filtering_effect": [], 281 | "final_filtering_effect": 1, 282 | "access_type": "scan", 283 | "resulting_rows": 276023, 284 | "cost": 28466.5, 285 | "chosen": true 286 | } 287 | ] 288 | }, 289 | "condition_filtering_pct": 100, 290 | "rows_for_plan": 276023, 291 | "cost_for_plan": 28466.5, 292 | "pruned_by_cost": true 293 | } 294 | ] 295 | }, 296 | { 297 | "attaching_conditions_to_tables": { 298 | "original_condition": "((`e`.`emp_no` = `a`.`emp_no`) and (`a`.`dept_no` = 'd001'))", 299 | "attached_conditions_computation": [], 300 | "attached_conditions_summary": [ 301 | { 302 | "table": "`dept_manager` `a`", 303 | "attached": "(`a`.`dept_no` = 'd001')" 304 | }, 305 | { 306 | "table": "`employees` `e`", 307 | "attached": "(`e`.`emp_no` = `a`.`emp_no`)" 308 | } 309 | ] 310 | } 311 | }, 312 | { 313 | "finalizing_table_conditions": [ 314 | { 315 | "table": "`dept_manager` `a`", 316 | "original_table_condition": "(`a`.`dept_no` = 'd001')", 317 | "final_table_condition ": "(`a`.`dept_no` = 'd001')" 318 | }, 319 | { 320 | "table": "`employees` `e`", 321 | "original_table_condition": "(`e`.`emp_no` = `a`.`emp_no`)", 322 | "final_table_condition ": null 323 | } 324 | ] 325 | }, 326 | { 327 | "refine_plan": [ 328 | { 329 | "table": "`dept_manager` `a`", 330 | "pushed_index_condition": "(`a`.`dept_no` = 'd001')", 331 | "table_condition_attached": null 332 | }, 333 | { 334 | "table": "`employees` `e`" 335 | } 336 | ] 337 | } 338 | ] 339 | } 340 | }, 341 | { 342 | "join_execution": { 343 | "select#": 1, 344 | "steps": [] 345 | } 346 | } 347 | ] 348 | } 349 | -------------------------------------------------------------------------------- /assets/join3_02_opt.sql: -------------------------------------------------------------------------------- 1 | use employees; 2 | 3 | set optimizer_trace="enabled=on"; 4 | 5 | select 6 | e.first_name, e.last_name, a.from_date 7 | from 8 | dept_manager a join departments d join employees e 9 | where 10 | a.dept_no = d.dept_no and a.emp_no = e.emp_no and d.dept_no = 'd001'; 11 | 12 | select trace from information_schema.optimizer_trace\G 13 | -------------------------------------------------------------------------------- /assets/join3_02_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` from ((`dept_manager` `a` join `departments` `d`) join `employees` `e`) where ((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` = `e`.`emp_no`) and (`d`.`dept_no` = 'd001'))" 9 | }, 10 | { 11 | "transformations_to_nested_joins": { 12 | "transformations": [ 13 | "parenthesis_removal" 14 | ], 15 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` from `dept_manager` `a` join `departments` `d` join `employees` `e` where ((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` = `e`.`emp_no`) and (`d`.`dept_no` = 'd001'))" 16 | } 17 | } 18 | ] 19 | } 20 | }, 21 | { 22 | "join_optimization": { 23 | "select#": 1, 24 | "steps": [ 25 | { 26 | "condition_processing": { 27 | "condition": "WHERE", 28 | "original_condition": "((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` = `e`.`emp_no`) and (`d`.`dept_no` = 'd001'))", 29 | "steps": [ 30 | { 31 | "transformation": "equality_propagation", 32 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`, `d`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 33 | }, 34 | { 35 | "transformation": "constant_propagation", 36 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`, `d`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 37 | }, 38 | { 39 | "transformation": "trivial_condition_removal", 40 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`, `d`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 41 | } 42 | ] 43 | } 44 | }, 45 | { 46 | "substitute_generated_columns": {} 47 | }, 48 | { 49 | "table_dependencies": [ 50 | { 51 | "table": "`dept_manager` `a`", 52 | "row_may_be_null": false, 53 | "map_bit": 0, 54 | "depends_on_map_bits": [] 55 | }, 56 | { 57 | "table": "`departments` `d`", 58 | "row_may_be_null": false, 59 | "map_bit": 1, 60 | "depends_on_map_bits": [] 61 | }, 62 | { 63 | "table": "`employees` `e`", 64 | "row_may_be_null": false, 65 | "map_bit": 2, 66 | "depends_on_map_bits": [] 67 | } 68 | ] 69 | }, 70 | { 71 | "ref_optimizer_key_uses": [ 72 | { 73 | "table": "`dept_manager` `a`", 74 | "field": "emp_no", 75 | "equals": "`e`.`emp_no`", 76 | "null_rejecting": true 77 | }, 78 | { 79 | "table": "`dept_manager` `a`", 80 | "field": "dept_no", 81 | "equals": "'d001'", 82 | "null_rejecting": true 83 | }, 84 | { 85 | "table": "`dept_manager` `a`", 86 | "field": "dept_no", 87 | "equals": "'d001'", 88 | "null_rejecting": true 89 | }, 90 | { 91 | "table": "`dept_manager` `a`", 92 | "field": "emp_no", 93 | "equals": "`e`.`emp_no`", 94 | "null_rejecting": true 95 | }, 96 | { 97 | "table": "`departments` `d`", 98 | "field": "dept_no", 99 | "equals": "'d001'", 100 | "null_rejecting": true 101 | }, 102 | { 103 | "table": "`employees` `e`", 104 | "field": "emp_no", 105 | "equals": "`a`.`emp_no`", 106 | "null_rejecting": true 107 | } 108 | ] 109 | }, 110 | { 111 | "rows_estimation": [ 112 | { 113 | "table": "`dept_manager` `a`", 114 | "range_analysis": { 115 | "table_scan": { 116 | "rows": 24, 117 | "cost": 4.75 118 | }, 119 | "potential_range_indexes": [ 120 | { 121 | "index": "PRIMARY", 122 | "usable": false, 123 | "cause": "not_applicable" 124 | }, 125 | { 126 | "index": "dept_no", 127 | "usable": true, 128 | "key_parts": [ 129 | "dept_no", 130 | "emp_no" 131 | ] 132 | } 133 | ], 134 | "setup_range_conditions": [], 135 | "group_index_range": { 136 | "chosen": false, 137 | "cause": "not_single_table" 138 | }, 139 | "skip_scan_range": { 140 | "chosen": false, 141 | "cause": "not_single_table" 142 | }, 143 | "analyzing_range_alternatives": { 144 | "range_scan_alternatives": [ 145 | { 146 | "index": "dept_no", 147 | "ranges": [ 148 | "dept_no = 'd001'" 149 | ], 150 | "index_dives_for_eq_ranges": true, 151 | "rowid_ordered": true, 152 | "using_mrr": false, 153 | "index_only": false, 154 | "in_memory": 1, 155 | "rows": 2, 156 | "cost": 0.96, 157 | "chosen": true 158 | } 159 | ], 160 | "analyzing_roworder_intersect": { 161 | "usable": false, 162 | "cause": "too_few_roworder_scans" 163 | } 164 | }, 165 | "chosen_range_access_summary": { 166 | "range_access_plan": { 167 | "type": "range_scan", 168 | "index": "dept_no", 169 | "rows": 2, 170 | "ranges": [ 171 | "dept_no = 'd001'" 172 | ] 173 | }, 174 | "rows_for_plan": 2, 175 | "cost_for_plan": 0.96, 176 | "chosen": true 177 | } 178 | } 179 | }, 180 | { 181 | "table": "`departments` `d`", 182 | "rows": 1, 183 | "cost": 1, 184 | "table_type": "const", 185 | "empty": false 186 | }, 187 | { 188 | "table": "`employees` `e`", 189 | "table_scan": { 190 | "rows": 276023, 191 | "cost": 864.206 192 | } 193 | } 194 | ] 195 | }, 196 | { 197 | "considered_execution_plans": [ 198 | { 199 | "plan_prefix": [ 200 | "`departments` `d`" 201 | ], 202 | "table": "`dept_manager` `a`", 203 | "best_access_path": { 204 | "considered_access_paths": [ 205 | { 206 | "access_type": "ref", 207 | "index": "PRIMARY", 208 | "usable": false, 209 | "chosen": false 210 | }, 211 | { 212 | "access_type": "ref", 213 | "index": "dept_no", 214 | "rows": 2, 215 | "cost": 0.7, 216 | "chosen": true 217 | }, 218 | { 219 | "access_type": "range", 220 | "range_details": { 221 | "used_index": "dept_no" 222 | }, 223 | "chosen": false, 224 | "cause": "heuristic_index_cheaper" 225 | } 226 | ] 227 | }, 228 | "condition_filtering_pct": 100, 229 | "rows_for_plan": 2, 230 | "cost_for_plan": 0.7, 231 | "rest_of_plan": [ 232 | { 233 | "plan_prefix": [ 234 | "`departments` `d`", 235 | "`dept_manager` `a`" 236 | ], 237 | "table": "`employees` `e`", 238 | "best_access_path": { 239 | "considered_access_paths": [ 240 | { 241 | "access_type": "eq_ref", 242 | "index": "PRIMARY", 243 | "rows": 1, 244 | "cost": 2.19816, 245 | "chosen": true, 246 | "cause": "clustered_pk_chosen_by_heuristics" 247 | }, 248 | { 249 | "access_type": "scan", 250 | "cost": 28466.5, 251 | "rows": 276023, 252 | "chosen": false, 253 | "cause": "cost" 254 | } 255 | ] 256 | }, 257 | "condition_filtering_pct": 100, 258 | "rows_for_plan": 2, 259 | "cost_for_plan": 2.89816, 260 | "chosen": true 261 | } 262 | ] 263 | }, 264 | { 265 | "plan_prefix": [ 266 | "`departments` `d`" 267 | ], 268 | "table": "`employees` `e`", 269 | "best_access_path": { 270 | "considered_access_paths": [ 271 | { 272 | "access_type": "ref", 273 | "index": "PRIMARY", 274 | "usable": false, 275 | "chosen": false 276 | }, 277 | { 278 | "rows_to_scan": 276023, 279 | "filtering_effect": [], 280 | "final_filtering_effect": 1, 281 | "access_type": "scan", 282 | "resulting_rows": 276023, 283 | "cost": 28466.5, 284 | "chosen": true 285 | } 286 | ] 287 | }, 288 | "condition_filtering_pct": 100, 289 | "rows_for_plan": 276023, 290 | "cost_for_plan": 28466.5, 291 | "pruned_by_cost": true 292 | } 293 | ] 294 | }, 295 | { 296 | "attaching_conditions_to_tables": { 297 | "original_condition": "((`e`.`emp_no` = `a`.`emp_no`) and (`a`.`dept_no` = 'd001'))", 298 | "attached_conditions_computation": [], 299 | "attached_conditions_summary": [ 300 | { 301 | "table": "`dept_manager` `a`", 302 | "attached": "(`a`.`dept_no` = 'd001')" 303 | }, 304 | { 305 | "table": "`employees` `e`", 306 | "attached": "(`e`.`emp_no` = `a`.`emp_no`)" 307 | } 308 | ] 309 | } 310 | }, 311 | { 312 | "finalizing_table_conditions": [ 313 | { 314 | "table": "`dept_manager` `a`", 315 | "original_table_condition": "(`a`.`dept_no` = 'd001')", 316 | "final_table_condition ": "(`a`.`dept_no` = 'd001')" 317 | }, 318 | { 319 | "table": "`employees` `e`", 320 | "original_table_condition": "(`e`.`emp_no` = `a`.`emp_no`)", 321 | "final_table_condition ": null 322 | } 323 | ] 324 | }, 325 | { 326 | "refine_plan": [ 327 | { 328 | "table": "`dept_manager` `a`", 329 | "pushed_index_condition": "(`a`.`dept_no` = 'd001')", 330 | "table_condition_attached": null 331 | }, 332 | { 333 | "table": "`employees` `e`" 334 | } 335 | ] 336 | } 337 | ] 338 | } 339 | }, 340 | { 341 | "join_execution": { 342 | "select#": 1, 343 | "steps": [] 344 | } 345 | } 346 | ] 347 | } 348 | -------------------------------------------------------------------------------- /assets/join3_03_opt.sql: -------------------------------------------------------------------------------- 1 | use employees; 2 | 3 | set optimizer_trace="enabled=on"; 4 | 5 | select 6 | e.first_name, e.last_name, a.from_date 7 | from 8 | dept_manager a, departments d, employees e 9 | where 10 | a.dept_no = d.dept_no and a.emp_no = e.emp_no and d.dept_no = 'd001'; 11 | 12 | select trace from information_schema.optimizer_trace\G 13 | -------------------------------------------------------------------------------- /assets/join3_03_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name`,`a`.`from_date` AS `from_date` from `dept_manager` `a` join `departments` `d` join `employees` `e` where ((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` = `e`.`emp_no`) and (`d`.`dept_no` = 'd001'))" 9 | } 10 | ] 11 | } 12 | }, 13 | { 14 | "join_optimization": { 15 | "select#": 1, 16 | "steps": [ 17 | { 18 | "condition_processing": { 19 | "condition": "WHERE", 20 | "original_condition": "((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`emp_no` = `e`.`emp_no`) and (`d`.`dept_no` = 'd001'))", 21 | "steps": [ 22 | { 23 | "transformation": "equality_propagation", 24 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`, `d`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 25 | }, 26 | { 27 | "transformation": "constant_propagation", 28 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`, `d`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 29 | }, 30 | { 31 | "transformation": "trivial_condition_removal", 32 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`, `d`.`dept_no`) and multiple equal(`a`.`emp_no`, `e`.`emp_no`))" 33 | } 34 | ] 35 | } 36 | }, 37 | { 38 | "substitute_generated_columns": {} 39 | }, 40 | { 41 | "table_dependencies": [ 42 | { 43 | "table": "`dept_manager` `a`", 44 | "row_may_be_null": false, 45 | "map_bit": 0, 46 | "depends_on_map_bits": [] 47 | }, 48 | { 49 | "table": "`departments` `d`", 50 | "row_may_be_null": false, 51 | "map_bit": 1, 52 | "depends_on_map_bits": [] 53 | }, 54 | { 55 | "table": "`employees` `e`", 56 | "row_may_be_null": false, 57 | "map_bit": 2, 58 | "depends_on_map_bits": [] 59 | } 60 | ] 61 | }, 62 | { 63 | "ref_optimizer_key_uses": [ 64 | { 65 | "table": "`dept_manager` `a`", 66 | "field": "emp_no", 67 | "equals": "`e`.`emp_no`", 68 | "null_rejecting": true 69 | }, 70 | { 71 | "table": "`dept_manager` `a`", 72 | "field": "dept_no", 73 | "equals": "'d001'", 74 | "null_rejecting": true 75 | }, 76 | { 77 | "table": "`dept_manager` `a`", 78 | "field": "dept_no", 79 | "equals": "'d001'", 80 | "null_rejecting": true 81 | }, 82 | { 83 | "table": "`dept_manager` `a`", 84 | "field": "emp_no", 85 | "equals": "`e`.`emp_no`", 86 | "null_rejecting": true 87 | }, 88 | { 89 | "table": "`departments` `d`", 90 | "field": "dept_no", 91 | "equals": "'d001'", 92 | "null_rejecting": true 93 | }, 94 | { 95 | "table": "`employees` `e`", 96 | "field": "emp_no", 97 | "equals": "`a`.`emp_no`", 98 | "null_rejecting": true 99 | } 100 | ] 101 | }, 102 | { 103 | "rows_estimation": [ 104 | { 105 | "table": "`dept_manager` `a`", 106 | "range_analysis": { 107 | "table_scan": { 108 | "rows": 24, 109 | "cost": 4.75 110 | }, 111 | "potential_range_indexes": [ 112 | { 113 | "index": "PRIMARY", 114 | "usable": false, 115 | "cause": "not_applicable" 116 | }, 117 | { 118 | "index": "dept_no", 119 | "usable": true, 120 | "key_parts": [ 121 | "dept_no", 122 | "emp_no" 123 | ] 124 | } 125 | ], 126 | "setup_range_conditions": [], 127 | "group_index_range": { 128 | "chosen": false, 129 | "cause": "not_single_table" 130 | }, 131 | "skip_scan_range": { 132 | "chosen": false, 133 | "cause": "not_single_table" 134 | }, 135 | "analyzing_range_alternatives": { 136 | "range_scan_alternatives": [ 137 | { 138 | "index": "dept_no", 139 | "ranges": [ 140 | "dept_no = 'd001'" 141 | ], 142 | "index_dives_for_eq_ranges": true, 143 | "rowid_ordered": true, 144 | "using_mrr": false, 145 | "index_only": false, 146 | "in_memory": 1, 147 | "rows": 2, 148 | "cost": 0.96, 149 | "chosen": true 150 | } 151 | ], 152 | "analyzing_roworder_intersect": { 153 | "usable": false, 154 | "cause": "too_few_roworder_scans" 155 | } 156 | }, 157 | "chosen_range_access_summary": { 158 | "range_access_plan": { 159 | "type": "range_scan", 160 | "index": "dept_no", 161 | "rows": 2, 162 | "ranges": [ 163 | "dept_no = 'd001'" 164 | ] 165 | }, 166 | "rows_for_plan": 2, 167 | "cost_for_plan": 0.96, 168 | "chosen": true 169 | } 170 | } 171 | }, 172 | { 173 | "table": "`departments` `d`", 174 | "rows": 1, 175 | "cost": 1, 176 | "table_type": "const", 177 | "empty": false 178 | }, 179 | { 180 | "table": "`employees` `e`", 181 | "table_scan": { 182 | "rows": 276023, 183 | "cost": 864.206 184 | } 185 | } 186 | ] 187 | }, 188 | { 189 | "considered_execution_plans": [ 190 | { 191 | "plan_prefix": [ 192 | "`departments` `d`" 193 | ], 194 | "table": "`dept_manager` `a`", 195 | "best_access_path": { 196 | "considered_access_paths": [ 197 | { 198 | "access_type": "ref", 199 | "index": "PRIMARY", 200 | "usable": false, 201 | "chosen": false 202 | }, 203 | { 204 | "access_type": "ref", 205 | "index": "dept_no", 206 | "rows": 2, 207 | "cost": 0.7, 208 | "chosen": true 209 | }, 210 | { 211 | "access_type": "range", 212 | "range_details": { 213 | "used_index": "dept_no" 214 | }, 215 | "chosen": false, 216 | "cause": "heuristic_index_cheaper" 217 | } 218 | ] 219 | }, 220 | "condition_filtering_pct": 100, 221 | "rows_for_plan": 2, 222 | "cost_for_plan": 0.7, 223 | "rest_of_plan": [ 224 | { 225 | "plan_prefix": [ 226 | "`departments` `d`", 227 | "`dept_manager` `a`" 228 | ], 229 | "table": "`employees` `e`", 230 | "best_access_path": { 231 | "considered_access_paths": [ 232 | { 233 | "access_type": "eq_ref", 234 | "index": "PRIMARY", 235 | "rows": 1, 236 | "cost": 2.19816, 237 | "chosen": true, 238 | "cause": "clustered_pk_chosen_by_heuristics" 239 | }, 240 | { 241 | "access_type": "scan", 242 | "cost": 28466.5, 243 | "rows": 276023, 244 | "chosen": false, 245 | "cause": "cost" 246 | } 247 | ] 248 | }, 249 | "condition_filtering_pct": 100, 250 | "rows_for_plan": 2, 251 | "cost_for_plan": 2.89816, 252 | "chosen": true 253 | } 254 | ] 255 | }, 256 | { 257 | "plan_prefix": [ 258 | "`departments` `d`" 259 | ], 260 | "table": "`employees` `e`", 261 | "best_access_path": { 262 | "considered_access_paths": [ 263 | { 264 | "access_type": "ref", 265 | "index": "PRIMARY", 266 | "usable": false, 267 | "chosen": false 268 | }, 269 | { 270 | "rows_to_scan": 276023, 271 | "filtering_effect": [], 272 | "final_filtering_effect": 1, 273 | "access_type": "scan", 274 | "resulting_rows": 276023, 275 | "cost": 28466.5, 276 | "chosen": true 277 | } 278 | ] 279 | }, 280 | "condition_filtering_pct": 100, 281 | "rows_for_plan": 276023, 282 | "cost_for_plan": 28466.5, 283 | "pruned_by_cost": true 284 | } 285 | ] 286 | }, 287 | { 288 | "attaching_conditions_to_tables": { 289 | "original_condition": "((`e`.`emp_no` = `a`.`emp_no`) and (`a`.`dept_no` = 'd001'))", 290 | "attached_conditions_computation": [], 291 | "attached_conditions_summary": [ 292 | { 293 | "table": "`dept_manager` `a`", 294 | "attached": "(`a`.`dept_no` = 'd001')" 295 | }, 296 | { 297 | "table": "`employees` `e`", 298 | "attached": "(`e`.`emp_no` = `a`.`emp_no`)" 299 | } 300 | ] 301 | } 302 | }, 303 | { 304 | "finalizing_table_conditions": [ 305 | { 306 | "table": "`dept_manager` `a`", 307 | "original_table_condition": "(`a`.`dept_no` = 'd001')", 308 | "final_table_condition ": "(`a`.`dept_no` = 'd001')" 309 | }, 310 | { 311 | "table": "`employees` `e`", 312 | "original_table_condition": "(`e`.`emp_no` = `a`.`emp_no`)", 313 | "final_table_condition ": null 314 | } 315 | ] 316 | }, 317 | { 318 | "refine_plan": [ 319 | { 320 | "table": "`dept_manager` `a`", 321 | "pushed_index_condition": "(`a`.`dept_no` = 'd001')", 322 | "table_condition_attached": null 323 | }, 324 | { 325 | "table": "`employees` `e`" 326 | } 327 | ] 328 | } 329 | ] 330 | } 331 | }, 332 | { 333 | "join_execution": { 334 | "select#": 1, 335 | "steps": [] 336 | } 337 | } 338 | ] 339 | } 340 | -------------------------------------------------------------------------------- /assets/p12-opttrace-01.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "expanded_query": "/* select#1 */ select `employees`.`emp_no` AS `emp_no`,`employees`.`birth_date` AS `birth_date`,`employees`.`first_name` AS `first_name`,`employees`.`last_name` AS `last_name`,`employees`.`gender` AS `gender`,`employees`.`hire_date` AS `hire_date` from `employees` where ((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))" 9 | } 10 | ] 11 | } 12 | }, 13 | { 14 | "join_optimization": { 15 | "select#": 1, 16 | "steps": [ 17 | { 18 | "condition_processing": { 19 | "condition": "WHERE", 20 | "original_condition": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))", 21 | "steps": [ 22 | { 23 | "transformation": "equality_propagation", 24 | "resulting_condition": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))" 25 | }, 26 | { 27 | "transformation": "constant_propagation", 28 | "resulting_condition": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))" 29 | }, 30 | { 31 | "transformation": "trivial_condition_removal", 32 | "resulting_condition": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))" 33 | } 34 | ] 35 | } 36 | }, 37 | { 38 | "substitute_generated_columns": { 39 | } 40 | }, 41 | { 42 | "table_dependencies": [ 43 | { 44 | "table": "`employees`", 45 | "row_may_be_null": false, 46 | "map_bit": 0, 47 | "depends_on_map_bits": [ 48 | ] 49 | } 50 | ] 51 | }, 52 | { 53 | "ref_optimizer_key_uses": [ 54 | ] 55 | }, 56 | { 57 | "rows_estimation": [ 58 | { 59 | "table": "`employees`", 60 | "range_analysis": { 61 | "table_scan": { 62 | "rows": 299556, 63 | "cost": 30878.8 64 | }, 65 | "potential_range_indexes": [ 66 | { 67 | "index": "PRIMARY", 68 | "usable": true, 69 | "key_parts": [ 70 | "emp_no" 71 | ] 72 | } 73 | ], 74 | "setup_range_conditions": [ 75 | ], 76 | "group_index_range": { 77 | "chosen": false, 78 | "cause": "not_group_by_or_distinct" 79 | }, 80 | "skip_scan_range": { 81 | "potential_skip_scan_indexes": [ 82 | { 83 | "index": "PRIMARY", 84 | "usable": false, 85 | "cause": "query_references_nonkey_column" 86 | } 87 | ] 88 | }, 89 | "analyzing_range_alternatives": { 90 | "range_scan_alternatives": [ 91 | { 92 | "index": "PRIMARY", 93 | "ranges": [ 94 | "emp_no < 10010" 95 | ], 96 | "index_dives_for_eq_ranges": true, 97 | "rowid_ordered": true, 98 | "using_mrr": false, 99 | "index_only": false, 100 | "in_memory": 0.0112867, 101 | "rows": 9, 102 | "cost": 1.91039, 103 | "chosen": true 104 | } 105 | ], 106 | "analyzing_roworder_intersect": { 107 | "usable": false, 108 | "cause": "too_few_roworder_scans" 109 | } 110 | }, 111 | "chosen_range_access_summary": { 112 | "range_access_plan": { 113 | "type": "range_scan", 114 | "index": "PRIMARY", 115 | "rows": 9, 116 | "ranges": [ 117 | "emp_no < 10010" 118 | ] 119 | }, 120 | "rows_for_plan": 9, 121 | "cost_for_plan": 1.91039, 122 | "chosen": true 123 | } 124 | } 125 | } 126 | ] 127 | }, 128 | { 129 | "considered_execution_plans": [ 130 | { 131 | "plan_prefix": [ 132 | ], 133 | "table": "`employees`", 134 | "best_access_path": { 135 | "considered_access_paths": [ 136 | { 137 | "rows_to_scan": 9, 138 | "access_type": "range", 139 | "range_details": { 140 | "used_index": "PRIMARY" 141 | }, 142 | "resulting_rows": 9, 143 | "cost": 2.81039, 144 | "chosen": true 145 | } 146 | ] 147 | }, 148 | "condition_filtering_pct": 100, 149 | "rows_for_plan": 9, 150 | "cost_for_plan": 2.81039, 151 | "chosen": true 152 | } 153 | ] 154 | }, 155 | { 156 | "attaching_conditions_to_tables": { 157 | "original_condition": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))", 158 | "attached_conditions_computation": [ 159 | ], 160 | "attached_conditions_summary": [ 161 | { 162 | "table": "`employees`", 163 | "attached": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))" 164 | } 165 | ] 166 | } 167 | }, 168 | { 169 | "finalizing_table_conditions": [ 170 | { 171 | "table": "`employees`", 172 | "original_table_condition": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))", 173 | "final_table_condition ": "((`employees`.`emp_no` < 10010) and (`employees`.`first_name` like 'a%'))" 174 | } 175 | ] 176 | }, 177 | { 178 | "refine_plan": [ 179 | { 180 | "table": "`employees`" 181 | } 182 | ] 183 | } 184 | ] 185 | } 186 | }, 187 | { 188 | "join_execution": { 189 | "select#": 1, 190 | "steps": [ 191 | ] 192 | } 193 | } 194 | ] 195 | } 196 | -------------------------------------------------------------------------------- /assets/rewrite-insert-rule.sql: -------------------------------------------------------------------------------- 1 | -- 插入规则 2 | INSERT INTO query_rewrite.rewrite_rules 3 | (pattern_database, pattern, replacement) 4 | VALUES ( 5 | "employees", 6 | "SELECT * FROM employees WHERE emp_no > ? ", 7 | "SELECT * FROM employees WHERE emp_no > ? LIMIT 1" 8 | ); 9 | -- 应用规则 10 | CALL query_rewrite.flush_rewrite_rules(); 11 | -------------------------------------------------------------------------------- /assets/sdi-rtc-tt.json: -------------------------------------------------------------------------------- 1 | [ 2 | "ibd2sdi", 3 | { 4 | "type": 1, 5 | "id": 539, 6 | "object": { 7 | "mysqld_version_id": 80037, 8 | "dd_version": 80023, 9 | "sdi_version": 80019, 10 | "dd_object_type": "Table", 11 | "dd_object": { 12 | "name": "t", 13 | "mysql_version_id": 80037, 14 | "created": 20240804040720, 15 | "last_altered": 20240804040720, 16 | "hidden": 1, 17 | "options": "avg_row_length=0;encrypt_type=N;key_block_size=0;keys_disabled=0;pack_record=0;stats_auto_recalc=0;stats_sample_pages=0;", 18 | "columns": [ 19 | { 20 | "name": "k", 21 | "type": 4, 22 | "is_nullable": false, 23 | "is_zerofill": false, 24 | "is_unsigned": false, 25 | "is_auto_increment": false, 26 | "is_virtual": false, 27 | "hidden": 1, 28 | "ordinal_position": 1, 29 | "char_length": 11, 30 | "numeric_precision": 10, 31 | "numeric_scale": 0, 32 | "numeric_scale_null": false, 33 | "datetime_precision": 0, 34 | "datetime_precision_null": 1, 35 | "has_no_default": true, 36 | "default_value_null": false, 37 | "srs_id_null": true, 38 | "srs_id": 0, 39 | "default_value": "AAAAAA==", 40 | "default_value_utf8_null": true, 41 | "default_value_utf8": "", 42 | "default_option": "", 43 | "update_option": "", 44 | "comment": "", 45 | "generation_expression": "", 46 | "generation_expression_utf8": "", 47 | "options": "interval_count=0;", 48 | "se_private_data": "table_id=1127;", 49 | "engine_attribute": "", 50 | "secondary_engine_attribute": "", 51 | "column_key": 2, 52 | "column_type_utf8": "int", 53 | "elements": [], 54 | "collation_id": 255, 55 | "is_explicit_collation": false 56 | }, 57 | { 58 | "name": "v", 59 | "type": 29, 60 | "is_nullable": true, 61 | "is_zerofill": false, 62 | "is_unsigned": false, 63 | "is_auto_increment": false, 64 | "is_virtual": false, 65 | "hidden": 1, 66 | "ordinal_position": 2, 67 | "char_length": 16, 68 | "numeric_precision": 0, 69 | "numeric_scale": 0, 70 | "numeric_scale_null": true, 71 | "datetime_precision": 0, 72 | "datetime_precision_null": 1, 73 | "has_no_default": false, 74 | "default_value_null": true, 75 | "srs_id_null": true, 76 | "srs_id": 0, 77 | "default_value": "", 78 | "default_value_utf8_null": true, 79 | "default_value_utf8": "", 80 | "default_option": "", 81 | "update_option": "", 82 | "comment": "", 83 | "generation_expression": "", 84 | "generation_expression_utf8": "", 85 | "options": "interval_count=0;", 86 | "se_private_data": "table_id=1127;", 87 | "engine_attribute": "", 88 | "secondary_engine_attribute": "", 89 | "column_key": 1, 90 | "column_type_utf8": "char(4)", 91 | "elements": [], 92 | "collation_id": 255, 93 | "is_explicit_collation": false 94 | }, 95 | { 96 | "name": "DB_TRX_ID", 97 | "type": 10, 98 | "is_nullable": false, 99 | "is_zerofill": false, 100 | "is_unsigned": false, 101 | "is_auto_increment": false, 102 | "is_virtual": false, 103 | "hidden": 2, 104 | "ordinal_position": 3, 105 | "char_length": 6, 106 | "numeric_precision": 0, 107 | "numeric_scale": 0, 108 | "numeric_scale_null": true, 109 | "datetime_precision": 0, 110 | "datetime_precision_null": 1, 111 | "has_no_default": false, 112 | "default_value_null": true, 113 | "srs_id_null": true, 114 | "srs_id": 0, 115 | "default_value": "", 116 | "default_value_utf8_null": true, 117 | "default_value_utf8": "", 118 | "default_option": "", 119 | "update_option": "", 120 | "comment": "", 121 | "generation_expression": "", 122 | "generation_expression_utf8": "", 123 | "options": "", 124 | "se_private_data": "table_id=1127;", 125 | "engine_attribute": "", 126 | "secondary_engine_attribute": "", 127 | "column_key": 1, 128 | "column_type_utf8": "", 129 | "elements": [], 130 | "collation_id": 63, 131 | "is_explicit_collation": false 132 | }, 133 | { 134 | "name": "DB_ROLL_PTR", 135 | "type": 9, 136 | "is_nullable": false, 137 | "is_zerofill": false, 138 | "is_unsigned": false, 139 | "is_auto_increment": false, 140 | "is_virtual": false, 141 | "hidden": 2, 142 | "ordinal_position": 4, 143 | "char_length": 7, 144 | "numeric_precision": 0, 145 | "numeric_scale": 0, 146 | "numeric_scale_null": true, 147 | "datetime_precision": 0, 148 | "datetime_precision_null": 1, 149 | "has_no_default": false, 150 | "default_value_null": true, 151 | "srs_id_null": true, 152 | "srs_id": 0, 153 | "default_value": "", 154 | "default_value_utf8_null": true, 155 | "default_value_utf8": "", 156 | "default_option": "", 157 | "update_option": "", 158 | "comment": "", 159 | "generation_expression": "", 160 | "generation_expression_utf8": "", 161 | "options": "", 162 | "se_private_data": "table_id=1127;", 163 | "engine_attribute": "", 164 | "secondary_engine_attribute": "", 165 | "column_key": 1, 166 | "column_type_utf8": "", 167 | "elements": [], 168 | "collation_id": 63, 169 | "is_explicit_collation": false 170 | } 171 | ], 172 | "schema_ref": "rtc", 173 | "se_private_id": 1127, 174 | "engine": "InnoDB", 175 | "last_checked_for_upgrade_version_id": 0, 176 | "comment": "", 177 | "se_private_data": "", 178 | "engine_attribute": "", 179 | "secondary_engine_attribute": "", 180 | "row_format": 2, 181 | "partition_type": 0, 182 | "partition_expression": "", 183 | "partition_expression_utf8": "", 184 | "default_partitioning": 0, 185 | "subpartition_type": 0, 186 | "subpartition_expression": "", 187 | "subpartition_expression_utf8": "", 188 | "default_subpartitioning": 0, 189 | "indexes": [ 190 | { 191 | "name": "PRIMARY", 192 | "hidden": false, 193 | "is_generated": false, 194 | "ordinal_position": 1, 195 | "comment": "", 196 | "options": "flags=0;", 197 | "se_private_data": "id=246;root=4;space_id=65;table_id=1127;trx_id=61525;", 198 | "type": 1, 199 | "algorithm": 2, 200 | "is_algorithm_explicit": false, 201 | "is_visible": true, 202 | "engine": "InnoDB", 203 | "engine_attribute": "", 204 | "secondary_engine_attribute": "", 205 | "elements": [ 206 | { 207 | "ordinal_position": 1, 208 | "length": 4, 209 | "order": 2, 210 | "hidden": false, 211 | "column_opx": 0 212 | }, 213 | { 214 | "ordinal_position": 2, 215 | "length": 4294967295, 216 | "order": 2, 217 | "hidden": true, 218 | "column_opx": 2 219 | }, 220 | { 221 | "ordinal_position": 3, 222 | "length": 4294967295, 223 | "order": 2, 224 | "hidden": true, 225 | "column_opx": 3 226 | }, 227 | { 228 | "ordinal_position": 4, 229 | "length": 4294967295, 230 | "order": 2, 231 | "hidden": true, 232 | "column_opx": 1 233 | } 234 | ], 235 | "tablespace_ref": "rtc/t" 236 | } 237 | ], 238 | "foreign_keys": [], 239 | "check_constraints": [], 240 | "partitions": [], 241 | "collation_id": 255 242 | } 243 | } 244 | }, 245 | { 246 | "type": 2, 247 | "id": 70, 248 | "object": { 249 | "mysqld_version_id": 80037, 250 | "dd_version": 80023, 251 | "sdi_version": 80019, 252 | "dd_object_type": "Tablespace", 253 | "dd_object": { 254 | "name": "rtc/t", 255 | "comment": "", 256 | "options": "autoextend_size=0;encryption=N;", 257 | "se_private_data": "flags=16417;id=65;server_version=80037;space_version=1;state=normal;", 258 | "engine": "InnoDB", 259 | "engine_attribute": "", 260 | "files": [ 261 | { 262 | "ordinal_position": 1, 263 | "filename": "./rtc/t.ibd", 264 | "se_private_data": "id=65;" 265 | } 266 | ] 267 | } 268 | } 269 | } 270 | ] 271 | -------------------------------------------------------------------------------- /assets/subq01_scalar_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "6.69" 6 | }, 7 | "table": { 8 | "table_name": "a", 9 | "access_type": "range", 10 | "possible_keys": [ 11 | "PRIMARY", 12 | "dept_no" 13 | ], 14 | "key": "dept_no", 15 | "used_key_parts": [ 16 | "dept_no", 17 | "emp_no" 18 | ], 19 | "key_length": "20", 20 | "rows_examined_per_scan": 32, 21 | "rows_produced_per_join": 32, 22 | "filtered": "100.00", 23 | "using_index": true, 24 | "cost_info": { 25 | "read_cost": "3.49", 26 | "eval_cost": "3.20", 27 | "prefix_cost": "6.69", 28 | "data_read_per_join": "1024" 29 | }, 30 | "used_columns": [ 31 | "emp_no", 32 | "dept_no" 33 | ], 34 | "attached_condition": "((`employees`.`a`.`dept_no` = (/* select#2 */ select 'd005' from `employees`.`departments` `d` where true)) and (`employees`.`a`.`emp_no` < 10100))", 35 | "attached_subqueries": [ 36 | { 37 | "dependent": false, 38 | "cacheable": true, 39 | "query_block": { 40 | "select_id": 2, 41 | "cost_info": { 42 | "query_cost": "1.00" 43 | }, 44 | "table": { 45 | "table_name": "d", 46 | "access_type": "const", 47 | "possible_keys": [ 48 | "dept_name" 49 | ], 50 | "key": "dept_name", 51 | "used_key_parts": [ 52 | "dept_name" 53 | ], 54 | "key_length": "162", 55 | "ref": [ 56 | "const" 57 | ], 58 | "rows_examined_per_scan": 1, 59 | "rows_produced_per_join": 1, 60 | "filtered": "100.00", 61 | "using_index": true, 62 | "cost_info": { 63 | "read_cost": "0.00", 64 | "eval_cost": "0.10", 65 | "prefix_cost": "0.00", 66 | "data_read_per_join": "184" 67 | }, 68 | "used_columns": [ 69 | "dept_no", 70 | "dept_name" 71 | ] 72 | } 73 | } 74 | } 75 | ] 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /assets/subq02_unique_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "2.65" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "a", 11 | "access_type": "ref", 12 | "possible_keys": [ 13 | "PRIMARY", 14 | "dept_no" 15 | ], 16 | "key": "dept_no", 17 | "used_key_parts": [ 18 | "dept_no" 19 | ], 20 | "key_length": "16", 21 | "ref": [ 22 | "const" 23 | ], 24 | "rows_examined_per_scan": 2, 25 | "rows_produced_per_join": 2, 26 | "filtered": "100.00", 27 | "using_index": true, 28 | "cost_info": { 29 | "read_cost": "0.25", 30 | "eval_cost": "0.20", 31 | "prefix_cost": "0.45", 32 | "data_read_per_join": "64" 33 | }, 34 | "used_columns": [ 35 | "emp_no", 36 | "dept_no" 37 | ], 38 | "attached_condition": "(`employees`.`a`.`dept_no` = 'd001')" 39 | } 40 | }, 41 | { 42 | "table": { 43 | "table_name": "e", 44 | "access_type": "eq_ref", 45 | "possible_keys": [ 46 | "PRIMARY" 47 | ], 48 | "key": "PRIMARY", 49 | "used_key_parts": [ 50 | "emp_no" 51 | ], 52 | "key_length": "4", 53 | "ref": [ 54 | "employees.a.emp_no" 55 | ], 56 | "rows_examined_per_scan": 1, 57 | "rows_produced_per_join": 2, 58 | "filtered": "100.00", 59 | "cost_info": { 60 | "read_cost": "2.00", 61 | "eval_cost": "0.20", 62 | "prefix_cost": "2.65", 63 | "data_read_per_join": "272" 64 | }, 65 | "used_columns": [ 66 | "emp_no", 67 | "first_name", 68 | "last_name" 69 | ] 70 | } 71 | } 72 | ] 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /assets/subq02_unique_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "join_preparation": { 9 | "select#": 2, 10 | "steps": [ 11 | { 12 | "expanded_query": "/* select#2 */ select `a`.`emp_no` from `dept_manager` `a` where (`a`.`dept_no` = 'd001')" 13 | } 14 | ] 15 | } 16 | }, 17 | { 18 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name` from `employees` `e` where `e`.`emp_no` in (/* select#2 */ select `a`.`emp_no` from `dept_manager` `a` where (`a`.`dept_no` = 'd001'))" 19 | }, 20 | { 21 | "transformation": { 22 | "select#": 2, 23 | "from": "IN (SELECT)", 24 | "to": "semijoin", 25 | "chosen": true, 26 | "transformation_to_semi_join": { 27 | "subquery_predicate": "`e`.`emp_no` in (/* select#2 */ select `a`.`emp_no` from `dept_manager` `a` where (`a`.`dept_no` = 'd001'))", 28 | "embedded in": "WHERE", 29 | "evaluating_constant_semijoin_conditions": [], 30 | "semi-join condition": "((`a`.`dept_no` = 'd001') and (`e`.`emp_no` = `a`.`emp_no`))", 31 | "decorrelated_predicates": [ 32 | { 33 | "outer": "`e`.`emp_no`", 34 | "inner": "`a`.`emp_no`" 35 | } 36 | ] 37 | } 38 | } 39 | }, 40 | { 41 | "transformations_to_nested_joins": { 42 | "transformations": [ 43 | "semijoin" 44 | ], 45 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name` from `employees` `e` semi join (`dept_manager` `a`) where ((`a`.`dept_no` = 'd001') and (`e`.`emp_no` = `a`.`emp_no`))" 46 | } 47 | } 48 | ] 49 | } 50 | }, 51 | { 52 | "join_optimization": { 53 | "select#": 1, 54 | "steps": [ 55 | { 56 | "condition_processing": { 57 | "condition": "WHERE", 58 | "original_condition": "((`a`.`dept_no` = 'd001') and (`e`.`emp_no` = `a`.`emp_no`))", 59 | "steps": [ 60 | { 61 | "transformation": "equality_propagation", 62 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`) and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 63 | }, 64 | { 65 | "transformation": "constant_propagation", 66 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`) and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 67 | }, 68 | { 69 | "transformation": "trivial_condition_removal", 70 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`) and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 71 | } 72 | ] 73 | } 74 | }, 75 | { 76 | "substitute_generated_columns": {} 77 | }, 78 | { 79 | "table_dependencies": [ 80 | { 81 | "table": "`employees` `e`", 82 | "row_may_be_null": false, 83 | "map_bit": 0, 84 | "depends_on_map_bits": [] 85 | }, 86 | { 87 | "table": "`dept_manager` `a`", 88 | "row_may_be_null": false, 89 | "map_bit": 1, 90 | "depends_on_map_bits": [] 91 | } 92 | ] 93 | }, 94 | { 95 | "ref_optimizer_key_uses": [ 96 | { 97 | "table": "`employees` `e`", 98 | "field": "emp_no", 99 | "equals": "`a`.`emp_no`", 100 | "null_rejecting": true 101 | }, 102 | { 103 | "table": "`dept_manager` `a`", 104 | "field": "emp_no", 105 | "equals": "`e`.`emp_no`", 106 | "null_rejecting": true 107 | }, 108 | { 109 | "table": "`dept_manager` `a`", 110 | "field": "dept_no", 111 | "equals": "'d001'", 112 | "null_rejecting": true 113 | }, 114 | { 115 | "table": "`dept_manager` `a`", 116 | "field": "dept_no", 117 | "equals": "'d001'", 118 | "null_rejecting": true 119 | }, 120 | { 121 | "table": "`dept_manager` `a`", 122 | "field": "emp_no", 123 | "equals": "`e`.`emp_no`", 124 | "null_rejecting": true 125 | } 126 | ] 127 | }, 128 | { 129 | "pulled_out_semijoin_tables": [ 130 | { 131 | "table": "`dept_manager` `a`", 132 | "functionally_dependent": true 133 | } 134 | ] 135 | }, 136 | { 137 | "rows_estimation": [ 138 | { 139 | "table": "`employees` `e`", 140 | "table_scan": { 141 | "rows": 276023, 142 | "cost": 864.206 143 | } 144 | }, 145 | { 146 | "table": "`dept_manager` `a`", 147 | "range_analysis": { 148 | "table_scan": { 149 | "rows": 24, 150 | "cost": 4.75 151 | }, 152 | "potential_range_indexes": [ 153 | { 154 | "index": "PRIMARY", 155 | "usable": false, 156 | "cause": "not_applicable" 157 | }, 158 | { 159 | "index": "dept_no", 160 | "usable": true, 161 | "key_parts": [ 162 | "dept_no", 163 | "emp_no" 164 | ] 165 | } 166 | ], 167 | "best_covering_index_scan": { 168 | "index": "dept_no", 169 | "cost": 2.67522, 170 | "chosen": true 171 | }, 172 | "setup_range_conditions": [], 173 | "group_index_range": { 174 | "chosen": false, 175 | "cause": "not_single_table" 176 | }, 177 | "skip_scan_range": { 178 | "chosen": false, 179 | "cause": "not_single_table" 180 | }, 181 | "analyzing_range_alternatives": { 182 | "range_scan_alternatives": [ 183 | { 184 | "index": "dept_no", 185 | "ranges": [ 186 | "dept_no = 'd001'" 187 | ], 188 | "index_dives_for_eq_ranges": true, 189 | "rowid_ordered": true, 190 | "using_mrr": false, 191 | "index_only": true, 192 | "in_memory": 1, 193 | "rows": 2, 194 | "cost": 0.461096, 195 | "chosen": true 196 | } 197 | ], 198 | "analyzing_roworder_intersect": { 199 | "usable": false, 200 | "cause": "too_few_roworder_scans" 201 | } 202 | }, 203 | "chosen_range_access_summary": { 204 | "range_access_plan": { 205 | "type": "range_scan", 206 | "index": "dept_no", 207 | "rows": 2, 208 | "ranges": [ 209 | "dept_no = 'd001'" 210 | ] 211 | }, 212 | "rows_for_plan": 2, 213 | "cost_for_plan": 0.461096, 214 | "chosen": true 215 | } 216 | } 217 | } 218 | ] 219 | }, 220 | { 221 | "considered_execution_plans": [ 222 | { 223 | "plan_prefix": [], 224 | "table": "`dept_manager` `a`", 225 | "best_access_path": { 226 | "considered_access_paths": [ 227 | { 228 | "access_type": "ref", 229 | "index": "PRIMARY", 230 | "usable": false, 231 | "chosen": false 232 | }, 233 | { 234 | "access_type": "ref", 235 | "index": "dept_no", 236 | "rows": 2, 237 | "cost": 0.451096, 238 | "chosen": true 239 | }, 240 | { 241 | "access_type": "range", 242 | "range_details": { 243 | "used_index": "dept_no" 244 | }, 245 | "chosen": false, 246 | "cause": "heuristic_index_cheaper" 247 | } 248 | ] 249 | }, 250 | "condition_filtering_pct": 100, 251 | "rows_for_plan": 2, 252 | "cost_for_plan": 0.451096, 253 | "rest_of_plan": [ 254 | { 255 | "plan_prefix": [ 256 | "`dept_manager` `a`" 257 | ], 258 | "table": "`employees` `e`", 259 | "best_access_path": { 260 | "considered_access_paths": [ 261 | { 262 | "access_type": "eq_ref", 263 | "index": "PRIMARY", 264 | "rows": 1, 265 | "cost": 2.19816, 266 | "chosen": true, 267 | "cause": "clustered_pk_chosen_by_heuristics" 268 | }, 269 | { 270 | "access_type": "scan", 271 | "cost": 28466.5, 272 | "rows": 276023, 273 | "chosen": false, 274 | "cause": "cost" 275 | } 276 | ] 277 | }, 278 | "condition_filtering_pct": 100, 279 | "rows_for_plan": 2, 280 | "cost_for_plan": 2.64926, 281 | "chosen": true 282 | } 283 | ] 284 | }, 285 | { 286 | "plan_prefix": [], 287 | "table": "`employees` `e`", 288 | "best_access_path": { 289 | "considered_access_paths": [ 290 | { 291 | "access_type": "ref", 292 | "index": "PRIMARY", 293 | "usable": false, 294 | "chosen": false 295 | }, 296 | { 297 | "rows_to_scan": 276023, 298 | "filtering_effect": [], 299 | "final_filtering_effect": 1, 300 | "access_type": "scan", 301 | "resulting_rows": 276023, 302 | "cost": 28466.5, 303 | "chosen": true 304 | } 305 | ] 306 | }, 307 | "condition_filtering_pct": 100, 308 | "rows_for_plan": 276023, 309 | "cost_for_plan": 28466.5, 310 | "pruned_by_cost": true 311 | } 312 | ] 313 | }, 314 | { 315 | "attaching_conditions_to_tables": { 316 | "original_condition": "((`e`.`emp_no` = `a`.`emp_no`) and (`a`.`dept_no` = 'd001'))", 317 | "attached_conditions_computation": [], 318 | "attached_conditions_summary": [ 319 | { 320 | "table": "`dept_manager` `a`", 321 | "attached": "(`a`.`dept_no` = 'd001')" 322 | }, 323 | { 324 | "table": "`employees` `e`", 325 | "attached": "(`e`.`emp_no` = `a`.`emp_no`)" 326 | } 327 | ] 328 | } 329 | }, 330 | { 331 | "finalizing_table_conditions": [ 332 | { 333 | "table": "`dept_manager` `a`", 334 | "original_table_condition": "(`a`.`dept_no` = 'd001')", 335 | "final_table_condition ": "(`a`.`dept_no` = 'd001')" 336 | }, 337 | { 338 | "table": "`employees` `e`", 339 | "original_table_condition": "(`e`.`emp_no` = `a`.`emp_no`)", 340 | "final_table_condition ": null 341 | } 342 | ] 343 | }, 344 | { 345 | "refine_plan": [ 346 | { 347 | "table": "`dept_manager` `a`" 348 | }, 349 | { 350 | "table": "`employees` `e`" 351 | } 352 | ] 353 | } 354 | ] 355 | } 356 | }, 357 | { 358 | "join_execution": { 359 | "select#": 1, 360 | "steps": [] 361 | } 362 | } 363 | ] 364 | } 365 | -------------------------------------------------------------------------------- /assets/subq03_non-unique_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "6.50" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "d", 11 | "access_type": "index", 12 | "possible_keys": [ 13 | "PRIMARY" 14 | ], 15 | "key": "dept_name", 16 | "used_key_parts": [ 17 | "dept_name" 18 | ], 19 | "key_length": "162", 20 | "rows_examined_per_scan": 9, 21 | "rows_produced_per_join": 9, 22 | "filtered": "100.00", 23 | "using_index": true, 24 | "cost_info": { 25 | "read_cost": "0.25", 26 | "eval_cost": "0.90", 27 | "prefix_cost": "1.15", 28 | "data_read_per_join": "1K" 29 | }, 30 | "used_columns": [ 31 | "dept_no", 32 | "dept_name" 33 | ] 34 | } 35 | }, 36 | { 37 | "table": { 38 | "table_name": "", 39 | "access_type": "eq_ref", 40 | "key": "", 41 | "key_length": "16", 42 | "ref": [ 43 | "employees.d.dept_no" 44 | ], 45 | "rows_examined_per_scan": 1, 46 | "materialized_from_subquery": { 47 | "using_temporary_table": true, 48 | "query_block": { 49 | "table": { 50 | "table_name": "a", 51 | "access_type": "ALL", 52 | "possible_keys": [ 53 | "dept_no" 54 | ], 55 | "rows_examined_per_scan": 24, 56 | "rows_produced_per_join": 7, 57 | "filtered": "33.33", 58 | "cost_info": { 59 | "read_cost": "1.85", 60 | "eval_cost": "0.80", 61 | "prefix_cost": "2.65", 62 | "data_read_per_join": "255" 63 | }, 64 | "used_columns": [ 65 | "dept_no", 66 | "from_date" 67 | ], 68 | "attached_condition": "(`employees`.`a`.`from_date` >= DATE'1995-01-01')" 69 | } 70 | } 71 | } 72 | } 73 | } 74 | ] 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /assets/subq04_exists_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "2.65" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "a", 11 | "access_type": "ref", 12 | "possible_keys": [ 13 | "PRIMARY", 14 | "dept_no" 15 | ], 16 | "key": "dept_no", 17 | "used_key_parts": [ 18 | "dept_no" 19 | ], 20 | "key_length": "16", 21 | "ref": [ 22 | "const" 23 | ], 24 | "rows_examined_per_scan": 2, 25 | "rows_produced_per_join": 2, 26 | "filtered": "100.00", 27 | "using_index": true, 28 | "cost_info": { 29 | "read_cost": "0.25", 30 | "eval_cost": "0.20", 31 | "prefix_cost": "0.45", 32 | "data_read_per_join": "64" 33 | }, 34 | "used_columns": [ 35 | "emp_no", 36 | "dept_no" 37 | ], 38 | "attached_condition": "(`employees`.`a`.`dept_no` = 'd001')" 39 | } 40 | }, 41 | { 42 | "table": { 43 | "table_name": "e", 44 | "access_type": "eq_ref", 45 | "possible_keys": [ 46 | "PRIMARY" 47 | ], 48 | "key": "PRIMARY", 49 | "used_key_parts": [ 50 | "emp_no" 51 | ], 52 | "key_length": "4", 53 | "ref": [ 54 | "employees.a.emp_no" 55 | ], 56 | "rows_examined_per_scan": 1, 57 | "rows_produced_per_join": 2, 58 | "filtered": "100.00", 59 | "cost_info": { 60 | "read_cost": "2.00", 61 | "eval_cost": "0.20", 62 | "prefix_cost": "2.65", 63 | "data_read_per_join": "272" 64 | }, 65 | "used_columns": [ 66 | "emp_no", 67 | "first_name", 68 | "last_name" 69 | ] 70 | } 71 | } 72 | ] 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /assets/subq04_exists_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "join_preparation": { 9 | "select#": 2, 10 | "steps": [ 11 | { 12 | "expanded_query": "/* select#2 */ select 1 from `dept_manager` `a` where ((`a`.`dept_no` = 'd001') and (`a`.`emp_no` = `e`.`emp_no`))" 13 | } 14 | ] 15 | } 16 | }, 17 | { 18 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name` from `employees` `e` where exists(/* select#2 */ select 1 from `dept_manager` `a` where ((`a`.`dept_no` = 'd001') and (`a`.`emp_no` = `e`.`emp_no`)))" 19 | }, 20 | { 21 | "transformation": { 22 | "select#": 2, 23 | "from": "IN (SELECT)", 24 | "to": "semijoin", 25 | "chosen": true, 26 | "transformation_to_semi_join": { 27 | "subquery_predicate": "exists(/* select#2 */ select 1 from `dept_manager` `a` where ((`a`.`dept_no` = 'd001') and (`a`.`emp_no` = `e`.`emp_no`)))", 28 | "embedded in": "WHERE", 29 | "evaluating_constant_semijoin_conditions": [], 30 | "semi-join condition": "((`a`.`dept_no` = 'd001') and (`e`.`emp_no` = `a`.`emp_no`))", 31 | "decorrelated_predicates": [ 32 | { 33 | "outer": "`e`.`emp_no`", 34 | "inner": "`a`.`emp_no`" 35 | } 36 | ] 37 | } 38 | } 39 | }, 40 | { 41 | "transformations_to_nested_joins": { 42 | "transformations": [ 43 | "semijoin" 44 | ], 45 | "expanded_query": "/* select#1 */ select `e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name` from `employees` `e` semi join (`dept_manager` `a`) where ((`a`.`dept_no` = 'd001') and (`e`.`emp_no` = `a`.`emp_no`))" 46 | } 47 | } 48 | ] 49 | } 50 | }, 51 | { 52 | "join_optimization": { 53 | "select#": 1, 54 | "steps": [ 55 | { 56 | "condition_processing": { 57 | "condition": "WHERE", 58 | "original_condition": "((`a`.`dept_no` = 'd001') and (`e`.`emp_no` = `a`.`emp_no`))", 59 | "steps": [ 60 | { 61 | "transformation": "equality_propagation", 62 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`) and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 63 | }, 64 | { 65 | "transformation": "constant_propagation", 66 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`) and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 67 | }, 68 | { 69 | "transformation": "trivial_condition_removal", 70 | "resulting_condition": "(multiple equal('d001', `a`.`dept_no`) and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 71 | } 72 | ] 73 | } 74 | }, 75 | { 76 | "substitute_generated_columns": {} 77 | }, 78 | { 79 | "table_dependencies": [ 80 | { 81 | "table": "`employees` `e`", 82 | "row_may_be_null": false, 83 | "map_bit": 0, 84 | "depends_on_map_bits": [] 85 | }, 86 | { 87 | "table": "`dept_manager` `a`", 88 | "row_may_be_null": false, 89 | "map_bit": 1, 90 | "depends_on_map_bits": [] 91 | } 92 | ] 93 | }, 94 | { 95 | "ref_optimizer_key_uses": [ 96 | { 97 | "table": "`employees` `e`", 98 | "field": "emp_no", 99 | "equals": "`a`.`emp_no`", 100 | "null_rejecting": true 101 | }, 102 | { 103 | "table": "`dept_manager` `a`", 104 | "field": "emp_no", 105 | "equals": "`e`.`emp_no`", 106 | "null_rejecting": true 107 | }, 108 | { 109 | "table": "`dept_manager` `a`", 110 | "field": "dept_no", 111 | "equals": "'d001'", 112 | "null_rejecting": true 113 | }, 114 | { 115 | "table": "`dept_manager` `a`", 116 | "field": "dept_no", 117 | "equals": "'d001'", 118 | "null_rejecting": true 119 | }, 120 | { 121 | "table": "`dept_manager` `a`", 122 | "field": "emp_no", 123 | "equals": "`e`.`emp_no`", 124 | "null_rejecting": true 125 | } 126 | ] 127 | }, 128 | { 129 | "pulled_out_semijoin_tables": [ 130 | { 131 | "table": "`dept_manager` `a`", 132 | "functionally_dependent": true 133 | } 134 | ] 135 | }, 136 | { 137 | "rows_estimation": [ 138 | { 139 | "table": "`employees` `e`", 140 | "table_scan": { 141 | "rows": 276023, 142 | "cost": 864.206 143 | } 144 | }, 145 | { 146 | "table": "`dept_manager` `a`", 147 | "range_analysis": { 148 | "table_scan": { 149 | "rows": 24, 150 | "cost": 4.75 151 | }, 152 | "potential_range_indexes": [ 153 | { 154 | "index": "PRIMARY", 155 | "usable": false, 156 | "cause": "not_applicable" 157 | }, 158 | { 159 | "index": "dept_no", 160 | "usable": true, 161 | "key_parts": [ 162 | "dept_no", 163 | "emp_no" 164 | ] 165 | } 166 | ], 167 | "best_covering_index_scan": { 168 | "index": "dept_no", 169 | "cost": 2.67522, 170 | "chosen": true 171 | }, 172 | "setup_range_conditions": [], 173 | "group_index_range": { 174 | "chosen": false, 175 | "cause": "not_single_table" 176 | }, 177 | "skip_scan_range": { 178 | "chosen": false, 179 | "cause": "not_single_table" 180 | }, 181 | "analyzing_range_alternatives": { 182 | "range_scan_alternatives": [ 183 | { 184 | "index": "dept_no", 185 | "ranges": [ 186 | "dept_no = 'd001'" 187 | ], 188 | "index_dives_for_eq_ranges": true, 189 | "rowid_ordered": true, 190 | "using_mrr": false, 191 | "index_only": true, 192 | "in_memory": 1, 193 | "rows": 2, 194 | "cost": 0.461096, 195 | "chosen": true 196 | } 197 | ], 198 | "analyzing_roworder_intersect": { 199 | "usable": false, 200 | "cause": "too_few_roworder_scans" 201 | } 202 | }, 203 | "chosen_range_access_summary": { 204 | "range_access_plan": { 205 | "type": "range_scan", 206 | "index": "dept_no", 207 | "rows": 2, 208 | "ranges": [ 209 | "dept_no = 'd001'" 210 | ] 211 | }, 212 | "rows_for_plan": 2, 213 | "cost_for_plan": 0.461096, 214 | "chosen": true 215 | } 216 | } 217 | } 218 | ] 219 | }, 220 | { 221 | "considered_execution_plans": [ 222 | { 223 | "plan_prefix": [], 224 | "table": "`dept_manager` `a`", 225 | "best_access_path": { 226 | "considered_access_paths": [ 227 | { 228 | "access_type": "ref", 229 | "index": "PRIMARY", 230 | "usable": false, 231 | "chosen": false 232 | }, 233 | { 234 | "access_type": "ref", 235 | "index": "dept_no", 236 | "rows": 2, 237 | "cost": 0.451096, 238 | "chosen": true 239 | }, 240 | { 241 | "access_type": "range", 242 | "range_details": { 243 | "used_index": "dept_no" 244 | }, 245 | "chosen": false, 246 | "cause": "heuristic_index_cheaper" 247 | } 248 | ] 249 | }, 250 | "condition_filtering_pct": 100, 251 | "rows_for_plan": 2, 252 | "cost_for_plan": 0.451096, 253 | "rest_of_plan": [ 254 | { 255 | "plan_prefix": [ 256 | "`dept_manager` `a`" 257 | ], 258 | "table": "`employees` `e`", 259 | "best_access_path": { 260 | "considered_access_paths": [ 261 | { 262 | "access_type": "eq_ref", 263 | "index": "PRIMARY", 264 | "rows": 1, 265 | "cost": 2.19816, 266 | "chosen": true, 267 | "cause": "clustered_pk_chosen_by_heuristics" 268 | }, 269 | { 270 | "access_type": "scan", 271 | "cost": 28466.5, 272 | "rows": 276023, 273 | "chosen": false, 274 | "cause": "cost" 275 | } 276 | ] 277 | }, 278 | "condition_filtering_pct": 100, 279 | "rows_for_plan": 2, 280 | "cost_for_plan": 2.64926, 281 | "chosen": true 282 | } 283 | ] 284 | }, 285 | { 286 | "plan_prefix": [], 287 | "table": "`employees` `e`", 288 | "best_access_path": { 289 | "considered_access_paths": [ 290 | { 291 | "access_type": "ref", 292 | "index": "PRIMARY", 293 | "usable": false, 294 | "chosen": false 295 | }, 296 | { 297 | "rows_to_scan": 276023, 298 | "filtering_effect": [], 299 | "final_filtering_effect": 1, 300 | "access_type": "scan", 301 | "resulting_rows": 276023, 302 | "cost": 28466.5, 303 | "chosen": true 304 | } 305 | ] 306 | }, 307 | "condition_filtering_pct": 100, 308 | "rows_for_plan": 276023, 309 | "cost_for_plan": 28466.5, 310 | "pruned_by_cost": true 311 | } 312 | ] 313 | }, 314 | { 315 | "attaching_conditions_to_tables": { 316 | "original_condition": "((`e`.`emp_no` = `a`.`emp_no`) and (`a`.`dept_no` = 'd001'))", 317 | "attached_conditions_computation": [], 318 | "attached_conditions_summary": [ 319 | { 320 | "table": "`dept_manager` `a`", 321 | "attached": "(`a`.`dept_no` = 'd001')" 322 | }, 323 | { 324 | "table": "`employees` `e`", 325 | "attached": "(`e`.`emp_no` = `a`.`emp_no`)" 326 | } 327 | ] 328 | } 329 | }, 330 | { 331 | "finalizing_table_conditions": [ 332 | { 333 | "table": "`dept_manager` `a`", 334 | "original_table_condition": "(`a`.`dept_no` = 'd001')", 335 | "final_table_condition ": "(`a`.`dept_no` = 'd001')" 336 | }, 337 | { 338 | "table": "`employees` `e`", 339 | "original_table_condition": "(`e`.`emp_no` = `a`.`emp_no`)", 340 | "final_table_condition ": null 341 | } 342 | ] 343 | }, 344 | { 345 | "refine_plan": [ 346 | { 347 | "table": "`dept_manager` `a`" 348 | }, 349 | { 350 | "table": "`employees` `e`" 351 | } 352 | ] 353 | } 354 | ] 355 | } 356 | }, 357 | { 358 | "join_execution": { 359 | "select#": 1, 360 | "steps": [] 361 | } 362 | } 363 | ] 364 | } 365 | -------------------------------------------------------------------------------- /assets/subq05_not-in_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "8.10" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "d", 11 | "access_type": "index", 12 | "key": "dept_name", 13 | "used_key_parts": [ 14 | "dept_name" 15 | ], 16 | "key_length": "162", 17 | "rows_examined_per_scan": 9, 18 | "rows_produced_per_join": 9, 19 | "filtered": "100.00", 20 | "using_index": true, 21 | "cost_info": { 22 | "read_cost": "0.25", 23 | "eval_cost": "0.90", 24 | "prefix_cost": "1.15", 25 | "data_read_per_join": "1K" 26 | }, 27 | "used_columns": [ 28 | "dept_no", 29 | "dept_name" 30 | ] 31 | } 32 | }, 33 | { 34 | "table": { 35 | "table_name": "", 36 | "access_type": "eq_ref", 37 | "key": "", 38 | "key_length": "17", 39 | "ref": [ 40 | "employees.d.dept_no" 41 | ], 42 | "rows_examined_per_scan": 1, 43 | "not_exists": true, 44 | "attached_condition": "(is_not_null_compl(), (found_match(), false, true), true)", 45 | "materialized_from_subquery": { 46 | "using_temporary_table": true, 47 | "query_block": { 48 | "table": { 49 | "table_name": "a", 50 | "access_type": "ALL", 51 | "possible_keys": [ 52 | "dept_no" 53 | ], 54 | "rows_examined_per_scan": 24, 55 | "rows_produced_per_join": 24, 56 | "filtered": "100.00", 57 | "cost_info": { 58 | "read_cost": "0.25", 59 | "eval_cost": "2.40", 60 | "prefix_cost": "2.65", 61 | "data_read_per_join": "768" 62 | }, 63 | "used_columns": [ 64 | "dept_no", 65 | "from_date" 66 | ], 67 | "attached_condition": "(`employees`.`a`.`from_date` > '1995-01-01')" 68 | } 69 | } 70 | } 71 | } 72 | } 73 | ] 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /assets/subq05_not-in_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "join_preparation": { 9 | "select#": 2, 10 | "steps": [ 11 | { 12 | "expanded_query": "/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` > '1995-01-01')" 13 | } 14 | ] 15 | } 16 | }, 17 | { 18 | "expanded_query": "/* select#1 */ select `d`.`dept_no` AS `dept_no`,`d`.`dept_name` AS `dept_name` from `departments` `d` where `d`.`dept_no` in (/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` > '1995-01-01')) is false" 19 | }, 20 | { 21 | "transformation": { 22 | "select#": 2, 23 | "from": "IN (SELECT)", 24 | "to": "antijoin", 25 | "chosen": true, 26 | "transformation_to_semi_join": { 27 | "subquery_predicate": "`d`.`dept_no` in (/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` > '1995-01-01')) is false", 28 | "embedded in": "WHERE", 29 | "evaluating_constant_semijoin_conditions": [], 30 | "semi-join condition": "((`a`.`from_date` > '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))", 31 | "decorrelated_predicates": [ 32 | { 33 | "outer": "`d`.`dept_no`", 34 | "inner": "`a`.`dept_no`" 35 | } 36 | ] 37 | } 38 | } 39 | }, 40 | { 41 | "transformations_to_nested_joins": { 42 | "transformations": [ 43 | "parenthesis_removal" 44 | ], 45 | "expanded_query": "/* select#1 */ select `d`.`dept_no` AS `dept_no`,`d`.`dept_name` AS `dept_name` from `departments` `d` anti join (`dept_manager` `a`) on(((`a`.`from_date` > '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))) where true" 46 | } 47 | } 48 | ] 49 | } 50 | }, 51 | { 52 | "join_optimization": { 53 | "select#": 1, 54 | "steps": [ 55 | { 56 | "condition_processing": { 57 | "condition": "WHERE", 58 | "original_condition": "true", 59 | "steps": [ 60 | { 61 | "transformation": "equality_propagation", 62 | "resulting_condition": "true" 63 | }, 64 | { 65 | "transformation": "constant_propagation", 66 | "resulting_condition": "true" 67 | }, 68 | { 69 | "transformation": "trivial_condition_removal", 70 | "resulting_condition": null 71 | } 72 | ] 73 | } 74 | }, 75 | { 76 | "table_dependencies": [ 77 | { 78 | "table": "`departments` `d`", 79 | "row_may_be_null": false, 80 | "map_bit": 0, 81 | "depends_on_map_bits": [] 82 | }, 83 | { 84 | "table": "`dept_manager` `a`", 85 | "row_may_be_null": true, 86 | "map_bit": 1, 87 | "depends_on_map_bits": [ 88 | 0 89 | ] 90 | } 91 | ] 92 | }, 93 | { 94 | "ref_optimizer_key_uses": [ 95 | { 96 | "table": "`dept_manager` `a`", 97 | "field": "dept_no", 98 | "equals": "`d`.`dept_no`", 99 | "null_rejecting": true 100 | } 101 | ] 102 | }, 103 | { 104 | "pulled_out_semijoin_tables": [] 105 | }, 106 | { 107 | "rows_estimation": [ 108 | { 109 | "table": "`departments` `d`", 110 | "table_scan": { 111 | "rows": 9, 112 | "cost": 0.25 113 | } 114 | }, 115 | { 116 | "table": "`dept_manager` `a`", 117 | "table_scan": { 118 | "rows": 24, 119 | "cost": 0.25 120 | } 121 | } 122 | ] 123 | }, 124 | { 125 | "execution_plan_for_potential_materialization": { 126 | "steps": [ 127 | { 128 | "considered_execution_plans": [ 129 | { 130 | "plan_prefix": [], 131 | "table": "`dept_manager` `a`", 132 | "best_access_path": { 133 | "considered_access_paths": [ 134 | { 135 | "access_type": "ref", 136 | "index": "dept_no", 137 | "usable": false, 138 | "chosen": false 139 | }, 140 | { 141 | "rows_to_scan": 24, 142 | "access_type": "scan", 143 | "resulting_rows": 24, 144 | "cost": 2.65, 145 | "chosen": true 146 | } 147 | ] 148 | }, 149 | "condition_filtering_pct": 100, 150 | "rows_for_plan": 24, 151 | "cost_for_plan": 2.65, 152 | "chosen": true 153 | } 154 | ] 155 | } 156 | ] 157 | } 158 | }, 159 | { 160 | "considered_execution_plans": [ 161 | { 162 | "plan_prefix": [], 163 | "table": "`departments` `d`", 164 | "best_access_path": { 165 | "considered_access_paths": [ 166 | { 167 | "rows_to_scan": 9, 168 | "access_type": "scan", 169 | "resulting_rows": 9, 170 | "cost": 1.15, 171 | "chosen": true 172 | } 173 | ] 174 | }, 175 | "condition_filtering_pct": 100, 176 | "rows_for_plan": 9, 177 | "cost_for_plan": 1.15, 178 | "semijoin_strategy_choice": [], 179 | "rest_of_plan": [ 180 | { 181 | "plan_prefix": [ 182 | "`departments` `d`" 183 | ], 184 | "table": "`dept_manager` `a`", 185 | "best_access_path": { 186 | "considered_access_paths": [ 187 | { 188 | "access_type": "ref", 189 | "index": "dept_no", 190 | "rows": 2.66667, 191 | "cost": 7.8, 192 | "chosen": true 193 | }, 194 | { 195 | "rows_to_scan": 24, 196 | "access_type": "scan", 197 | "using_join_cache": true, 198 | "buffers_needed": 1, 199 | "resulting_rows": 24, 200 | "cost": 21.8515, 201 | "chosen": false 202 | } 203 | ] 204 | }, 205 | "condition_filtering_pct": 100, 206 | "rows_for_plan": 24, 207 | "cost_for_plan": 8.95, 208 | "semijoin_strategy_choice": [ 209 | { 210 | "strategy": "FirstMatch", 211 | "recalculate_access_paths_and_cost": { 212 | "tables": [] 213 | }, 214 | "cost": 8.95, 215 | "rows": 9, 216 | "chosen": true 217 | }, 218 | { 219 | "strategy": "MaterializeLookup", 220 | "cost": 8.1, 221 | "rows": 9, 222 | "duplicate_tables_left": false, 223 | "chosen": true 224 | }, 225 | { 226 | "strategy": "DuplicatesWeedout", 227 | "cost": 13.25, 228 | "rows": 9, 229 | "duplicate_tables_left": false, 230 | "chosen": false 231 | } 232 | ], 233 | "chosen": true 234 | } 235 | ] 236 | }, 237 | { 238 | "final_semijoin_strategy": "MaterializeLookup" 239 | } 240 | ] 241 | }, 242 | { 243 | "creating_tmp_table": { 244 | "tmp_table_info": { 245 | "table": "", 246 | "columns": 1, 247 | "row_length": 17, 248 | "key_length": 17, 249 | "unique_constraint": false, 250 | "makes_grouped_rows": false, 251 | "cannot_insert_duplicates": true, 252 | "location": "TempTable" 253 | } 254 | } 255 | }, 256 | { 257 | "condition_on_constant_tables": "true", 258 | "condition_value": true 259 | }, 260 | { 261 | "attaching_conditions_to_tables": { 262 | "original_condition": "true", 263 | "attached_conditions_computation": [], 264 | "attached_conditions_summary": [ 265 | { 266 | "table": "`departments` `d`", 267 | "attached": null 268 | }, 269 | { 270 | "table": "``", 271 | "attached": "((is_not_null_compl(), (``.`dept_no` = `d`.`dept_no`), true) and (is_not_null_compl(), (found_match(), false, true), true))" 272 | }, 273 | { 274 | "table": "`dept_manager` `a`", 275 | "attached": "(`a`.`from_date` > '1995-01-01')" 276 | } 277 | ] 278 | } 279 | }, 280 | { 281 | "finalizing_table_conditions": [ 282 | { 283 | "table": "``", 284 | "original_table_condition": "((is_not_null_compl(), (``.`dept_no` = `d`.`dept_no`), true) and (is_not_null_compl(), (found_match(), false, true), true))", 285 | "final_table_condition ": "(is_not_null_compl(), (found_match(), false, true), true)" 286 | }, 287 | { 288 | "table": "`dept_manager` `a`", 289 | "original_table_condition": "(`a`.`from_date` > '1995-01-01')", 290 | "final_table_condition ": "(`a`.`from_date` > '1995-01-01')" 291 | } 292 | ] 293 | }, 294 | { 295 | "refine_plan": [ 296 | { 297 | "table": "`departments` `d`" 298 | }, 299 | { 300 | "table": "``" 301 | }, 302 | { 303 | "table": "`dept_manager` `a`" 304 | } 305 | ] 306 | } 307 | ] 308 | } 309 | }, 310 | { 311 | "join_execution": { 312 | "select#": 1, 313 | "steps": [ 314 | { 315 | "materialize": { 316 | "select#": 1, 317 | "steps": [] 318 | } 319 | } 320 | ] 321 | } 322 | } 323 | ] 324 | } 325 | -------------------------------------------------------------------------------- /assets/subq06_derived-table_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "48.24" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "t", 11 | "access_type": "range", 12 | "possible_keys": [ 13 | "PRIMARY" 14 | ], 15 | "key": "PRIMARY", 16 | "used_key_parts": [ 17 | "emp_no" 18 | ], 19 | "key_length": "4", 20 | "rows_examined_per_scan": 151, 21 | "rows_produced_per_join": 50, 22 | "filtered": "33.33", 23 | "cost_info": { 24 | "read_cost": "25.59", 25 | "eval_cost": "5.03", 26 | "prefix_cost": "30.63", 27 | "data_read_per_join": "10K" 28 | }, 29 | "used_columns": [ 30 | "emp_no", 31 | "title", 32 | "from_date", 33 | "to_date" 34 | ], 35 | "attached_condition": "((`employees`.`t`.`from_date` > DATE'2000-01-01') and (`employees`.`t`.`emp_no` <= 10100))" 36 | } 37 | }, 38 | { 39 | "table": { 40 | "table_name": "employees", 41 | "access_type": "eq_ref", 42 | "possible_keys": [ 43 | "PRIMARY" 44 | ], 45 | "key": "PRIMARY", 46 | "used_key_parts": [ 47 | "emp_no" 48 | ], 49 | "key_length": "4", 50 | "ref": [ 51 | "employees.t.emp_no" 52 | ], 53 | "rows_examined_per_scan": 1, 54 | "rows_produced_per_join": 50, 55 | "filtered": "100.00", 56 | "cost_info": { 57 | "read_cost": "12.58", 58 | "eval_cost": "5.03", 59 | "prefix_cost": "48.24", 60 | "data_read_per_join": "6K" 61 | }, 62 | "used_columns": [ 63 | "emp_no", 64 | "birth_date", 65 | "first_name", 66 | "last_name", 67 | "gender", 68 | "hire_date" 69 | ] 70 | } 71 | } 72 | ] 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /assets/subq10_sj_default_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "6.50" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "d", 11 | "access_type": "index", 12 | "possible_keys": [ 13 | "PRIMARY" 14 | ], 15 | "key": "dept_name", 16 | "used_key_parts": [ 17 | "dept_name" 18 | ], 19 | "key_length": "162", 20 | "rows_examined_per_scan": 9, 21 | "rows_produced_per_join": 9, 22 | "filtered": "100.00", 23 | "using_index": true, 24 | "cost_info": { 25 | "read_cost": "0.25", 26 | "eval_cost": "0.90", 27 | "prefix_cost": "1.15", 28 | "data_read_per_join": "1K" 29 | }, 30 | "used_columns": [ 31 | "dept_no", 32 | "dept_name" 33 | ] 34 | } 35 | }, 36 | { 37 | "table": { 38 | "table_name": "", 39 | "access_type": "eq_ref", 40 | "key": "", 41 | "key_length": "16", 42 | "ref": [ 43 | "employees.d.dept_no" 44 | ], 45 | "rows_examined_per_scan": 1, 46 | "materialized_from_subquery": { 47 | "using_temporary_table": true, 48 | "query_block": { 49 | "table": { 50 | "table_name": "a", 51 | "access_type": "ALL", 52 | "possible_keys": [ 53 | "dept_no" 54 | ], 55 | "rows_examined_per_scan": 24, 56 | "rows_produced_per_join": 7, 57 | "filtered": "33.33", 58 | "cost_info": { 59 | "read_cost": "1.85", 60 | "eval_cost": "0.80", 61 | "prefix_cost": "2.65", 62 | "data_read_per_join": "255" 63 | }, 64 | "used_columns": [ 65 | "dept_no", 66 | "from_date" 67 | ], 68 | "attached_condition": "(`employees`.`a`.`from_date` >= DATE'1995-01-01')" 69 | } 70 | } 71 | } 72 | } 73 | } 74 | ] 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /assets/subq11_sj_duplicate-weedout_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "8.05" 6 | }, 7 | "duplicates_removal": { 8 | "using_temporary_table": true, 9 | "nested_loop": [ 10 | { 11 | "table": { 12 | "table_name": "a", 13 | "access_type": "ALL", 14 | "possible_keys": [ 15 | "dept_no" 16 | ], 17 | "rows_examined_per_scan": 24, 18 | "rows_produced_per_join": 7, 19 | "filtered": "33.33", 20 | "cost_info": { 21 | "read_cost": "1.85", 22 | "eval_cost": "0.80", 23 | "prefix_cost": "2.65", 24 | "data_read_per_join": "255" 25 | }, 26 | "used_columns": [ 27 | "dept_no", 28 | "from_date" 29 | ], 30 | "attached_condition": "(`employees`.`a`.`from_date` >= DATE'1995-01-01')" 31 | } 32 | }, 33 | { 34 | "table": { 35 | "table_name": "d", 36 | "access_type": "eq_ref", 37 | "possible_keys": [ 38 | "PRIMARY" 39 | ], 40 | "key": "PRIMARY", 41 | "used_key_parts": [ 42 | "dept_no" 43 | ], 44 | "key_length": "16", 45 | "ref": [ 46 | "employees.a.dept_no" 47 | ], 48 | "rows_examined_per_scan": 1, 49 | "rows_produced_per_join": 7, 50 | "filtered": "100.00", 51 | "cost_info": { 52 | "read_cost": "2.00", 53 | "eval_cost": "0.80", 54 | "prefix_cost": "8.05", 55 | "data_read_per_join": "1K" 56 | }, 57 | "used_columns": [ 58 | "dept_no", 59 | "dept_name" 60 | ] 61 | } 62 | } 63 | ] 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /assets/subq11_sj_duplicate-weedout_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "join_preparation": { 9 | "select#": 2, 10 | "steps": [ 11 | { 12 | "expanded_query": "/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` >= '1995-01-01')" 13 | } 14 | ] 15 | } 16 | }, 17 | { 18 | "expanded_query": "/* select#1 */ select /*+ SEMIJOIN(@`select#2` DUPSWEEDOUT) */ `d`.`dept_no` AS `dept_no`,`d`.`dept_name` AS `dept_name` from `departments` `d` where `d`.`dept_no` in (/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` >= '1995-01-01'))" 19 | }, 20 | { 21 | "transformation": { 22 | "select#": 2, 23 | "from": "IN (SELECT)", 24 | "to": "semijoin", 25 | "chosen": true, 26 | "transformation_to_semi_join": { 27 | "subquery_predicate": "`d`.`dept_no` in (/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` >= '1995-01-01'))", 28 | "embedded in": "WHERE", 29 | "evaluating_constant_semijoin_conditions": [], 30 | "semi-join condition": "((`a`.`from_date` >= '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))", 31 | "decorrelated_predicates": [ 32 | { 33 | "outer": "`d`.`dept_no`", 34 | "inner": "`a`.`dept_no`" 35 | } 36 | ] 37 | } 38 | } 39 | }, 40 | { 41 | "transformations_to_nested_joins": { 42 | "transformations": [ 43 | "semijoin" 44 | ], 45 | "expanded_query": "/* select#1 */ select /*+ SEMIJOIN(@`select#2` DUPSWEEDOUT) */ `d`.`dept_no` AS `dept_no`,`d`.`dept_name` AS `dept_name` from `departments` `d` semi join (`dept_manager` `a`) where ((`a`.`from_date` >= '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))" 46 | } 47 | } 48 | ] 49 | } 50 | }, 51 | { 52 | "join_optimization": { 53 | "select#": 1, 54 | "steps": [ 55 | { 56 | "condition_processing": { 57 | "condition": "WHERE", 58 | "original_condition": "((`a`.`from_date` >= '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))", 59 | "steps": [ 60 | { 61 | "transformation": "equality_propagation", 62 | "resulting_condition": "((`a`.`from_date` >= '1995-01-01') and multiple equal(`d`.`dept_no`, `a`.`dept_no`))" 63 | }, 64 | { 65 | "transformation": "constant_propagation", 66 | "resulting_condition": "((`a`.`from_date` >= '1995-01-01') and multiple equal(`d`.`dept_no`, `a`.`dept_no`))" 67 | }, 68 | { 69 | "transformation": "trivial_condition_removal", 70 | "resulting_condition": "((`a`.`from_date` >= DATE'1995-01-01') and multiple equal(`d`.`dept_no`, `a`.`dept_no`))" 71 | } 72 | ] 73 | } 74 | }, 75 | { 76 | "substitute_generated_columns": {} 77 | }, 78 | { 79 | "table_dependencies": [ 80 | { 81 | "table": "`departments` `d`", 82 | "row_may_be_null": false, 83 | "map_bit": 0, 84 | "depends_on_map_bits": [] 85 | }, 86 | { 87 | "table": "`dept_manager` `a`", 88 | "row_may_be_null": false, 89 | "map_bit": 1, 90 | "depends_on_map_bits": [] 91 | } 92 | ] 93 | }, 94 | { 95 | "ref_optimizer_key_uses": [ 96 | { 97 | "table": "`departments` `d`", 98 | "field": "dept_no", 99 | "equals": "`a`.`dept_no`", 100 | "null_rejecting": true 101 | }, 102 | { 103 | "table": "`dept_manager` `a`", 104 | "field": "dept_no", 105 | "equals": "`d`.`dept_no`", 106 | "null_rejecting": true 107 | } 108 | ] 109 | }, 110 | { 111 | "pulled_out_semijoin_tables": [] 112 | }, 113 | { 114 | "rows_estimation": [ 115 | { 116 | "table": "`departments` `d`", 117 | "table_scan": { 118 | "rows": 9, 119 | "cost": 0.25 120 | } 121 | }, 122 | { 123 | "table": "`dept_manager` `a`", 124 | "table_scan": { 125 | "rows": 24, 126 | "cost": 0.25 127 | } 128 | } 129 | ] 130 | }, 131 | { 132 | "considered_execution_plans": [ 133 | { 134 | "plan_prefix": [], 135 | "table": "`departments` `d`", 136 | "best_access_path": { 137 | "considered_access_paths": [ 138 | { 139 | "access_type": "ref", 140 | "index": "PRIMARY", 141 | "usable": false, 142 | "chosen": false 143 | }, 144 | { 145 | "rows_to_scan": 9, 146 | "filtering_effect": [], 147 | "final_filtering_effect": 1, 148 | "access_type": "scan", 149 | "resulting_rows": 9, 150 | "cost": 1.15, 151 | "chosen": true 152 | } 153 | ] 154 | }, 155 | "condition_filtering_pct": 100, 156 | "rows_for_plan": 9, 157 | "cost_for_plan": 1.15, 158 | "semijoin_strategy_choice": [], 159 | "rest_of_plan": [ 160 | { 161 | "plan_prefix": [ 162 | "`departments` `d`" 163 | ], 164 | "table": "`dept_manager` `a`", 165 | "best_access_path": { 166 | "considered_access_paths": [ 167 | { 168 | "access_type": "ref", 169 | "index": "dept_no", 170 | "rows": 2.66667, 171 | "cost": 7.8, 172 | "chosen": true 173 | }, 174 | { 175 | "rows_to_scan": 24, 176 | "filtering_effect": [], 177 | "final_filtering_effect": 0.3333, 178 | "access_type": "scan", 179 | "using_join_cache": true, 180 | "buffers_needed": 1, 181 | "resulting_rows": 7.9992, 182 | "cost": 9.0606, 183 | "chosen": false 184 | } 185 | ] 186 | }, 187 | "condition_filtering_pct": 33.33, 188 | "rows_for_plan": 7.9992, 189 | "cost_for_plan": 8.95, 190 | "semijoin_strategy_choice": [ 191 | { 192 | "strategy": "DuplicatesWeedout", 193 | "cost": 11.6499, 194 | "rows": 9, 195 | "duplicate_tables_left": true, 196 | "chosen": true 197 | } 198 | ], 199 | "chosen": true 200 | } 201 | ] 202 | }, 203 | { 204 | "plan_prefix": [], 205 | "table": "`dept_manager` `a`", 206 | "best_access_path": { 207 | "considered_access_paths": [ 208 | { 209 | "access_type": "ref", 210 | "index": "dept_no", 211 | "usable": false, 212 | "chosen": false 213 | }, 214 | { 215 | "rows_to_scan": 24, 216 | "filtering_effect": [], 217 | "final_filtering_effect": 0.3333, 218 | "access_type": "scan", 219 | "resulting_rows": 7.9992, 220 | "cost": 2.65, 221 | "chosen": true 222 | } 223 | ] 224 | }, 225 | "condition_filtering_pct": 100, 226 | "rows_for_plan": 7.9992, 227 | "cost_for_plan": 2.65, 228 | "semijoin_strategy_choice": [], 229 | "rest_of_plan": [ 230 | { 231 | "plan_prefix": [ 232 | "`dept_manager` `a`" 233 | ], 234 | "table": "`departments` `d`", 235 | "best_access_path": { 236 | "considered_access_paths": [ 237 | { 238 | "access_type": "eq_ref", 239 | "index": "PRIMARY", 240 | "rows": 1, 241 | "cost": 2.79972, 242 | "chosen": true, 243 | "cause": "clustered_pk_chosen_by_heuristics" 244 | }, 245 | { 246 | "access_type": "scan", 247 | "chosen": false, 248 | "cause": "covering_index_better_than_full_scan" 249 | } 250 | ] 251 | }, 252 | "condition_filtering_pct": 100, 253 | "rows_for_plan": 7.9992, 254 | "cost_for_plan": 5.44972, 255 | "semijoin_strategy_choice": [ 256 | { 257 | "strategy": "DuplicatesWeedout", 258 | "cost": 8.04956, 259 | "rows": 7.9992, 260 | "duplicate_tables_left": true, 261 | "chosen": true 262 | } 263 | ], 264 | "chosen": true 265 | } 266 | ] 267 | }, 268 | { 269 | "final_semijoin_strategy": "DuplicateWeedout" 270 | } 271 | ] 272 | }, 273 | { 274 | "attaching_conditions_to_tables": { 275 | "original_condition": "((`d`.`dept_no` = `a`.`dept_no`) and (`a`.`from_date` >= DATE'1995-01-01'))", 276 | "attached_conditions_computation": [], 277 | "attached_conditions_summary": [ 278 | { 279 | "table": "`dept_manager` `a`", 280 | "attached": "(`a`.`from_date` >= DATE'1995-01-01')" 281 | }, 282 | { 283 | "table": "`departments` `d`", 284 | "attached": "(`d`.`dept_no` = `a`.`dept_no`)" 285 | } 286 | ] 287 | } 288 | }, 289 | { 290 | "finalizing_table_conditions": [ 291 | { 292 | "table": "`dept_manager` `a`", 293 | "original_table_condition": "(`a`.`from_date` >= DATE'1995-01-01')", 294 | "final_table_condition ": "(`a`.`from_date` >= DATE'1995-01-01')" 295 | }, 296 | { 297 | "table": "`departments` `d`", 298 | "original_table_condition": "(`d`.`dept_no` = `a`.`dept_no`)", 299 | "final_table_condition ": null 300 | } 301 | ] 302 | }, 303 | { 304 | "refine_plan": [ 305 | { 306 | "creating_tmp_table": { 307 | "tmp_table_info": { 308 | "table": "weedout-tmp", 309 | "columns": 1, 310 | "row_length": 18, 311 | "key_length": 16, 312 | "unique_constraint": false, 313 | "makes_grouped_rows": false, 314 | "cannot_insert_duplicates": false, 315 | "location": "TempTable" 316 | } 317 | } 318 | }, 319 | { 320 | "table": "`dept_manager` `a`" 321 | }, 322 | { 323 | "table": "`departments` `d`" 324 | } 325 | ] 326 | } 327 | ] 328 | } 329 | }, 330 | { 331 | "join_execution": { 332 | "select#": 1, 333 | "steps": [] 334 | } 335 | } 336 | ] 337 | } 338 | -------------------------------------------------------------------------------- /assets/subq12_sj_first-match_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "8.95" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "d", 11 | "access_type": "index", 12 | "possible_keys": [ 13 | "PRIMARY" 14 | ], 15 | "key": "dept_name", 16 | "used_key_parts": [ 17 | "dept_name" 18 | ], 19 | "key_length": "162", 20 | "rows_examined_per_scan": 9, 21 | "rows_produced_per_join": 9, 22 | "filtered": "100.00", 23 | "using_index": true, 24 | "cost_info": { 25 | "read_cost": "0.25", 26 | "eval_cost": "0.90", 27 | "prefix_cost": "1.15", 28 | "data_read_per_join": "1K" 29 | }, 30 | "used_columns": [ 31 | "dept_no", 32 | "dept_name" 33 | ] 34 | } 35 | }, 36 | { 37 | "table": { 38 | "table_name": "a", 39 | "access_type": "ref", 40 | "possible_keys": [ 41 | "dept_no" 42 | ], 43 | "key": "dept_no", 44 | "used_key_parts": [ 45 | "dept_no" 46 | ], 47 | "key_length": "16", 48 | "ref": [ 49 | "employees.d.dept_no" 50 | ], 51 | "rows_examined_per_scan": 2, 52 | "rows_produced_per_join": 9, 53 | "filtered": "33.33", 54 | "first_match": "d", 55 | "cost_info": { 56 | "read_cost": "5.40", 57 | "eval_cost": "0.90", 58 | "prefix_cost": "8.95", 59 | "data_read_per_join": "288" 60 | }, 61 | "used_columns": [ 62 | "dept_no", 63 | "from_date" 64 | ], 65 | "attached_condition": "(`employees`.`a`.`from_date` >= DATE'1995-01-01')" 66 | } 67 | } 68 | ] 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /assets/subq12_sj_first-match_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "join_preparation": { 9 | "select#": 2, 10 | "steps": [ 11 | { 12 | "expanded_query": "/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` >= '1995-01-01')" 13 | } 14 | ] 15 | } 16 | }, 17 | { 18 | "expanded_query": "/* select#1 */ select /*+ SEMIJOIN(@`select#2` FIRSTMATCH) */ `d`.`dept_no` AS `dept_no`,`d`.`dept_name` AS `dept_name` from `departments` `d` where `d`.`dept_no` in (/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` >= '1995-01-01'))" 19 | }, 20 | { 21 | "transformation": { 22 | "select#": 2, 23 | "from": "IN (SELECT)", 24 | "to": "semijoin", 25 | "chosen": true, 26 | "transformation_to_semi_join": { 27 | "subquery_predicate": "`d`.`dept_no` in (/* select#2 */ select `a`.`dept_no` from `dept_manager` `a` where (`a`.`from_date` >= '1995-01-01'))", 28 | "embedded in": "WHERE", 29 | "evaluating_constant_semijoin_conditions": [], 30 | "semi-join condition": "((`a`.`from_date` >= '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))", 31 | "decorrelated_predicates": [ 32 | { 33 | "outer": "`d`.`dept_no`", 34 | "inner": "`a`.`dept_no`" 35 | } 36 | ] 37 | } 38 | } 39 | }, 40 | { 41 | "transformations_to_nested_joins": { 42 | "transformations": [ 43 | "semijoin" 44 | ], 45 | "expanded_query": "/* select#1 */ select /*+ SEMIJOIN(@`select#2` FIRSTMATCH) */ `d`.`dept_no` AS `dept_no`,`d`.`dept_name` AS `dept_name` from `departments` `d` semi join (`dept_manager` `a`) where ((`a`.`from_date` >= '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))" 46 | } 47 | } 48 | ] 49 | } 50 | }, 51 | { 52 | "join_optimization": { 53 | "select#": 1, 54 | "steps": [ 55 | { 56 | "condition_processing": { 57 | "condition": "WHERE", 58 | "original_condition": "((`a`.`from_date` >= '1995-01-01') and (`d`.`dept_no` = `a`.`dept_no`))", 59 | "steps": [ 60 | { 61 | "transformation": "equality_propagation", 62 | "resulting_condition": "((`a`.`from_date` >= '1995-01-01') and multiple equal(`d`.`dept_no`, `a`.`dept_no`))" 63 | }, 64 | { 65 | "transformation": "constant_propagation", 66 | "resulting_condition": "((`a`.`from_date` >= '1995-01-01') and multiple equal(`d`.`dept_no`, `a`.`dept_no`))" 67 | }, 68 | { 69 | "transformation": "trivial_condition_removal", 70 | "resulting_condition": "((`a`.`from_date` >= DATE'1995-01-01') and multiple equal(`d`.`dept_no`, `a`.`dept_no`))" 71 | } 72 | ] 73 | } 74 | }, 75 | { 76 | "substitute_generated_columns": {} 77 | }, 78 | { 79 | "table_dependencies": [ 80 | { 81 | "table": "`departments` `d`", 82 | "row_may_be_null": false, 83 | "map_bit": 0, 84 | "depends_on_map_bits": [] 85 | }, 86 | { 87 | "table": "`dept_manager` `a`", 88 | "row_may_be_null": false, 89 | "map_bit": 1, 90 | "depends_on_map_bits": [] 91 | } 92 | ] 93 | }, 94 | { 95 | "ref_optimizer_key_uses": [ 96 | { 97 | "table": "`departments` `d`", 98 | "field": "dept_no", 99 | "equals": "`a`.`dept_no`", 100 | "null_rejecting": true 101 | }, 102 | { 103 | "table": "`dept_manager` `a`", 104 | "field": "dept_no", 105 | "equals": "`d`.`dept_no`", 106 | "null_rejecting": true 107 | } 108 | ] 109 | }, 110 | { 111 | "pulled_out_semijoin_tables": [] 112 | }, 113 | { 114 | "rows_estimation": [ 115 | { 116 | "table": "`departments` `d`", 117 | "table_scan": { 118 | "rows": 9, 119 | "cost": 0.25 120 | } 121 | }, 122 | { 123 | "table": "`dept_manager` `a`", 124 | "table_scan": { 125 | "rows": 24, 126 | "cost": 0.25 127 | } 128 | } 129 | ] 130 | }, 131 | { 132 | "considered_execution_plans": [ 133 | { 134 | "plan_prefix": [], 135 | "table": "`departments` `d`", 136 | "best_access_path": { 137 | "considered_access_paths": [ 138 | { 139 | "access_type": "ref", 140 | "index": "PRIMARY", 141 | "usable": false, 142 | "chosen": false 143 | }, 144 | { 145 | "rows_to_scan": 9, 146 | "filtering_effect": [], 147 | "final_filtering_effect": 1, 148 | "access_type": "scan", 149 | "resulting_rows": 9, 150 | "cost": 1.15, 151 | "chosen": true 152 | } 153 | ] 154 | }, 155 | "condition_filtering_pct": 100, 156 | "rows_for_plan": 9, 157 | "cost_for_plan": 1.15, 158 | "semijoin_strategy_choice": [], 159 | "rest_of_plan": [ 160 | { 161 | "plan_prefix": [ 162 | "`departments` `d`" 163 | ], 164 | "table": "`dept_manager` `a`", 165 | "best_access_path": { 166 | "considered_access_paths": [ 167 | { 168 | "access_type": "ref", 169 | "index": "dept_no", 170 | "rows": 2.66667, 171 | "cost": 7.8, 172 | "chosen": true 173 | }, 174 | { 175 | "rows_to_scan": 24, 176 | "filtering_effect": [], 177 | "final_filtering_effect": 0.3333, 178 | "access_type": "scan", 179 | "using_join_cache": true, 180 | "buffers_needed": 1, 181 | "resulting_rows": 7.9992, 182 | "cost": 9.0606, 183 | "chosen": false 184 | } 185 | ] 186 | }, 187 | "condition_filtering_pct": 33.33, 188 | "rows_for_plan": 7.9992, 189 | "cost_for_plan": 8.95, 190 | "semijoin_strategy_choice": [ 191 | { 192 | "strategy": "FirstMatch", 193 | "recalculate_access_paths_and_cost": { 194 | "tables": [] 195 | }, 196 | "cost": 8.95, 197 | "rows": 9, 198 | "chosen": true 199 | }, 200 | { 201 | "strategy": "DuplicatesWeedout", 202 | "cost": 11.6499, 203 | "rows": 9, 204 | "duplicate_tables_left": false, 205 | "chosen": false 206 | } 207 | ], 208 | "chosen": true 209 | } 210 | ] 211 | }, 212 | { 213 | "plan_prefix": [], 214 | "table": "`dept_manager` `a`", 215 | "best_access_path": { 216 | "considered_access_paths": [ 217 | { 218 | "access_type": "ref", 219 | "index": "dept_no", 220 | "usable": false, 221 | "chosen": false 222 | }, 223 | { 224 | "rows_to_scan": 24, 225 | "filtering_effect": [], 226 | "final_filtering_effect": 0.3333, 227 | "access_type": "scan", 228 | "resulting_rows": 7.9992, 229 | "cost": 2.65, 230 | "chosen": true 231 | } 232 | ] 233 | }, 234 | "condition_filtering_pct": 100, 235 | "rows_for_plan": 7.9992, 236 | "cost_for_plan": 2.65, 237 | "semijoin_strategy_choice": [], 238 | "rest_of_plan": [ 239 | { 240 | "plan_prefix": [ 241 | "`dept_manager` `a`" 242 | ], 243 | "table": "`departments` `d`", 244 | "best_access_path": { 245 | "considered_access_paths": [ 246 | { 247 | "access_type": "eq_ref", 248 | "index": "PRIMARY", 249 | "rows": 1, 250 | "cost": 2.79972, 251 | "chosen": true, 252 | "cause": "clustered_pk_chosen_by_heuristics" 253 | }, 254 | { 255 | "access_type": "scan", 256 | "chosen": false, 257 | "cause": "covering_index_better_than_full_scan" 258 | } 259 | ] 260 | }, 261 | "condition_filtering_pct": 100, 262 | "rows_for_plan": 7.9992, 263 | "cost_for_plan": 5.44972, 264 | "semijoin_strategy_choice": [ 265 | { 266 | "strategy": "DuplicatesWeedout", 267 | "cost": 8.04956, 268 | "rows": 7.9992, 269 | "duplicate_tables_left": true, 270 | "chosen": true 271 | } 272 | ], 273 | "chosen": false, 274 | "cause": "plan_uses_disabled_strategy" 275 | } 276 | ] 277 | }, 278 | { 279 | "final_semijoin_strategy": "FirstMatch", 280 | "recalculate_access_paths_and_cost": { 281 | "tables": [] 282 | } 283 | } 284 | ] 285 | }, 286 | { 287 | "attaching_conditions_to_tables": { 288 | "original_condition": "((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`from_date` >= DATE'1995-01-01'))", 289 | "attached_conditions_computation": [], 290 | "attached_conditions_summary": [ 291 | { 292 | "table": "`departments` `d`", 293 | "attached": null 294 | }, 295 | { 296 | "table": "`dept_manager` `a`", 297 | "attached": "((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`from_date` >= DATE'1995-01-01'))" 298 | } 299 | ] 300 | } 301 | }, 302 | { 303 | "finalizing_table_conditions": [ 304 | { 305 | "table": "`dept_manager` `a`", 306 | "original_table_condition": "((`a`.`dept_no` = `d`.`dept_no`) and (`a`.`from_date` >= DATE'1995-01-01'))", 307 | "final_table_condition ": "(`a`.`from_date` >= DATE'1995-01-01')" 308 | } 309 | ] 310 | }, 311 | { 312 | "refine_plan": [ 313 | { 314 | "table": "`departments` `d`" 315 | }, 316 | { 317 | "table": "`dept_manager` `a`" 318 | } 319 | ] 320 | } 321 | ] 322 | } 323 | }, 324 | { 325 | "join_execution": { 326 | "select#": 1, 327 | "steps": [] 328 | } 329 | } 330 | ] 331 | } 332 | -------------------------------------------------------------------------------- /assets/subq13_sj_loose-scan_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "8.05" 6 | }, 7 | "duplicates_removal": { 8 | "using_temporary_table": true, 9 | "nested_loop": [ 10 | { 11 | "table": { 12 | "table_name": "a", 13 | "access_type": "ALL", 14 | "possible_keys": [ 15 | "dept_no" 16 | ], 17 | "rows_examined_per_scan": 24, 18 | "rows_produced_per_join": 7, 19 | "filtered": "33.33", 20 | "cost_info": { 21 | "read_cost": "1.85", 22 | "eval_cost": "0.80", 23 | "prefix_cost": "2.65", 24 | "data_read_per_join": "255" 25 | }, 26 | "used_columns": [ 27 | "dept_no", 28 | "from_date" 29 | ], 30 | "attached_condition": "(`employees`.`a`.`from_date` >= DATE'1995-01-01')" 31 | } 32 | }, 33 | { 34 | "table": { 35 | "table_name": "d", 36 | "access_type": "eq_ref", 37 | "possible_keys": [ 38 | "PRIMARY" 39 | ], 40 | "key": "PRIMARY", 41 | "used_key_parts": [ 42 | "dept_no" 43 | ], 44 | "key_length": "16", 45 | "ref": [ 46 | "employees.a.dept_no" 47 | ], 48 | "rows_examined_per_scan": 1, 49 | "rows_produced_per_join": 7, 50 | "filtered": "100.00", 51 | "cost_info": { 52 | "read_cost": "2.00", 53 | "eval_cost": "0.80", 54 | "prefix_cost": "8.05", 55 | "data_read_per_join": "1K" 56 | }, 57 | "used_columns": [ 58 | "dept_no", 59 | "dept_name" 60 | ] 61 | } 62 | } 63 | ] 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /assets/subq14_sj_materialization_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "6.50" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "d", 11 | "access_type": "index", 12 | "possible_keys": [ 13 | "PRIMARY" 14 | ], 15 | "key": "dept_name", 16 | "used_key_parts": [ 17 | "dept_name" 18 | ], 19 | "key_length": "162", 20 | "rows_examined_per_scan": 9, 21 | "rows_produced_per_join": 9, 22 | "filtered": "100.00", 23 | "using_index": true, 24 | "cost_info": { 25 | "read_cost": "0.25", 26 | "eval_cost": "0.90", 27 | "prefix_cost": "1.15", 28 | "data_read_per_join": "1K" 29 | }, 30 | "used_columns": [ 31 | "dept_no", 32 | "dept_name" 33 | ] 34 | } 35 | }, 36 | { 37 | "table": { 38 | "table_name": "", 39 | "access_type": "eq_ref", 40 | "key": "", 41 | "key_length": "16", 42 | "ref": [ 43 | "employees.d.dept_no" 44 | ], 45 | "rows_examined_per_scan": 1, 46 | "materialized_from_subquery": { 47 | "using_temporary_table": true, 48 | "query_block": { 49 | "table": { 50 | "table_name": "a", 51 | "access_type": "ALL", 52 | "possible_keys": [ 53 | "dept_no" 54 | ], 55 | "rows_examined_per_scan": 24, 56 | "rows_produced_per_join": 7, 57 | "filtered": "33.33", 58 | "cost_info": { 59 | "read_cost": "1.85", 60 | "eval_cost": "0.80", 61 | "prefix_cost": "2.65", 62 | "data_read_per_join": "255" 63 | }, 64 | "used_columns": [ 65 | "dept_no", 66 | "from_date" 67 | ], 68 | "attached_condition": "(`employees`.`a`.`from_date` >= DATE'1995-01-01')" 69 | } 70 | } 71 | } 72 | } 73 | } 74 | ] 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /assets/subq20_sj_default_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "10.39" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "a", 11 | "access_type": "index", 12 | "possible_keys": [ 13 | "PRIMARY", 14 | "dept_no" 15 | ], 16 | "key": "PRIMARY", 17 | "used_key_parts": [ 18 | "emp_no", 19 | "dept_no" 20 | ], 21 | "key_length": "20", 22 | "rows_examined_per_scan": 24, 23 | "rows_produced_per_join": 24, 24 | "filtered": "100.00", 25 | "using_index": true, 26 | "loosescan": true, 27 | "cost_info": { 28 | "read_cost": "0.28", 29 | "eval_cost": "2.40", 30 | "prefix_cost": "2.68", 31 | "data_read_per_join": "768" 32 | }, 33 | "used_columns": [ 34 | "emp_no", 35 | "dept_no" 36 | ], 37 | "attached_condition": "(`employees`.`a`.`dept_no` >= 'd003')" 38 | } 39 | }, 40 | { 41 | "table": { 42 | "table_name": "e", 43 | "access_type": "eq_ref", 44 | "possible_keys": [ 45 | "PRIMARY" 46 | ], 47 | "key": "PRIMARY", 48 | "used_key_parts": [ 49 | "emp_no" 50 | ], 51 | "key_length": "4", 52 | "ref": [ 53 | "employees.a.emp_no" 54 | ], 55 | "rows_examined_per_scan": 1, 56 | "rows_produced_per_join": 1, 57 | "filtered": "100.00", 58 | "cost_info": { 59 | "read_cost": "5.31", 60 | "eval_cost": "0.10", 61 | "prefix_cost": "10.39", 62 | "data_read_per_join": "136" 63 | }, 64 | "used_columns": [ 65 | "emp_no", 66 | "birth_date", 67 | "first_name", 68 | "last_name", 69 | "gender", 70 | "hire_date" 71 | ] 72 | } 73 | } 74 | ] 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /assets/subq21_sj_duplicate-weedout_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "16.59" 6 | }, 7 | "duplicates_removal": { 8 | "using_temporary_table": true, 9 | "nested_loop": [ 10 | { 11 | "table": { 12 | "table_name": "a", 13 | "access_type": "range", 14 | "possible_keys": [ 15 | "PRIMARY", 16 | "dept_no" 17 | ], 18 | "key": "dept_no", 19 | "used_key_parts": [ 20 | "dept_no" 21 | ], 22 | "key_length": "16", 23 | "rows_examined_per_scan": 20, 24 | "rows_produced_per_join": 20, 25 | "filtered": "100.00", 26 | "using_index": true, 27 | "cost_info": { 28 | "read_cost": "2.28", 29 | "eval_cost": "2.00", 30 | "prefix_cost": "4.28", 31 | "data_read_per_join": "640" 32 | }, 33 | "used_columns": [ 34 | "emp_no", 35 | "dept_no" 36 | ], 37 | "attached_condition": "(`employees`.`a`.`dept_no` >= 'd003')" 38 | } 39 | }, 40 | { 41 | "table": { 42 | "table_name": "e", 43 | "access_type": "eq_ref", 44 | "possible_keys": [ 45 | "PRIMARY" 46 | ], 47 | "key": "PRIMARY", 48 | "used_key_parts": [ 49 | "emp_no" 50 | ], 51 | "key_length": "4", 52 | "ref": [ 53 | "employees.a.emp_no" 54 | ], 55 | "rows_examined_per_scan": 1, 56 | "rows_produced_per_join": 20, 57 | "filtered": "100.00", 58 | "cost_info": { 59 | "read_cost": "5.31", 60 | "eval_cost": "2.00", 61 | "prefix_cost": "16.59", 62 | "data_read_per_join": "2K" 63 | }, 64 | "used_columns": [ 65 | "emp_no", 66 | "birth_date", 67 | "first_name", 68 | "last_name", 69 | "gender", 70 | "hire_date" 71 | ] 72 | } 73 | } 74 | ] 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /assets/subq21_sj_duplicate-weedout_opt.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "join_preparation": { 5 | "select#": 1, 6 | "steps": [ 7 | { 8 | "join_preparation": { 9 | "select#": 2, 10 | "steps": [ 11 | { 12 | "expanded_query": "/* select#2 */ select `a`.`emp_no` from `dept_manager` `a` where (`a`.`dept_no` >= 'd003')" 13 | } 14 | ] 15 | } 16 | }, 17 | { 18 | "expanded_query": "/* select#1 */ select /*+ SEMIJOIN(@`select#2` DUPSWEEDOUT) */ `e`.`emp_no` AS `emp_no`,`e`.`birth_date` AS `birth_date`,`e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name`,`e`.`gender` AS `gender`,`e`.`hire_date` AS `hire_date` from `employees` `e` where `e`.`emp_no` in (/* select#2 */ select `a`.`emp_no` from `dept_manager` `a` where (`a`.`dept_no` >= 'd003'))" 19 | }, 20 | { 21 | "transformation": { 22 | "select#": 2, 23 | "from": "IN (SELECT)", 24 | "to": "semijoin", 25 | "chosen": true, 26 | "transformation_to_semi_join": { 27 | "subquery_predicate": "`e`.`emp_no` in (/* select#2 */ select `a`.`emp_no` from `dept_manager` `a` where (`a`.`dept_no` >= 'd003'))", 28 | "embedded in": "WHERE", 29 | "evaluating_constant_semijoin_conditions": [], 30 | "semi-join condition": "((`a`.`dept_no` >= 'd003') and (`e`.`emp_no` = `a`.`emp_no`))", 31 | "decorrelated_predicates": [ 32 | { 33 | "outer": "`e`.`emp_no`", 34 | "inner": "`a`.`emp_no`" 35 | } 36 | ] 37 | } 38 | } 39 | }, 40 | { 41 | "transformations_to_nested_joins": { 42 | "transformations": [ 43 | "semijoin" 44 | ], 45 | "expanded_query": "/* select#1 */ select /*+ SEMIJOIN(@`select#2` DUPSWEEDOUT) */ `e`.`emp_no` AS `emp_no`,`e`.`birth_date` AS `birth_date`,`e`.`first_name` AS `first_name`,`e`.`last_name` AS `last_name`,`e`.`gender` AS `gender`,`e`.`hire_date` AS `hire_date` from `employees` `e` semi join (`dept_manager` `a`) where ((`a`.`dept_no` >= 'd003') and (`e`.`emp_no` = `a`.`emp_no`))" 46 | } 47 | } 48 | ] 49 | } 50 | }, 51 | { 52 | "join_optimization": { 53 | "select#": 1, 54 | "steps": [ 55 | { 56 | "condition_processing": { 57 | "condition": "WHERE", 58 | "original_condition": "((`a`.`dept_no` >= 'd003') and (`e`.`emp_no` = `a`.`emp_no`))", 59 | "steps": [ 60 | { 61 | "transformation": "equality_propagation", 62 | "resulting_condition": "((`a`.`dept_no` >= 'd003') and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 63 | }, 64 | { 65 | "transformation": "constant_propagation", 66 | "resulting_condition": "((`a`.`dept_no` >= 'd003') and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 67 | }, 68 | { 69 | "transformation": "trivial_condition_removal", 70 | "resulting_condition": "((`a`.`dept_no` >= 'd003') and multiple equal(`e`.`emp_no`, `a`.`emp_no`))" 71 | } 72 | ] 73 | } 74 | }, 75 | { 76 | "substitute_generated_columns": {} 77 | }, 78 | { 79 | "table_dependencies": [ 80 | { 81 | "table": "`employees` `e`", 82 | "row_may_be_null": false, 83 | "map_bit": 0, 84 | "depends_on_map_bits": [] 85 | }, 86 | { 87 | "table": "`dept_manager` `a`", 88 | "row_may_be_null": false, 89 | "map_bit": 1, 90 | "depends_on_map_bits": [] 91 | } 92 | ] 93 | }, 94 | { 95 | "ref_optimizer_key_uses": [ 96 | { 97 | "table": "`employees` `e`", 98 | "field": "emp_no", 99 | "equals": "`a`.`emp_no`", 100 | "null_rejecting": true 101 | }, 102 | { 103 | "table": "`dept_manager` `a`", 104 | "field": "emp_no", 105 | "equals": "`e`.`emp_no`", 106 | "null_rejecting": true 107 | } 108 | ] 109 | }, 110 | { 111 | "pulled_out_semijoin_tables": [] 112 | }, 113 | { 114 | "rows_estimation": [ 115 | { 116 | "table": "`employees` `e`", 117 | "table_scan": { 118 | "rows": 276023, 119 | "cost": 229.749 120 | } 121 | }, 122 | { 123 | "table": "`dept_manager` `a`", 124 | "range_analysis": { 125 | "table_scan": { 126 | "rows": 24, 127 | "cost": 4.75 128 | }, 129 | "potential_range_indexes": [ 130 | { 131 | "index": "PRIMARY", 132 | "usable": false, 133 | "cause": "not_applicable" 134 | }, 135 | { 136 | "index": "dept_no", 137 | "usable": true, 138 | "key_parts": [ 139 | "dept_no", 140 | "emp_no" 141 | ] 142 | } 143 | ], 144 | "best_covering_index_scan": { 145 | "index": "dept_no", 146 | "cost": 2.67522, 147 | "chosen": true 148 | }, 149 | "setup_range_conditions": [], 150 | "group_index_range": { 151 | "chosen": false, 152 | "cause": "not_single_table" 153 | }, 154 | "skip_scan_range": { 155 | "chosen": false, 156 | "cause": "not_single_table" 157 | }, 158 | "analyzing_range_alternatives": { 159 | "range_scan_alternatives": [ 160 | { 161 | "index": "dept_no", 162 | "ranges": [ 163 | "'d003' <= dept_no" 164 | ], 165 | "index_dives_for_eq_ranges": true, 166 | "rowid_ordered": false, 167 | "using_mrr": false, 168 | "index_only": true, 169 | "in_memory": 1, 170 | "rows": 20, 171 | "cost": 2.28083, 172 | "chosen": true 173 | } 174 | ], 175 | "analyzing_roworder_intersect": { 176 | "usable": false, 177 | "cause": "too_few_roworder_scans" 178 | } 179 | }, 180 | "chosen_range_access_summary": { 181 | "range_access_plan": { 182 | "type": "range_scan", 183 | "index": "dept_no", 184 | "rows": 20, 185 | "ranges": [ 186 | "'d003' <= dept_no" 187 | ] 188 | }, 189 | "rows_for_plan": 20, 190 | "cost_for_plan": 2.28083, 191 | "chosen": true 192 | } 193 | } 194 | } 195 | ] 196 | }, 197 | { 198 | "considered_execution_plans": [ 199 | { 200 | "plan_prefix": [], 201 | "table": "`dept_manager` `a`", 202 | "best_access_path": { 203 | "considered_access_paths": [ 204 | { 205 | "access_type": "ref", 206 | "index": "PRIMARY", 207 | "usable": false, 208 | "chosen": false 209 | }, 210 | { 211 | "rows_to_scan": 20, 212 | "filtering_effect": [], 213 | "final_filtering_effect": 1, 214 | "access_type": "range", 215 | "range_details": { 216 | "used_index": "dept_no" 217 | }, 218 | "resulting_rows": 20, 219 | "cost": 4.28083, 220 | "chosen": true 221 | } 222 | ] 223 | }, 224 | "condition_filtering_pct": 100, 225 | "rows_for_plan": 20, 226 | "cost_for_plan": 4.28083, 227 | "semijoin_strategy_choice": [], 228 | "rest_of_plan": [ 229 | { 230 | "plan_prefix": [ 231 | "`dept_manager` `a`" 232 | ], 233 | "table": "`employees` `e`", 234 | "best_access_path": { 235 | "considered_access_paths": [ 236 | { 237 | "access_type": "eq_ref", 238 | "index": "PRIMARY", 239 | "rows": 1, 240 | "cost": 7.31212, 241 | "chosen": true, 242 | "cause": "clustered_pk_chosen_by_heuristics" 243 | }, 244 | { 245 | "access_type": "scan", 246 | "cost": 27832, 247 | "rows": 276023, 248 | "chosen": false, 249 | "cause": "cost" 250 | } 251 | ] 252 | }, 253 | "condition_filtering_pct": 100, 254 | "rows_for_plan": 20, 255 | "cost_for_plan": 11.593, 256 | "semijoin_strategy_choice": [ 257 | { 258 | "strategy": "DuplicatesWeedout", 259 | "cost": 16.593, 260 | "rows": 20, 261 | "duplicate_tables_left": true, 262 | "chosen": true 263 | } 264 | ], 265 | "chosen": true 266 | } 267 | ] 268 | }, 269 | { 270 | "plan_prefix": [], 271 | "table": "`employees` `e`", 272 | "best_access_path": { 273 | "considered_access_paths": [ 274 | { 275 | "access_type": "ref", 276 | "index": "PRIMARY", 277 | "usable": false, 278 | "chosen": false 279 | }, 280 | { 281 | "rows_to_scan": 276023, 282 | "filtering_effect": [], 283 | "final_filtering_effect": 1, 284 | "access_type": "scan", 285 | "resulting_rows": 276023, 286 | "cost": 27832, 287 | "chosen": true 288 | } 289 | ] 290 | }, 291 | "condition_filtering_pct": 100, 292 | "rows_for_plan": 276023, 293 | "cost_for_plan": 27832, 294 | "semijoin_strategy_choice": [], 295 | "pruned_by_cost": true 296 | }, 297 | { 298 | "final_semijoin_strategy": "DuplicateWeedout" 299 | } 300 | ] 301 | }, 302 | { 303 | "attaching_conditions_to_tables": { 304 | "original_condition": "((`e`.`emp_no` = `a`.`emp_no`) and (`a`.`dept_no` >= 'd003'))", 305 | "attached_conditions_computation": [], 306 | "attached_conditions_summary": [ 307 | { 308 | "table": "`dept_manager` `a`", 309 | "attached": "(`a`.`dept_no` >= 'd003')" 310 | }, 311 | { 312 | "table": "`employees` `e`", 313 | "attached": "(`e`.`emp_no` = `a`.`emp_no`)" 314 | } 315 | ] 316 | } 317 | }, 318 | { 319 | "finalizing_table_conditions": [ 320 | { 321 | "table": "`dept_manager` `a`", 322 | "original_table_condition": "(`a`.`dept_no` >= 'd003')", 323 | "final_table_condition ": "(`a`.`dept_no` >= 'd003')" 324 | }, 325 | { 326 | "table": "`employees` `e`", 327 | "original_table_condition": "(`e`.`emp_no` = `a`.`emp_no`)", 328 | "final_table_condition ": null 329 | } 330 | ] 331 | }, 332 | { 333 | "refine_plan": [ 334 | { 335 | "creating_tmp_table": { 336 | "tmp_table_info": { 337 | "table": "weedout-tmp", 338 | "columns": 1, 339 | "row_length": 6, 340 | "key_length": 4, 341 | "unique_constraint": false, 342 | "makes_grouped_rows": false, 343 | "cannot_insert_duplicates": false, 344 | "location": "TempTable" 345 | } 346 | } 347 | }, 348 | { 349 | "table": "`dept_manager` `a`" 350 | }, 351 | { 352 | "table": "`employees` `e`" 353 | } 354 | ] 355 | } 356 | ] 357 | } 358 | }, 359 | { 360 | "join_execution": { 361 | "select#": 1, 362 | "steps": [] 363 | } 364 | } 365 | ] 366 | } 367 | -------------------------------------------------------------------------------- /assets/subq22_sj_first-match_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "124440.10" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "e", 11 | "access_type": "ALL", 12 | "possible_keys": [ 13 | "PRIMARY" 14 | ], 15 | "rows_examined_per_scan": 276023, 16 | "rows_produced_per_join": 276023, 17 | "filtered": "100.00", 18 | "cost_info": { 19 | "read_cost": "229.75", 20 | "eval_cost": "27602.30", 21 | "prefix_cost": "27832.05", 22 | "data_read_per_join": "35M" 23 | }, 24 | "used_columns": [ 25 | "emp_no", 26 | "birth_date", 27 | "first_name", 28 | "last_name", 29 | "gender", 30 | "hire_date" 31 | ] 32 | } 33 | }, 34 | { 35 | "table": { 36 | "table_name": "a", 37 | "access_type": "ref", 38 | "possible_keys": [ 39 | "PRIMARY", 40 | "dept_no" 41 | ], 42 | "key": "PRIMARY", 43 | "used_key_parts": [ 44 | "emp_no" 45 | ], 46 | "key_length": "4", 47 | "ref": [ 48 | "employees.e.emp_no" 49 | ], 50 | "rows_examined_per_scan": 1, 51 | "rows_produced_per_join": 276023, 52 | "filtered": "83.33", 53 | "using_index": true, 54 | "first_match": "e", 55 | "cost_info": { 56 | "read_cost": "69005.75", 57 | "eval_cost": "27602.30", 58 | "prefix_cost": "124440.10", 59 | "data_read_per_join": "8M" 60 | }, 61 | "used_columns": [ 62 | "emp_no", 63 | "dept_no" 64 | ], 65 | "attached_condition": "(`employees`.`a`.`dept_no` >= 'd003')" 66 | } 67 | } 68 | ] 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /assets/subq23_sj_loose-scan_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "10.39" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "a", 11 | "access_type": "index", 12 | "possible_keys": [ 13 | "PRIMARY", 14 | "dept_no" 15 | ], 16 | "key": "PRIMARY", 17 | "used_key_parts": [ 18 | "emp_no", 19 | "dept_no" 20 | ], 21 | "key_length": "20", 22 | "rows_examined_per_scan": 24, 23 | "rows_produced_per_join": 24, 24 | "filtered": "100.00", 25 | "using_index": true, 26 | "loosescan": true, 27 | "cost_info": { 28 | "read_cost": "0.28", 29 | "eval_cost": "2.40", 30 | "prefix_cost": "2.68", 31 | "data_read_per_join": "768" 32 | }, 33 | "used_columns": [ 34 | "emp_no", 35 | "dept_no" 36 | ], 37 | "attached_condition": "(`employees`.`a`.`dept_no` >= 'd003')" 38 | } 39 | }, 40 | { 41 | "table": { 42 | "table_name": "e", 43 | "access_type": "eq_ref", 44 | "possible_keys": [ 45 | "PRIMARY" 46 | ], 47 | "key": "PRIMARY", 48 | "used_key_parts": [ 49 | "emp_no" 50 | ], 51 | "key_length": "4", 52 | "ref": [ 53 | "employees.a.emp_no" 54 | ], 55 | "rows_examined_per_scan": 1, 56 | "rows_produced_per_join": 1, 57 | "filtered": "100.00", 58 | "cost_info": { 59 | "read_cost": "5.31", 60 | "eval_cost": "0.10", 61 | "prefix_cost": "10.39", 62 | "data_read_per_join": "136" 63 | }, 64 | "used_columns": [ 65 | "emp_no", 66 | "birth_date", 67 | "first_name", 68 | "last_name", 69 | "gender", 70 | "hire_date" 71 | ] 72 | } 73 | } 74 | ] 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /assets/subq24_sj_materialization_exp.sql.json: -------------------------------------------------------------------------------- 1 | { 2 | "query_block": { 3 | "select_id": 1, 4 | "cost_info": { 5 | "query_cost": "16.59" 6 | }, 7 | "nested_loop": [ 8 | { 9 | "table": { 10 | "table_name": "", 11 | "access_type": "ALL", 12 | "materialized_from_subquery": { 13 | "using_temporary_table": true, 14 | "query_block": { 15 | "table": { 16 | "table_name": "a", 17 | "access_type": "range", 18 | "possible_keys": [ 19 | "PRIMARY", 20 | "dept_no" 21 | ], 22 | "key": "dept_no", 23 | "used_key_parts": [ 24 | "dept_no" 25 | ], 26 | "key_length": "16", 27 | "rows_examined_per_scan": 20, 28 | "rows_produced_per_join": 20, 29 | "filtered": "100.00", 30 | "using_index": true, 31 | "cost_info": { 32 | "read_cost": "2.28", 33 | "eval_cost": "2.00", 34 | "prefix_cost": "4.28", 35 | "data_read_per_join": "640" 36 | }, 37 | "used_columns": [ 38 | "emp_no", 39 | "dept_no" 40 | ], 41 | "attached_condition": "(`employees`.`a`.`dept_no` >= 'd003')" 42 | } 43 | } 44 | } 45 | } 46 | }, 47 | { 48 | "table": { 49 | "table_name": "e", 50 | "access_type": "eq_ref", 51 | "possible_keys": [ 52 | "PRIMARY" 53 | ], 54 | "key": "PRIMARY", 55 | "used_key_parts": [ 56 | "emp_no" 57 | ], 58 | "key_length": "4", 59 | "ref": [ 60 | ".emp_no" 61 | ], 62 | "rows_examined_per_scan": 1, 63 | "rows_produced_per_join": 1, 64 | "filtered": "100.00", 65 | "cost_info": { 66 | "read_cost": "0.27", 67 | "eval_cost": "0.10", 68 | "prefix_cost": "16.59", 69 | "data_read_per_join": "136" 70 | }, 71 | "used_columns": [ 72 | "emp_no", 73 | "birth_date", 74 | "first_name", 75 | "last_name", 76 | "gender", 77 | "hire_date" 78 | ] 79 | } 80 | } 81 | ] 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /assets/thd-name-ref.org: -------------------------------------------------------------------------------- 1 | #+TITLE: MySQL 系统线程名称和性能视图表名称对应 2 | #+AUTHOR: Jinghui Hu 3 | #+EMAIL: hujinghui@buaa.edu.cn 4 | #+DATE: <2024-05-21 Tue> 5 | #+STARTUP: overview num indent 6 | #+OPTIONS: ^:nil 7 | 8 | 9 | | os_thd_id | os_name | pfs_thd_id | thd_name | 10 | |-----------+-----------------+------------+---------------------------------------------| 11 | | 73190 | mysqld | 73190 | thread/sql/main | 12 | | 73193 | ib_io_ibuf | 73193 | thread/innodb/io_ibuf_thread | 13 | | 73194 | ib_io_rd-1 | 73194 | thread/innodb/io_read_thread | 14 | | 73195 | ib_io_rd-2 | 73195 | thread/innodb/io_read_thread | 15 | | 73196 | ib_io_rd-3 | 73196 | thread/innodb/io_read_thread | 16 | | 73197 | ib_io_rd-4 | 73197 | thread/innodb/io_read_thread | 17 | | 73198 | ib_io_wr-1 | 73198 | thread/innodb/io_write_thread | 18 | | 73199 | ib_io_wr-2 | 73199 | thread/innodb/io_write_thread | 19 | | 73200 | ib_io_wr-3 | 73200 | thread/innodb/io_write_thread | 20 | | 73201 | ib_io_wr-4 | 73201 | thread/innodb/io_write_thread | 21 | | 73202 | ib_pg_flush_co | 73202 | thread/innodb/page_flush_coordinator_thread | 22 | | 73203 | ib_log_checkpt | 73203 | thread/innodb/log_checkpointer_thread | 23 | | 73204 | ib_log_fl_notif | 73204 | thread/innodb/log_flush_notifier_thread | 24 | | 73205 | ib_log_flush | 73205 | thread/innodb/log_flusher_thread | 25 | | 73206 | ib_log_wr_notif | 73206 | thread/innodb/log_write_notifier_thread | 26 | | 73207 | ib_log_writer | 73207 | thread/innodb/log_writer_thread | 27 | | 73208 | ib_log_files_g | 73208 | thread/innodb/log_files_governor_thread | 28 | | 73213 | ib_srv_lock_to | 73213 | thread/innodb/srv_lock_timeout_thread | 29 | | 73214 | ib_srv_err_mon | 73214 | thread/innodb/srv_error_monitor_thread | 30 | | 73215 | ib_srv_mon | 73215 | thread/innodb/srv_monitor_thread | 31 | | 73217 | ib_buf_resize | 73217 | thread/innodb/buf_resize_thread | 32 | | 73218 | ib_src_main | 73218 | thread/innodb/srv_master_thread | 33 | | 73219 | ib_dict_stats | 73219 | thread/innodb/dict_stats_thread | 34 | | 73220 | ib_fts_opt | 73220 | thread/innodb/fts_optimize_thread | 35 | | 73221 | xpl_worker-1 | 73221 | thread/mysqlx/worker | 36 | | 73222 | xpl_worker-2 | 73222 | thread/mysqlx/worker | 37 | | 73223 | xpl_accept-1 | 73223 | thread/mysqlx/acceptor_network | 38 | | 73227 | ib_buf_dump | 73227 | thread/innodb/buf_dump_thread | 39 | | 73228 | ib_clone_gtid | 73228 | thread/innodb/clone_gtid_thread | 40 | | 73229 | ib_srv_purge | 73229 | thread/innodb/srv_purge_thread | 41 | | 73230 | ib_srv_wkr-1 | 73230 | thread/innodb/srv_worker_thread | 42 | | 73231 | ib_srv_wkr-2 | 73231 | thread/innodb/srv_worker_thread | 43 | | 73232 | ib_srv_wkr-3 | 73232 | thread/innodb/srv_worker_thread | 44 | | 73233 | evt_sched | 73233 | thread/sql/event_scheduler | 45 | | 73234 | sig_handler | 73234 | thread/sql/signal_handler | 46 | | 73235 | xpl_accept-2 | 73235 | thread/mysqlx/acceptor_network | 47 | | 73237 | gtid_zip | 73237 | thread/sql/compress_gtid_table | 48 | | 73295 | connection | | | 49 | | 77484 | connection | | | 50 | | 77832 | connection | | | 51 | | 82160 | connection | 82160 | thread/sql/one_connection | 52 | | 82163 | connection | | | 53 | -------------------------------------------------------------------------------- /lab/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.6' 2 | 3 | services: 4 | mysql80027: 5 | container_name: mysql-8.0.27 6 | image: 'mysql:8.0.27' 7 | restart: always 8 | # privileged: true 9 | environment: 10 | MYSQL_ROOT_PASSWORD: 'root' 11 | MYSQL_DATABASE: rtc80027 12 | MYSQL_USER: rtc 13 | MYSQL_PASSWORD: rtc123456 14 | ports: 15 | - '3327:3306' 16 | volumes: 17 | - '/opt/docker/mysql80027:/var/lib/mysql' 18 | 19 | mysql57040: 20 | container_name: mysql-5.7.40 21 | image: 'mysql:5.7.40' 22 | restart: always 23 | # privileged: true 24 | environment: 25 | MYSQL_ROOT_PASSWORD: 'root' 26 | MYSQL_DATABASE: rtc50040 27 | MYSQL_USER: rtc 28 | MYSQL_PASSWORD: rtc123456 29 | ports: 30 | - '3340:3306' 31 | volumes: 32 | - '/opt/docker/mysql50040:/var/lib/mysql' 33 | -------------------------------------------------------------------------------- /lab/p22.sql: -------------------------------------------------------------------------------- 1 | create table t1 ( 2 | k1 int, 3 | c1 varchar(8), 4 | c2 varchar(8), 5 | primary key (k1) 6 | ); 7 | 8 | insert into t1 (k1, c1, c2) values (1, 'r1c1', 'r1c2'); 9 | insert into t1 (k1, c1, c2) values (2, 'r2c1', 'r2c2'); 10 | -------------------------------------------------------------------------------- /lab/t10w.sql: -------------------------------------------------------------------------------- 1 | use rtc; 2 | 3 | drop table if exists t10w; 4 | 5 | create table t10w ( 6 | k1 int, 7 | c1 varchar(8), 8 | c2 varchar(8), 9 | primary key (k1) 10 | ); 11 | 12 | delimiter // 13 | 14 | create procedure mock10w () 15 | begin 16 | declare 17 | i int; 18 | set i = 1; 19 | while (i <= 100000) 20 | do insert into t10w 21 | values (i, i, i); 22 | set i = i + 1; 23 | end while; 24 | end // 25 | 26 | delimiter ; 27 | 28 | call mock10w(); 29 | -------------------------------------------------------------------------------- /lab/t500w.sql: -------------------------------------------------------------------------------- 1 | use rtc; 2 | 3 | drop table if exists t500w; 4 | 5 | create table t500w ( 6 | k1 int, 7 | c1 varchar(8), 8 | c2 varchar(8), 9 | primary key (k1) 10 | ); 11 | 12 | delimiter // 13 | 14 | drop procedure if exists mock500w; 15 | create procedure mock500w () 16 | begin 17 | declare 18 | i int; 19 | set i = 1; 20 | while (i <= 5000000) 21 | do insert into t500w 22 | values (i, i, i); 23 | set i = i + 1; 24 | end while; 25 | end // 26 | 27 | delimiter ; 28 | 29 | call mock500w(); 30 | -------------------------------------------------------------------------------- /notes/n22.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n22.pdf -------------------------------------------------------------------------------- /notes/n23.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n23.pdf -------------------------------------------------------------------------------- /notes/n24.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n24.pdf -------------------------------------------------------------------------------- /notes/n25.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n25.pdf -------------------------------------------------------------------------------- /notes/n26.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n26.pdf -------------------------------------------------------------------------------- /notes/n27.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n27.pdf -------------------------------------------------------------------------------- /notes/n28.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n28.pdf -------------------------------------------------------------------------------- /notes/n29.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeanhwea/mysql-source-course/4db3c70586c89f207488dca584cbc50d878d41f4/notes/n29.pdf -------------------------------------------------------------------------------- /query/exe01.sql: -------------------------------------------------------------------------------- 1 | select 2 | emp_no, 3 | first_name, 4 | birth_date, 5 | ceil(datediff(current_date, birth_date)/365) 6 | as age 7 | from 8 | employees 9 | where 10 | emp_no < 10010; 11 | -------------------------------------------------------------------------------- /query/exe02.sql: -------------------------------------------------------------------------------- 1 | select 2 | x.dept_no, 3 | e.first_name, 4 | e.last_name 5 | from 6 | dept_manager x 7 | left join 8 | employees e 9 | using (emp_no) 10 | where 11 | x.dept_no < 'd004'; 12 | -------------------------------------------------------------------------------- /query/init-record-list.sql: -------------------------------------------------------------------------------- 1 | create table t (k int primary key, v char(4)); 2 | 3 | insert into t values(1, 'aaaa'); 4 | insert into t values(2, 'bbbb'); 5 | insert into t values(3, 'cccc'); 6 | insert into t values(4, 'dddd'); 7 | insert into t values(5, 'eeee'); 8 | insert into t values(6, 'ffff'); 9 | insert into t values(7, 'gggg'); 10 | insert into t values(8, 'hhhh'); 11 | insert into t values(9, 'iiii'); 12 | -------------------------------------------------------------------------------- /query/join3.sql: -------------------------------------------------------------------------------- 1 | select /*+ rtc */ 2 | e.first_name, e.last_name, a.from_date 3 | from 4 | dept_manager a join departments d join employees e 5 | where 6 | a.dept_no = d.dept_no and a.emp_no = e.emp_no and d.dept_no = 'd001'; 7 | -------------------------------------------------------------------------------- /query/join3_straight.sql: -------------------------------------------------------------------------------- 1 | select /*+ rtc */ 2 | e.first_name, e.last_name, a.from_date 3 | from 4 | dept_manager a straight_join departments d straight_join employees e 5 | where 6 | a.dept_no = d.dept_no and a.emp_no = e.emp_no and d.dept_no = 'd001'; 7 | -------------------------------------------------------------------------------- /query/join4.sql: -------------------------------------------------------------------------------- 1 | select /*+ rtc */ 2 | d.dept_no, e.first_name, e.last_name, s.from_date, s.salary 3 | from 4 | dept_manager a join departments d join employees e join salaries s 5 | where 6 | a.dept_no = d.dept_no and a.emp_no = e.emp_no 7 | and a.emp_no = s.emp_no and d.dept_no = 'd001'; 8 | -------------------------------------------------------------------------------- /query/join5.sql: -------------------------------------------------------------------------------- 1 | select /*+ rtc */ 2 | d.dept_no, t.title, e.first_name, s.from_date, s.salary 3 | from 4 | dept_manager a join departments d join employees e join salaries s join titles t 5 | where 6 | a.dept_no = d.dept_no and a.emp_no = e.emp_no and a.emp_no = s.emp_no 7 | and a.emp_no = t.emp_no and d.dept_no = 'd001'; 8 | -------------------------------------------------------------------------------- /query/pfs_setup.sql: -------------------------------------------------------------------------------- 1 | select * from performance_schema.setup_actors; 2 | 3 | update performance_schema.setup_instruments set ENABLED = 'YES', TIMED = 'YES' 4 | where name like '%statement/%'; 5 | update performance_schema.setup_instruments set ENABLED = 'YES', TIMED = 'YES' 6 | where name like '%stage/%'; 7 | 8 | update performance_schema.setup_consumers set ENABLED = 'YES' 9 | where name like '%events_statements_%'; 10 | update performance_schema.setup_consumers set ENABLED = 'YES' 11 | where name like '%events_stages_%'; 12 | -------------------------------------------------------------------------------- /query/q.sql: -------------------------------------------------------------------------------- 1 | -- explain 2 | 3 | select 4 | * 5 | from 6 | employees e 7 | where 8 | e.emp_no in ( 9 | select 10 | a.emp_no 11 | from 12 | dept_manager a 13 | where 14 | date_sub(a.from_date, interval 30 day) < e.hire_date); 15 | -------------------------------------------------------------------------------- /query/subq01.sql: -------------------------------------------------------------------------------- 1 | select 2 | count(distinct emp_no) as emp_cnt 3 | from 4 | dept_emp a 5 | where 6 | a.emp_no < 10100 7 | and a.dept_no = ( 8 | select 9 | d.dept_no 10 | from 11 | departments d 12 | where 13 | d.dept_name = 'Development'); 14 | -------------------------------------------------------------------------------- /query/subq02.sql: -------------------------------------------------------------------------------- 1 | select 2 | e.first_name, e.last_name 3 | from 4 | employees e 5 | where 6 | e.emp_no in ( 7 | select 8 | a.emp_no 9 | from 10 | dept_manager a 11 | where 12 | a.dept_no = 'd001'); 13 | -------------------------------------------------------------------------------- /query/subq03.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | departments d 5 | where 6 | d.dept_no in ( 7 | select 8 | a.dept_no 9 | from 10 | dept_manager a 11 | where 12 | a.from_date >= '1995-01-01'); 13 | -------------------------------------------------------------------------------- /query/subq04.sql: -------------------------------------------------------------------------------- 1 | select 2 | e.first_name, 3 | e.last_name 4 | from 5 | employees e 6 | where 7 | exists ( 8 | select 9 | * 10 | from 11 | dept_manager a 12 | where 13 | a.dept_no = 'd001' 14 | and a.emp_no = e.emp_no); 15 | -------------------------------------------------------------------------------- /query/subq05.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | departments d 5 | where 6 | d.dept_no not in ( 7 | select 8 | a.dept_no 9 | from 10 | dept_manager a 11 | where 12 | a.from_date > '1995-01-01'); 13 | -------------------------------------------------------------------------------- /query/subq06.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | titles t, 5 | ( 6 | select 7 | * 8 | from 9 | employees 10 | where 11 | emp_no <= 10100) emp_100 12 | where 13 | t.emp_no = emp_100.emp_no 14 | and t.from_date > '2000-01-01'; 15 | -------------------------------------------------------------------------------- /readme.org: -------------------------------------------------------------------------------- 1 | #+TITLE:【更新中】🐬 读 MySQL 源码 2 | #+AUTHOR: Jinghui Hu 3 | #+EMAIL: hujinghui@buaa.edu.cn 4 | #+DATE: <2024-05-06 Mon> 5 | #+STARTUP: overview num indent 6 | #+OPTIONS: ^:nil 7 | 8 | [[file:figures/mysql-poster.svg]] 9 | 10 | * 快速链接 11 | 1. 课程主页 | [[https://github.com/Jeanhwea/mysql-source-course][github]] | [[https://gitee.com/jeanhwea/mysql-source-course][gitee]] 12 | 2. 源码仓库 | [[https://github.com/Jeanhwea/mysql-server][github]] | [[https://gitee.com/jeanhwea/mysql-server][gitee]] 13 | 3. 视频讲解 | [[https://www.bilibili.com/cheese/play/ss19642][bilibili]] 14 | 4. ibr 工具 | [[https://github.com/Jeanhwea/innobase_reader][source]] | [[https://github.com/Jeanhwea/innobase_reader/releases][release]] | [[https://read0code.github.io/pub/ibr/ibr/index.html][doc]] 15 | 16 | * 课程安排 17 | ** 课程大纲 18 | - 课程预计时间 <2024-05-06 Mon> 至 <2026-05-26 Tue> 19 | | Timeline | Topic | Slide & Note | Video | 20 | |------------------+------------------------------------------+--------------+-------| 21 | | <2024-05-06 Mon> | 关系型数据库管理系统绪论 | [[file:slides/p01-introduction-to-RDMS.pdf][p01]] | [[https://www.bilibili.com/cheese/play/ep676075][v01]] | 22 | | <2024-05-08 Wed> | 源码构建 MySQL 调试环境 | [[file:slides/p02-build-mysql-from-source.pdf][p02]] | [[https://www.bilibili.com/cheese/play/ep683149][v02]] | 23 | | <2024-05-10 Fri> | MySQL 系统架构及模块功能概述 | [[file:slides/p03-mysql-architecture.pdf][p03]] | [[https://www.bilibili.com/cheese/play/ep693532][v03]] | 24 | | <2024-05-15 Wed> | MySQL 服务启动源码分析 | [[file:slides/p04-mysql-startup.pdf][p04]] | [[https://www.bilibili.com/cheese/play/ep704954][v04]] | 25 | | <2024-05-20 Mon> | MySQL 的线程模型 | [[file:slides/p05-mysql-thread-model.pdf][p05]] | [[https://www.bilibili.com/cheese/play/ep725138][v05]] | 26 | | <2024-05-23 Thu> | 服务层组件连接器的设计与实现 | [[file:slides/p06-server-connection-manager.pdf][p06]] | [[https://www.bilibili.com/cheese/play/ep731978][v06]] | 27 | | <2024-05-28 Tue> | 服务层组件线程管理和用户模块 | [[file:slides/p07-server-thd-manager.pdf][p07]] | [[https://www.bilibili.com/cheese/play/ep740625][v07]] | 28 | | <2024-05-30 Thu> | 网络模块和派发模块 | [[file:slides/p08-net-dispatch-command.pdf][p08]] | [[https://www.bilibili.com/cheese/play/ep746335][v08]] | 29 | | <2024-06-04 Tue> | MySQL 词法分析器的设计与实现 | [[file:slides/p09-lexical-scanner.pdf][p09]] | [[https://www.bilibili.com/cheese/play/ep759933][v09]] | 30 | | <2024-06-06 Thu> | MySQL 语法分析器的设计与实现 | [[file:slides/p10-syntax-parser.pdf][p10]] | [[https://www.bilibili.com/cheese/play/ep764493][v10]] | 31 | | <2024-06-12 Wed> | 遍历解析树上下文构建词法单元 | [[file:slides/p11-contextualize-parse-tree.pdf][p11]] | [[https://www.bilibili.com/cheese/play/ep785171][v11]] | 32 | | <2024-06-15 Sat> | MySQL 优化器功能概述及其观测工具 | [[file:slides/p12-introduction-to-optimizer.pdf][p12]] | [[https://www.bilibili.com/cheese/play/ep795203][v12]] | 33 | | <2024-06-20 Thu> | 准备阶段 Rewrite 和 Prepare 设计与实现 | [[file:slides/p13-rewrite-and-prepare.pdf][p13]] | [[https://www.bilibili.com/cheese/play/ep813796][v13]] | 34 | | <2024-06-23 Sun> | 进入优化器和优化器追踪日志实现 | [[file:slides/p14-enter-optimizer.pdf][p14]] | [[https://www.bilibili.com/cheese/play/ep820168][v14]] | 35 | | <2024-06-27 Thu> | 代价模型和优化模块的设计与实现 | [[file:slides/p15-optimizer-and-cost-model.pdf][p15]] | [[https://www.bilibili.com/cheese/play/ep834530][v15]] | 36 | | <2024-06-29 Sat> | 联表查询 Join 优化器的设计与实现 | [[file:slides/p16-join-order-optimizer.pdf][p16]] | [[https://www.bilibili.com/cheese/play/ep838693][v16]] | 37 | | <2024-07-04 Thu> | 子查询优化器的设计与实现 | [[file:slides/p17-subquery-optimizer.pdf][p17]] | [[https://www.bilibili.com/cheese/play/ep853672][v17]] | 38 | | <2024-07-09 Tue> | MySQL 执行器的设计与实现 | [[file:slides/p18-enter-executor.pdf][p18]] | [[https://www.bilibili.com/cheese/play/ep869070][v18]] | 39 | | <2024-07-22 Mon> | 性能分析及 handlerton 存储引擎接口设计 | [[file:slides/p19-profile-handlerton.pdf][p19]] | [[https://www.bilibili.com/cheese/play/ep913384][v19]] | 40 | | <2024-08-01 Thu> | InnoDB 存储引擎数据文件和分页机制 | [[file:slides/p20-innodb-datafile.pdf][p20]] | [[https://www.bilibili.com/cheese/play/ep950258][v20]] | 41 | | <2024-08-06 Tue> | InnoDB 存储引擎的行记录格式 | [[file:slides/p21-innodb-row-format.pdf][p21]] | [[https://www.bilibili.com/cheese/play/ep965657][v21]] | 42 | | <2024-08-12 Mon> | INDEX 数据页案例研究和 ibr 工具介绍 | [[file:slides/p22-innobase-reader-cli.pdf][p22]] / [[file:notes/n22.pdf][n22]] | [[https://www.bilibili.com/cheese/play/ep982336][v22]] | 43 | | <2024-08-14 Wed> | InnoDB 行记录格式的演进过程 | [[file:slides/p23-parse-record.pdf][p23]] / [[file:notes/n23.pdf][n23]] | [[https://www.bilibili.com/cheese/play/ep988104][v23]] | 44 | | <2024-08-19 Mon> | MySQL 的 Online DDL 的演进过程 | [[file:slides/p24-online-ddl-development.pdf][p24]] / [[file:notes/n24.pdf][n24]] | [[https://www.bilibili.com/cheese/play/ep1000682][v24]] | 45 | | <2024-08-22 Thu> | MySQL 的数据文件层级:表空间、段、区、页 | [[file:slides/p25-datafile-physical-struct.pdf][p25]] / [[file:notes/n25.pdf][n25]] | [[https://www.bilibili.com/cheese/play/ep1007243][v25]] | 46 | | <2024-09-02 Mon> | MySQL 的索引组织结构和 B+树结构 | [[file:slides/p26-index-btree.pdf][p26]] / [[file:notes/n26.pdf][n26]] | [[https://www.bilibili.com/cheese/play/ep1042363][v26]] | 47 | | <2024-10-09 Wed> | InnoDB 的 UndoLog 数据结构设计 | [[file:slides/p27-undo-log.pdf][p27]] / [[file:notes/n27.pdf][n27]] | [[https://www.bilibili.com/cheese/play/ep1138975][v27]] | 48 | | <2024-10-15 Tue> | InnoDB 的 RedoLog 数据结构设计 | [[file:slides/p28-redo-log.pdf][p28]] / [[file:notes/n28.pdf][n28]] | [[https://www.bilibili.com/cheese/play/ep1158950][v28]] | 49 | | <2024-10-28 Mon> | MVCC 和事务隔离级别的设计与实现 | [[file:slides/p29-mvcc-trx-iso.pdf][p29]] / [[file:notes/n29.pdf][n29]] | [[https://www.bilibili.com/cheese/play/ep1196325][v29]] | 50 | | <2025-02-16 Sun> | InnoDB Buffer Pool 的设计与实现 | [[file:slides/p30-buffer-pool.pdf][p30]] | | 51 | | | 更新中 | | | 52 | 53 | ** 阅读材料 54 | 1. 系统线程名称和性能视图表名称对应 | [[file:assets/thd-name-ref.org][link]] 55 | 2. 三表连接不同查询写法的 Opt_trace 对比 | [[file:assets/join3-prepare-example.org][link]] 56 | 3. 子查询优化器分析示例 | [[file:assets/subquery-examples.org][link]] 57 | 58 | ** 课程资源 59 | 课程中较大的资源文件存档在百度网盘中,大家可自行下载 | [[https://pan.baidu.com/s/1XivUc1HAogTeXOWPc11-Og?pwd=rdms][BaiduYun]] 60 | #+BEGIN_EXAMPLE 61 | 链接:https://pan.baidu.com/s/1XivUc1HAogTeXOWPc11-Og?pwd=rdms 62 | 提取码:rdms 63 | #+END_EXAMPLE 64 | 65 | | 说明 | 文件名 | 来源 | 66 | |------------------+----------------------------+-------------------------| 67 | | boost 库 | boost_1_77_0.tar.bz2 | 官网下载 | 68 | | MySQL 源代码 | mysql-8.0.37.tar.gz | 官网下载 | 69 | | MySQL 开发文档 | mysql-devdoc-8.0.37.tar.gz | 源码编译输出 | 70 | | MySQL 用户手册 | refman-8.0-en.a4.pdf | 官网下载 | 71 | | Employee 测试库 | test_db.tar.gz | GitHub 下载 / [[https://github.com/datacharmer/test_db][link]] | 72 | | world 测试库 | world-db.tar.gz | 官网下载 / [[https://dev.mysql.com/doc/index-other.html][link]] / [[https://dev.mysql.com/doc/world-setup/en/][intro]] | 73 | | sakila 测试库 | sakila-db.tar.gz | 官网下载 / [[https://dev.mysql.com/doc/index-other.html][link]] / [[https://dev.mysql.com/doc/sakila/en/][intro]] | 74 | | airport 测试库 | airport-db.tar.gz | 官网下载 / [[https://dev.mysql.com/doc/index-other.html][link]] / [[https://dev.mysql.com/doc/airportdb/en/][intro]] | 75 | | menagerie 测试库 | menagerie-db.tar.gz | 官网下载 / [[https://dev.mysql.com/doc/index-other.html][link]] | 76 | -------------------------------------------------------------------------------- /scripts/dbg-attach-gdb.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export MYSQL_HOME=${MYSQL_HOME:-/opt/mysql} 3 | export MYSQLD_PID=$(cat $MYSQL_HOME/mysqld.pid) 4 | 5 | gdb -p $MYSQLD_PID 6 | -------------------------------------------------------------------------------- /scripts/dbg-attach-lldb.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export MYSQL_HOME=${MYSQL_HOME:-/opt/mysql} 3 | export MYSQLD_PID=$(cat $MYSQL_HOME/mysqld.pid) 4 | 5 | lldb -p $MYSQLD_PID 6 | -------------------------------------------------------------------------------- /scripts/dbg-start-lldb.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export MYSQL_HOME=${MYSQL_HOME:-/opt/mysql} 3 | 4 | if [ -f $MYSQL_HOME/mysqld.pid ]; then 5 | export MYSQLD_PID=$(cat $MYSQL_HOME/mysqld.pid) 6 | echo "mysqld already started. pid = $MYSQLD_PID" 7 | exit 8 | fi 9 | 10 | # set args 11 | # (lldb) settings set target.run-args --gdb 12 | 13 | # show args 14 | # (lldb) settings show target.run-args 15 | 16 | # set envs 17 | # (lldb) settings set target.env-vars DEBUG=1 18 | # (lldb) set se target.env-vars DEBUG=1 19 | # (lldb) env DEBUG=1 20 | 21 | lldb -o "b main" \ 22 | -o "r" \ 23 | -- mysqld --gdb 24 | -------------------------------------------------------------------------------- /scripts/rtc-index-source-code.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export MYSQL_SRC=${MYSQL_SRC:-/opt/src/mysql-server} 3 | 4 | cd $MYSQL_SRC 5 | rm -f cscope.* tags TAGS 6 | 7 | rtc_index_dir() { 8 | local srcdir=$1 9 | echo "index source dir: $srcdir" 10 | find $srcdir \( \ 11 | -iname '*.ic' -o \ 12 | -iname '*.c.in' -o \ 13 | -iname '*.h.in' -o \ 14 | -iname '*.cc.in' -o \ 15 | -iname '*.pc.in' -o \ 16 | -iname '*.h' -o \ 17 | -iname '*.hpp' -o \ 18 | -iname '*.c' -o \ 19 | -iname '*.yy' -o \ 20 | -iname '*.cc' \ 21 | \) -type f -print >> cscope.files 22 | } 23 | 24 | touch cscope.files 25 | rtc_index_dir "$MYSQL_SRC/client" 26 | rtc_index_dir "$MYSQL_SRC/components" 27 | # rtc_index_dir "$MYSQL_SRC/extra" 28 | rtc_index_dir "$MYSQL_SRC/include" 29 | rtc_index_dir "$MYSQL_SRC/mysys" 30 | # rtc_index_dir "$MYSQL_SRC/plugin" 31 | rtc_index_dir "$MYSQL_SRC/router" 32 | rtc_index_dir "$MYSQL_SRC/sql" 33 | rtc_index_dir "$MYSQL_SRC/sql-common" 34 | # rtc_index_dir "$MYSQL_SRC/storage" 35 | # rtc_index_dir "$MYSQL_SRC/storage/csv" 36 | # rtc_index_dir "$MYSQL_SRC/storage/heap" 37 | rtc_index_dir "$MYSQL_SRC/storage/innobase" 38 | rtc_index_dir "$MYSQL_SRC/storage/myisam" 39 | rtc_index_dir "$MYSQL_SRC/storage/perfschema" 40 | rtc_index_dir "$MYSQL_SRC/storage/temptable" 41 | # rtc_index_dir "$MYSQL_SRC/storage/myisam" 42 | rtc_index_dir "$MYSQL_SRC/strings" 43 | # rtc_index_dir "$MYSQL_SRC/unittest" 44 | rtc_index_dir "$MYSQL_SRC/utilities" 45 | rtc_index_dir "$MYSQL_SRC/vio" 46 | 47 | sort -u -o cscope.files cscope.files 48 | 49 | FILECNT=$(wc -l cscope.files | awk '{print $1}') 50 | echo "STAT: total $FILECNT source file" 51 | 52 | echo "GEN: create cscope database" 53 | cscope -b -q -k 54 | 55 | echo "GEN: create TAGS file" 56 | # grep '.ic$' cscope.files | etags --language=c++ -L - 57 | grep '.ic$' cscope.files | etags --language-force=c++ -L - 58 | grep -v '.ic$' cscope.files | etags --append -L - 59 | # ctags --langmap=c:+.ic -e -L cscope.files 60 | # ctags --langmap=c:+.ic -f tags -L cscope.files 61 | -------------------------------------------------------------------------------- /scripts/rtc-step1-install-depends.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # https://dev.mysql.com/doc/refman/8.0/en/source-installation-prerequisites.html 4 | sudo apt install -y build-essential git ncurses-dev bison cmake libaio1 libssl-dev 5 | 6 | # GCC 10 7 | gcc --version 8 | # GNU make 3.75 or later. 9 | make --version 10 | # cmake 3.x 11 | cmake --version 12 | # bison 2.1 or later 13 | bison --version 14 | 15 | # install debug source 16 | sudo apt install linux-source glibc-source 17 | -------------------------------------------------------------------------------- /scripts/rtc-step2-setup-boost.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | BOOST_DIR="/opt/boost_1_77_0" 3 | BOOST_URL="https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.bz2" 4 | if [ -d $BOOST_DIR ]; then 5 | echo "Find boost" 6 | exit 7 | fi 8 | 9 | if [ ! -f "/tmp/boost_1_77_0.tar.bz2" ]; then 10 | echo "Download from $BOOST_URL" 11 | cd /tmp 12 | wget -c $BOOST_URL 13 | fi 14 | 15 | tar xvf /tmp/boost_1_77_0.tar.bz2 16 | 17 | if [ $UID -ne 0 ]; then 18 | echo "Permission deny, sudo ..." 19 | exit 13 # EACCES 20 | fi 21 | 22 | sudo mv boost_1_77_0 /opt 23 | -------------------------------------------------------------------------------- /scripts/rtc-step3-build-mysql-server-27.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export MYSQL_HOME=${MYSQL_HOME:-/opt/mysql} 3 | export MYSQL_SRC=${MYSQL_SRC:-/opt/src/mysql-server} 4 | 5 | BOOST_DIR="/opt/boost_1_73_0" 6 | 7 | BUILD_DIR="$MYSQL_SRC/build" 8 | 9 | if [ ! -d $MYSQL_HOME ]; then 10 | sudo mkdir $MYSQL_HOME 11 | sudo chown $(whoami):$(whoami) $MYSQL_HOME 12 | fi 13 | 14 | echo "step1: prepare my.cnf" 15 | tee $MYSQL_HOME/my.cnf <