Skip to content

Commit

Permalink
add exp_json and opt_trace for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeanhwea committed Jul 4, 2024
1 parent db5ded2 commit 5aba88b
Showing 1 changed file with 130 additions and 6 deletions.
136 changes: 130 additions & 6 deletions assets/subquery-examples.org
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

* subq10
** subq10 - Default
- EXISTS 子查询 [[file:subq04_exists_exp.sql.json][exp_json]] | [[file:subq04_exists_opt.sql.json][opt_trace]]
- 默认 [[file:subq10_sj_default_exp.sql.json][exp_json]] | [[file:subq10_sj_default_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain
select
Expand All @@ -134,6 +134,7 @@
| 2 | MATERIALIZED | a | NULL | ALL | dept_no | NULL | NULL | NULL | 24 | 33.33 | Using where |

** subq10 - DuplicateWeedout
- [[file:subq11_sj_duplicate-weedout_exp.sql.json][exp_json]] | [[file:subq11_sj_duplicate-weedout_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain

Expand All @@ -159,7 +160,7 @@
| 1 | SIMPLE | d | NULL | eq_ref | PRIMARY | PRIMARY | 16 | employees.a.dept_no | 1 | 100.00 | End temporary |

** subq10 - FirstMatch
- xx
- [[file:subq12_sj_first-match_exp.sql.json][exp_json]] | [[file:subq12_sj_first-match_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain

Expand All @@ -179,7 +180,7 @@
#+END_SRC

** subq10 - LooseScan
- xx
- [[file:subq13_sj_loose-scan_exp.sql.json][exp_json]] | [[file:subq13_sj_loose-scan_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain

Expand All @@ -205,7 +206,7 @@
| 1 | SIMPLE | d | NULL | eq_ref | PRIMARY | PRIMARY | 16 | employees.a.dept_no | 1 | 100.00 | End temporary |

** subq10 - Materialize
- xx
- [[file:subq14_sj_materialization_exp.sql.json][exp_json]] | [[file:subq14_sj_materialization_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain

Expand All @@ -231,5 +232,128 @@
| 1 | SIMPLE | <subquery2> | NULL | eq_ref | <auto_distinct_key> | <auto_distinct_key> | 16 | employees.d.dept_no | 1 | 100.00 | NULL |
| 2 | MATERIALIZED | a | NULL | ALL | dept_no | NULL | NULL | NULL | 24 | 33.33 | Using where |

* subq14
- MaterializeScan 参考 | [[*subq03][subq03]]
* subq20
** subq20 - Default
- [[file:subq20_sj_default_exp.sql.json][exp_json]] | [[file:subq20_sj_default_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain
select
,*
from
employees e
where
e.emp_no in (
select
a.emp_no
from
dept_manager a
where
a.dept_no >= 'd003');
#+END_SRC

#+RESULTS:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|----+-------------+-------+------------+--------+-----------------+---------+---------+--------------------+------+----------+-------------------------------------|
| 1 | SIMPLE | a | NULL | index | PRIMARY,dept_no | PRIMARY | 20 | NULL | 24 | 100.00 | Using where; Using index; LooseScan |
| 1 | SIMPLE | e | NULL | eq_ref | PRIMARY | PRIMARY | 4 | employees.a.emp_no | 1 | 100.00 | NULL |

** subq20 - DuplicateWeedout
- [[file:subq21_sj_duplicate-weedout_exp.sql.json][exp_json]] | [[file:subq21_sj_duplicate-weedout_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain
select
,*
from
employees e
where
e.emp_no in (
select
/*+ SEMIJOIN(DUPSWEEDOUT) */
a.emp_no
from
dept_manager a
where
a.dept_no >= 'd003');
#+END_SRC

#+RESULTS:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|----+-------------+-------+------------+--------+-----------------+---------+---------+--------------------+------+----------+-------------------------------------------|
| 1 | SIMPLE | a | NULL | range | PRIMARY,dept_no | dept_no | 16 | NULL | 20 | 100.00 | Using where; Using index; Start temporary |
| 1 | SIMPLE | e | NULL | eq_ref | PRIMARY | PRIMARY | 4 | employees.a.emp_no | 1 | 100.00 | End temporary |

** subq20 - FirstMatch
- [[file:subq22_sj_first-match_exp.sql.json][exp_json]]
#+BEGIN_SRC sql
explain
select
,*
from
employees e
where
e.emp_no in (
select
/*+ SEMIJOIN(FIRSTMATCH) */
a.emp_no
from
dept_manager a
where
a.dept_no >= 'd003');
#+END_SRC

#+RESULTS:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|----+-------------+-------+------------+------+-----------------+---------+---------+--------------------+--------+----------+-----------------------------------------|
| 1 | SIMPLE | e | NULL | ALL | PRIMARY | NULL | NULL | NULL | 276023 | 100.00 | NULL |
| 1 | SIMPLE | a | NULL | ref | PRIMARY,dept_no | PRIMARY | 4 | employees.e.emp_no | 1 | 83.33 | Using where; Using index; FirstMatch(e) |

** subq20 - LooseScan
- [[file:subq23_sj_loose-scan_exp.sql.json][exp_json]] | [[file:subq23_sj_loose-scan_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain
select
,*
from
employees e
where
e.emp_no in (
select
/*+ SEMIJOIN(LOOSESCAN) */
a.emp_no
from
dept_manager a
where
a.dept_no >= 'd003');
#+END_SRC

#+RESULTS:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|----+-------------+-------+------------+--------+-----------------+---------+---------+--------------------+------+----------+-------------------------------------|
| 1 | SIMPLE | a | NULL | index | PRIMARY,dept_no | PRIMARY | 20 | NULL | 24 | 100.00 | Using where; Using index; LooseScan |
| 1 | SIMPLE | e | NULL | eq_ref | PRIMARY | PRIMARY | 4 | employees.a.emp_no | 1 | 100.00 | NULL |

** subq20 - Materialize
- [[file:subq24_sj_materialization_exp.sql.json][exp_json]] | [[file:subq24_sj_materialization_opt.sql.json][opt_trace]]
#+BEGIN_SRC sql
explain
select
,*
from
employees e
where
e.emp_no in (
select
/*+ SEMIJOIN(MATERIALIZATION) */
a.emp_no
from
dept_manager a
where
a.dept_no >= 'd003');
#+END_SRC

#+RESULTS:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|----+--------------+-------------+------------+--------+-----------------+---------+---------+--------------------+------+----------+--------------------------|
| 1 | SIMPLE | <subquery2> | NULL | ALL | NULL | NULL | NULL | NULL | NULL | 100.00 | NULL |
| 1 | SIMPLE | e | NULL | eq_ref | PRIMARY | PRIMARY | 4 | <subquery2>.emp_no | 1 | 100.00 | NULL |
| 2 | MATERIALIZED | a | NULL | range | PRIMARY,dept_no | dept_no | 16 | NULL | 20 | 100.00 | Using where; Using index |

0 comments on commit 5aba88b

Please sign in to comment.