Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(planner): implement explain query in verbose mode #14801

Merged
merged 2 commits into from Mar 1, 2024

Conversation

leiysky
Copy link
Member

@leiysky leiysky commented Feb 29, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Support explain logical plan with verbose output, which contains relational property information and statistics.

For example:

root@localhost:8000/default> explain(verbose, logical) select * from test;

EXPLAIN(verbose, logical)
SELECT
  *
FROM
  test

-[ EXPLAIN ]-----------------------------------
EvalScalar
├── scalars: [test.a (#0) AS (#0), test.b (#1) AS (#1)]
├── output columns: [default.test.a, default.test.b]
├── outer columns: []
├── used columns: [default.test.a, default.test.b]
├── cardinality: 10.000
├── precise cardinality: 10
├── statistics
│   ├── default.test.a: { min: 0, max: 9, ndv: 10, null count: 0 }
│   └── default.test.b: { min: hello, max: hello, ndv: 10, null count: 0 }
└── Scan
    ├── table: default.test
    ├── filters: []
    ├── order by: []
    ├── limit: NONE
    ├── output columns: [default.test.a, default.test.b]
    ├── outer columns: []
    ├── used columns: [default.test.a, default.test.b]
    ├── cardinality: 10.000
    ├── precise cardinality: 10
    └── statistics
        ├── default.test.a: { min: 0, max: 9, ndv: 10, null count: 0 }
        └── default.test.b: { min: hello, max: hello, ndv: 10, null count: 0 }

23 rows explain in 0.085 sec. Processed 0 rows, 0 B (0 rows/s, 0 B/s)

Also improve the syntax of explain statement by adding explain options, we will prefer to use EXPLAIN(LOGICAL) instead of EXPLAIN RAW.

Currently we supported following explain options:

  • VERBOSE: enable verbose output, only works with logical plan
  • LOGICAL: print unoptimized logical plan, the same with EXPLAIN RAW
  • OPTIMIZED: print optimized logical plan, the same with EXPLAIN OPTIMIZED

In the future we can support FORMAT option to enable different output format of explain statement, e.g. JSON format for strucutral analysis.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Feb 29, 2024
@BohuTANG
Copy link
Member

Cool.
Btw, we already have explain analyze, syntax like:

explain [analyze] <SQL>

Can we merge this PR feature into the analyze instead of introducing the new explain(verbose, logical)? Or it's hard to choose when to use.

@leiysky
Copy link
Member Author

leiysky commented Feb 29, 2024

Cool. Btw, we already have explain analyze, syntax like:

explain [analyze] <SQL>

Can we merge this PR feature into the analyze instead of introducing the new explain(verbose, logical)? Or it's hard to choose when to use.

They are not compatible because explain analyze and explain print PhysicalPlan while explain(logical) prints the logical plan SExpr. They are not even exact one-to-one mapping.

In most of the scenarios explain and explain analyze is enough for users. The explain(verbose, logical) is designed for developers to trace the internal information of optimizer.

@leiysky leiysky added this pull request to the merge queue Mar 1, 2024
@BohuTANG BohuTANG removed this pull request from the merge queue due to a manual request Mar 1, 2024
@BohuTANG BohuTANG merged commit 1b8e8c7 into datafuselabs:main Mar 1, 2024
72 checks passed
@leiysky leiysky deleted the explain-verbose branch March 1, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants