apache / pinot

Apache Pinot - A realtime distributed OLAP datastore
https://pinot.apache.org/
Apache License 2.0
5.39k stars 1.26k forks source link

Support SQL EXPLAIN PLAN FOR <query> #6978

Open siddharthteotia opened 3 years ago

siddharthteotia commented 3 years ago

Background

Standard SQL supports EXPLAIN plan functionality. The output of EXPLAIN is the physical execution plan (in a tree format) giving overview of the physical relational operators that will be used to execute the query. The query plan is always interpreted bottom-up (industry standard in databases).

In most databases (both OLTP and OLAP), the EXPLAIN plan also outputs the cost of the query (for each operator in the tree). The cost is mostly in terms of CPU, I/O that the operator might consume during the course of query execution. The numbers are based on estimates and statistics (rowCount etc) that databases commonly maintain per table for query optimizers to generate the best execution plan during the query planning process. This is commonly referred to as Estimated execution plan in database parlance.

Next is Actual execution plan which annotates the operator tree in estimated execution plan with profiling information (wall-clock time, cpu, I/O waits, numRows from one operator to another etc) collected during the execution of the query.

Proposal

Add support for EXPLAIN PLAN FOR <SQL QUERY>

The output of the command should be the physical execution plan

Physical execution plan must include the following

Note that SQL QUERY inside FOR clause won’t be executed.

Can consider to enhance the cluster manager controller UI that runs the EXPLAIN query to allow for visualizing and saving/downloading the plan (to XML, JSON etc)

We can optionally configure to run EXPLAIN PLAN for displaying the calcite logical plan. This may not be feasible for the following reasons

Additional Goal

We will add support for profiling (timing) the different stages (scan, filter, group by, sort, project, reduce) of the query execution.

How does this fit in?

When a user runs the SQL query (without EXPLAIN)

When a user runs the EXPLAIN FOR SQL query

This is also the behavior supported by SQL Server for example.

The key thing here is profiling info. We recently added support for measuring query execution cpu time on servers. It accounts for everything under Combine operator. We should continue to use this over wall-clock/elapsed time. But this requires some performance experiments to see if pushing down cpu time based instrumentation at the operator level will introduce any overhead or not. In any case, we have the cpu time info for Combine operator so that can be put in the actual execution plan.

siddharthteotia commented 3 years ago

We have started working on this. Will be sharing design/details etc with the community.

richardstartin commented 2 years ago

This seems to overlap with the existing query tracing functionality, was enhancing that to include CPU time (it already records operator level wall time) considered? What will this offer which the existing tracing solution doesn't?