Commits


alamb authored and Andy Grove committed 2dcc9a1031a
ARROW-9654: [Rust][DataFusion] Add `EXPLAIN <SQL>` statement In order to help users and developers understand what DataFusion's planner is doing, this PR adds an `"EXPLAIN PLAN"` feature. All other database systems I have worked with have such a feature (e.g. see [MySql](https://dev.mysql.com/doc/refman/8.0/en/explain-output.html)). Example printout (the plans printed are simply the `std::fmt::Debug` representation of the plan structures:) ``` > explain SELECT status, COUNT(1) FROM http_api_requests_total WHERE path = '/api/v2/write' GROUP BY status; +--------------+----------------------------------------------------------------------+ | plan_type | plan | +--------------+----------------------------------------------------------------------+ | logical_plan | Aggregate: groupBy=[[#status]], aggr=[[COUNT(UInt8(1))]] | | | Selection: #path Eq Utf8("/api/v2/write") And #path Eq Utf8("foo") | | | TableScan: http_api_requests_total projection=None | +--------------+----------------------------------------------------------------------+ 1 rows in set. Query took 0 seconds. ``` and ``` > explain VERBOSE SELECT status, COUNT(1) FROM http_api_requests_total WHERE path = '/api/v2/write' GROUP BY status; +-----------------------------------------+----------------------------------------------------------------------+ | plan_type | plan | +-----------------------------------------+----------------------------------------------------------------------+ | logical_plan | Aggregate: groupBy=[[#status]], aggr=[[COUNT(UInt8(1))]] | | | Selection: #path Eq Utf8("/api/v2/write") And #path Eq Utf8("foo") | | | TableScan: http_api_requests_total projection=None | | logical_plan after projection_push_down | Aggregate: groupBy=[[#status]], aggr=[[COUNT(UInt8(1))]] | | | Selection: #path Eq Utf8("/api/v2/write") And #path Eq Utf8("foo") | | | TableScan: http_api_requests_total projection=Some([6, 8]) | | logical_plan after type_coercion | Aggregate: groupBy=[[#status]], aggr=[[COUNT(UInt8(1))]] | | | Selection: #path Eq Utf8("/api/v2/write") And #path Eq Utf8("foo") | | | TableScan: http_api_requests_total projection=Some([6, 8]) | | physical_plan | HashAggregateExec { | | | group_expr: [ | | | Column { | | | name: "status", | | | }, | | | ], | | | aggr_expr: [ | | | Count { | | | expr: Literal { | | | value: UInt8( | | | 1, | | | ), | | | }, | | | }, | | | ], | | | input: SelectionExec { | | | expr: BinaryExpr { | | | left: BinaryExpr { | | | left: Column { | | | name: "path", | | | }, | | | op: Eq, | | | right: Literal { | | | value: Utf8( | | | "/api/v2/write", | | | ), | | | }, | | | }, | | | op: And, | | | right: BinaryExpr { | | | left: Column { | | | name: "path", | | | }, | | | op: Eq, | | | right: Literal { | | | value: Utf8( | | | "foo", | | | ), | | | }, | | | }, | | | }, | | | input: DataSourceExec { | | | schema: Schema { | | | fields: [ | | | Field { | | | name: "path", | | | data_type: Utf8, | | | nullable: true, | | | dict_id: 0, | | | dict_is_ordered: false, | | | }, | | | Field { | | | name: "status", | | | data_type: Utf8, | | | nullable: true, | | | dict_id: 0, | | | dict_is_ordered: false, | | | }, | | | ], | | | metadata: {}, | | | }, | | | partitions.len: 1, | | | }, | | | }, | | | schema: Schema { | | | fields: [ | | | Field { | | | name: "status", | | | data_type: Utf8, | | | nullable: true, | | | dict_id: 0, | | | dict_is_ordered: false, | | | }, | | | Field { | | | name: "COUNT(UInt8(1))", | | | data_type: UInt64, | | | nullable: true, | | | dict_id: 0, | | | dict_is_ordered: false, | | | }, | | | ], | | | metadata: {}, | | | }, | | | } | +-----------------------------------------+----------------------------------------------------------------------+ 4 row in set. Query took 0 seconds. ``` Closes #7959 from alamb/alamb/ARROW-9654-explain Authored-by: alamb <andrew@nerdnetworks.org> Signed-off-by: Andy Grove <andygrove73@gmail.com>