Conversation
:) explain select sum(number) from numbers(10) union all select sum(number) from numbers(10) order by sum(number)
EXPLAIN SELECT sum(number)
FROM numbers(10)
UNION ALL
SELECT sum(number)
FROM numbers(10)
ORDER BY sum(number) ASC
FORMAT TSV
Union
Expression (Projection)
Expression (Before ORDER BY and SELECT)
Aggregating
Expression (Before GROUP BY)
ReadFromStorage (Read from SystemNumbers)
Expression (Projection)
MergingSorted (Merge sorted streams before ORDER BY)
MergeSorting (Merge sorted blocks before ORDER BY)
PartialSorting (Sort each block before ORDER BY)
Expression (Before ORDER BY and SELECT)
Aggregating
Expression (Before GROUP BY)
ReadFromStorage (Read from SystemNumbers) |
Actually not before ORDER BY but for ORDER BY. |
|
BTW how about command to show processors pipeline graph in a graphviz format? I saw it in pipeline stuck exception, can it also be shown on demand? |
Yes, I will add it too. |
5f124e4 to
f1f98d7
Compare
255d8f8 to
5b1596c
Compare
Broken in #11903 |
| else if (s_syntax.ignore(pos, expected)) | ||
| kind = ASTExplainQuery::ExplainKind::AnalyzedSyntax; | ||
| else if (s_pipeline.ignore(pos, expected)) | ||
| kind = ASTExplainQuery::ExplainKind::QueryPipeline; |
There was a problem hiding this comment.
Usage:
EXPLAIN [AST | SYNTAX | PLAN | PIPELINE] [setting = value, ...] SELECT ... [FORMAT ...]
Looks like PLAN is not supported during parsing, or it wasn't not intended to be supported?
There was a problem hiding this comment.
I've forgotten about it indeed.
|
@KochetovNicolai thoughts on showing i.e.: There were some issues with these settings, when calculation was incorrect will help with debugging and will be useful in tests too |
Nice idea! |
I was thinking about showing it in the form of |
| { | ||
| WriteBuffer & out; | ||
| size_t offset = 0; | ||
| const size_t ident = 2; |
| ASTPtr ast_settings; | ||
|
|
||
| static String toString(ExplainKind kind) | ||
| static String toString(ExplainKind kind, bool old_syntax) |
There was a problem hiding this comment.
We can safely remove the old AST query. It's not for users and no backward compatibility is needed.
There was a problem hiding this comment.
I agree about 'we don' t care about backward compatibility fot that'. At the same time Ast and analyze are useful in some (rare) cases (for example to look on rewritten query with joins and lot a of aliases) it if possible it better to keep them.
There was a problem hiding this comment.
AFAICS It is used only for printing formatted query
- ANALYZE = EXPLAIN SYNTAX
- AST = EXPLAIN AST
There was a problem hiding this comment.
ANALYZE = EXPLAIN SYNTAX
AST = EXPLAIN AST
It's correct.
I mainly kept old syntax because it was used in tests. I probably may rewrite all that tests and remove compatibility. I would rather do it in a separate pr.
Flaky test. |
| bool first = true; | ||
| for (const auto & action : expression->getActions()) | ||
| { | ||
| settings.out << prefix << (first ? "Actions: " |
There was a problem hiding this comment.
@KochetovNicolai EXPLAIN actions=1 ... you can see row-level policies, while regular user cannot query them w/o access_management:
EXPLAIN actions = 1 SELECT *
FROM prewhere_filter
┌─explain───────────────────────────────────────────────────┐
│ Union │
│ Expression (Projection) │
│ Actions: PROJECT a, b │
│ Expression (Before ORDER BY and SELECT) │
│ Actions: PROJECT a, b │
│ Filter (Row-level security filter) │
│ Filter column: equals(b, 1) │ │ Actions: PROJECT a, b │
│ ADD 1 UInt8 Const(UInt8) │
│ FUNCTION equals(b, 1) UInt8 = equals(b, 1) │ <-- this
│ REMOVE 1 │
│ ReadFromStorage (Read from MergeTree) │
└───────────────────────────────────────────────────────────┘
There was a problem hiding this comment.
It can be considered normal.
The user can see how data was filtered and the fact that data is being filtered but they cannot see the data that was filtered out.
There was a problem hiding this comment.
Ok, but then what is the purpose of restricting access to the system.row_policies/show row policies ?
There was a problem hiding this comment.
It prevents to show policies for all other users?
| size_t count; | ||
| }; | ||
|
|
||
| using Edge = std::vector<EdgeData>; |
There was a problem hiding this comment.
@KochetovNicolai , does it mean that there could be multiple edges (lines) connecting two nodes in the graph? Do you have such an example query? Thank you!
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Initial implementation of
EXPLAINquery. Syntax:EXPLAIN SELECT .... This fixes #1118.Usage:
EXPLAIN ASTDump query AST.
EXPLAIN SYNTAXReturn query after syntax optimisations.
EXPLAIN PLANDump query plan steps.
Settings:
header- print output header for step. Default: 0.description- print step description. Default: 1.actions- print detailed information about step actions. Default: 0.EXPLAIN PIPELINESettings:
header- print header for each output port. Default: 0.graph- use DOT graph description language. Default: 0.compact- print graph in compact mode ifgraphis enabled. Default: 1.