v.22.7Improvement

New rewrite Option in EXPLAIN AST to Show Rewritten AST

New option rewrite in EXPLAIN AST. If enabled, it shows AST after it's rewritten, otherwise AST of original query. Disabled by default. #38910 (Igor Nikonov).
Added a new rewrite option to the EXPLAIN AST command in ClickHouse to display the abstract syntax tree (AST) after query rewriting.

Why it matters

This feature provides users with the ability to see the rewritten version of the query's AST, helping to better understand how ClickHouse transforms queries internally for optimization and execution. It aids in debugging and optimizing query behavior by comparing the original and rewritten AST.

How to use it

Use the EXPLAIN AST command with the rewrite option enabled to view the AST after rewriting. By default, this option is disabled and only shows the original AST. Example:

EXPLAIN AST rewrite <your_query>