File: nested_derived_tables.sql

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (22 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
explain select *,
   (select count(*) from sakila.film as outer_sub where outer_sub.film_id = outer_der.film_id)
from (
   select *,
      (select count(*) from sakila.film as mid_sub where mid_sub.film_id = mid_der.film_id)
   from (
      select *,
         (select count(*) from sakila.film as inner_sub where inner_sub.film_id = inner_der.film_id)
      from sakila.film as inner_der
   ) as mid_der
) as outer_der;

+----+--------------------+------------+--------+---------------+---------+---------+-------------------+------+--------------------------+
| id | select_type        | table      | type   | possible_keys | key     | key_len | ref               | rows | Extra                    |
+----+--------------------+------------+--------+---------------+---------+---------+-------------------+------+--------------------------+
|  1 | PRIMARY            | <derived3> | ALL    | NULL          | NULL    | NULL    | NULL              | 1000 |                          | 
|  3 | DERIVED            | <derived5> | ALL    | NULL          | NULL    | NULL    | NULL              | 1000 |                          | 
|  5 | DERIVED            | inner_der  | ALL    | NULL          | NULL    | NULL    | NULL              |  951 |                          | 
|  6 | DEPENDENT SUBQUERY | inner_sub  | eq_ref | PRIMARY       | PRIMARY | 2       | inner_der.film_id |    1 | Using where; Using index | 
|  4 | DEPENDENT SUBQUERY | mid_sub    | eq_ref | PRIMARY       | PRIMARY | 2       | mid_der.film_id   |    1 | Using where; Using index | 
|  2 | DEPENDENT SUBQUERY | outer_sub  | eq_ref | PRIMARY       | PRIMARY | 2       | outer_der.film_id |    1 | Using where; Using index | 
+----+--------------------+------------+--------+---------------+---------+---------+-------------------+------+--------------------------+