cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.8k stars 3.76k forks source link

opt: Plan comparison tool #35627

Open awoods187 opened 5 years ago

awoods187 commented 5 years ago

I want to be able to compare two plans quickly to see the difference without having to "eyeball" the results. Plan 1

                                     tree                                    |       field        |                     description
+----------------------------------------------------------------------------+--------------------+-----------------------------------------------------+
  render                                                                     |                    |
   └── sort                                                                  |                    |
        │                                                                    | order              | +o_year
        └── render                                                           |                    |
             └── group                                                       |                    |
                  │                                                          | aggregate 0        | o_year
                  │                                                          | aggregate 1        | sum(column63)
                  │                                                          | aggregate 2        | sum(volume)
                  │                                                          | group by           | @2
                  └── render                                                 |                    |
                       └── render                                            |                    |
                            └── join                                         |                    |
                                 │                                           | type               | inner
                                 │                                           | equality           | (l_partkey) = (p_partkey)
                                 │                                           | right cols are key |
                                 ├── join                                    |                    |
                                 │    │                                      | type               | inner
                                 │    │                                      | equality           | (l_suppkey, n_nationkey) = (s_suppkey, s_nationkey)
                                 │    │                                      | right cols are key |
                                 │    ├── lookup-join                        |                    |
                                 │    │    │                                 | table              | lineitem@primary
                                 │    │    │                                 | type               | inner
                                 │    │    └── join                          |                    |
                                 │    │         │                            | type               | inner
                                 │    │         │                            | equality           | (c_custkey) = (o_custkey)
                                 │    │         ├── join                     |                    |
                                 │    │         │    │                       | type               | inner
                                 │    │         │    │                       | equality           | (c_nationkey) = (n_nationkey)
                                 │    │         │    │                       | mergeJoinOrder     | +"(c_nationkey=n_nationkey)"
                                 │    │         │    ├── scan                |                    |
                                 │    │         │    │                       | table              | customer@c_nk
                                 │    │         │    │                       | spans              | ALL
                                 │    │         │    └── sort                |                    |
                                 │    │         │         │                  | order              | +n_nationkey
                                 │    │         │         └── join           |                    |
                                 │    │         │              │             | type               | inner
                                 │    │         │              │             | equality           | (n_regionkey) = (r_regionkey)
                                 │    │         │              ├── scan      |                    |
                                 │    │         │              │             | table              | nation@n_rk
                                 │    │         │              │             | spans              | ALL
                                 │    │         │              └── join      |                    |
                                 │    │         │                   │        | type               | cross
                                 │    │         │                   ├── scan |                    |
                                 │    │         │                   │        | table              | nation@primary
                                 │    │         │                   │        | spans              | ALL
                                 │    │         │                   └── scan |                    |
                                 │    │         │                            | table              | region@primary
                                 │    │         │                            | spans              | ALL
                                 │    │         │                            | filter             | r_name = 'AMERICA'
                                 │    │         └── index-join               |                    |
                                 │    │              │                       | table              | orders@primary
                                 │    │              └── scan                |                    |
                                 │    │                                      | table              | orders@o_od
                                 │    │                                      | spans              | /9131-/9862
                                 │    └── scan                               |                    |
                                 │                                           | table              | supplier@s_nk
                                 │                                           | spans              | ALL
                                 └── scan                                    |                    |
                                                                             | table              | part@primary
                                                                             | spans              | ALL
                                                                             | filter             | p_type = 'ECONOMY ANODIZED STEEL'
(61 rows)

vs. Plan 2

+-------------------------------------------------------------------------+--------------------+-----------------------------------------------------+
  render                                                                  |                    |
   └── sort                                                               |                    |
        │                                                                 | order              | +o_year
        └── render                                                        |                    |
             └── group                                                    |                    |
                  │                                                       | aggregate 0        | o_year
                  │                                                       | aggregate 1        | sum(column63)
                  │                                                       | aggregate 2        | sum(volume)
                  │                                                       | group by           | @2
                  └── render                                              |                    |
                       └── render                                         |                    |
                            └── join                                      |                    |
                                 │                                        | type               | inner
                                 │                                        | equality           | (l_partkey) = (p_partkey)
                                 │                                        | right cols are key |
                                 ├── join                                 |                    |
                                 │    │                                   | type               | inner
                                 │    │                                   | equality           | (l_suppkey, n_nationkey) = (s_suppkey, s_nationkey)
                                 │    │                                   | right cols are key |
                                 │    ├── join                            |                    |
                                 │    │    │                              | type               | cross
                                 │    │    ├── lookup-join                |                    |
                                 │    │    │    │                         | table              | lineitem@primary
                                 │    │    │    │                         | type               | inner
                                 │    │    │    └── join                  |                    |
                                 │    │    │         │                    | type               | inner
                                 │    │    │         │                    | equality           | (o_custkey) = (c_custkey)
                                 │    │    │         │                    | right cols are key |
                                 │    │    │         ├── index-join       |                    |
                                 │    │    │         │    │               | table              | orders@primary
                                 │    │    │         │    └── scan        |                    |
                                 │    │    │         │                    | table              | orders@o_od
                                 │    │    │         │                    | spans              | /9131-/9862
                                 │    │    │         └── lookup-join      |                    |
                                 │    │    │              │               | table              | customer@c_nk
                                 │    │    │              │               | type               | inner
                                 │    │    │              └── lookup-join |                    |
                                 │    │    │                   │          | table              | nation@n_rk
                                 │    │    │                   │          | type               | inner
                                 │    │    │                   └── scan   |                    |
                                 │    │    │                              | table              | region@primary
                                 │    │    │                              | spans              | ALL
                                 │    │    │                              | filter             | r_name = 'AMERICA'
                                 │    │    └── scan                       |                    |
                                 │    │                                   | table              | nation@primary
                                 │    │                                   | spans              | ALL
                                 │    └── scan                            |                    |
                                 │                                        | table              | supplier@s_nk
                                 │                                        | spans              | ALL
                                 └── scan                                 |                    |
                                                                          | table              | part@primary
                                                                          | spans              | ALL
                                                                          | filter             | p_type = 'ECONOMY ANODIZED STEEL'
(53 rows)

Jira issue: CRDB-4570

github-actions[bot] commented 3 years ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 5 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!

rytaft commented 3 years ago

Still relevant.

github-actions[bot] commented 11 months ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!

rytaft commented 9 months ago

still relevant