GreptimeTeam / greptimedb

An open-source, cloud-native, unified time series database for metrics, logs and events with SQL/PromQL supported. Available on GreptimeCloud.
https://greptime.com/
Apache License 2.0
4.19k stars 299 forks source link

Push down analyze verbose to region #4408

Open evenyag opened 1 month ago

evenyag commented 1 month ago

What type of enhancement is this?

User experience

What does the enhancement do?

explan verbose analyze can't push down the verbose flag

explain analyze verbose select hostname, usage_user, usage_system, usage_idle, usage_nice from CPU;

+-------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| stage | node | plan                                                                                                                                                                                        |
+-------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|     0 |    0 |  MergeScanExec: peers=[4398046511104(1024, 0), ] metrics=[output_rows: 103680000, greptime_exec_read_cost: 0, finish_time: 1366352665, ready_time: 644540, first_consume_time: 29508243, ]  |
|     1 |    0 |  SeqScan: partition_count=8 (0 memtable ranges, 12 file ranges) metrics=[output_rows: 103680000, mem_used: 7083630784, ]                                                                    |
|  NULL | NULL | Total rows: 103680000                                                                                                                                                                       |
+-------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (1.38 sec)

Implementation challenges

The output of explain analyze is collected by the DistAnalyzeExec. https://github.com/GreptimeTeam/greptimedb/blob/2ae2a6674e8a780cb93723de9b749b65ea28562e/src/query/src/analyze.rs#L134-L142

https://github.com/GreptimeTeam/greptimedb/blob/2ae2a6674e8a780cb93723de9b749b65ea28562e/src/query/src/analyze.rs#L203-L222

The MergeScanExec will collect metrics from each region's output stream https://github.com/GreptimeTeam/greptimedb/blob/2ae2a6674e8a780cb93723de9b749b65ea28562e/src/query/src/dist_plan/merge_scan.rs#L260-L274

The metric of a stream will use one_line() to format the plan, which always uses the default level. https://github.com/GreptimeTeam/greptimedb/blob/2ae2a6674e8a780cb93723de9b749b65ea28562e/src/common/recordbatch/src/adapter.rs#L302-L311

We have to find a way to push down the verbose level. Then we can use the indent() method to display the plan