You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ag...@apache.org on 2022/10/10 14:56:28 UTC

[arrow-datafusion] branch master updated: User Guide: Add `EXPLAIN` to SQL reference (#3767)

This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new e395e30cd User Guide: Add `EXPLAIN` to SQL reference (#3767)
e395e30cd is described below

commit e395e30cd972ba9684020a4167c12d1424675698
Author: unvalley <38...@users.noreply.github.com>
AuthorDate: Mon Oct 10 23:56:21 2022 +0900

    User Guide: Add `EXPLAIN` to SQL reference (#3767)
    
    * docs: add explain.md
    
    * docs: add explain to sql index
    
    * docs: describe explain at the beginning
    
    * docs: mention VERBOSE
---
 docs/source/user-guide/sql/explain.md | 71 +++++++++++++++++++++++++++++++++++
 docs/source/user-guide/sql/index.rst  |  1 +
 2 files changed, 72 insertions(+)

diff --git a/docs/source/user-guide/sql/explain.md b/docs/source/user-guide/sql/explain.md
new file mode 100644
index 000000000..08cc8be75
--- /dev/null
+++ b/docs/source/user-guide/sql/explain.md
@@ -0,0 +1,71 @@
+<!---
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+# EXPLAIN
+
+The `EXPLAIN` command shows the logical and physical execution plan for the specified SQL statement.
+
+<pre>
+EXPLAIN [ANALYZE] [VERBOSE] statement
+</pre>
+
+## EXPLAIN
+
+Shows the execution plan of a statement.
+If you need more details output, try to use `EXPLAIN VERBOSE`.
+
+```sql
+EXPLAIN SELECT SUM(x) FROM table GROUP BY b;
++---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| plan_type     | plan                                                                                                                                                           |
++---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| logical_plan  | Projection: #SUM(table.x)                                                                                                                                        |
+|               |   Aggregate: groupBy=[[#table.b]], aggr=[[SUM(#table.x)]]                                                                                                          |
+|               |     TableScan: table projection=[x, b]                                                                                                                           |
+| physical_plan | ProjectionExec: expr=[SUM(table.x)@1 as SUM(table.x)]                                                                                                              |
+|               |   AggregateExec: mode=FinalPartitioned, gby=[b@0 as b], aggr=[SUM(table.x)]                                                                                      |
+|               |     CoalesceBatchesExec: target_batch_size=4096                                                                                                                |
+|               |       RepartitionExec: partitioning=Hash([Column { name: "b", index: 0 }], 16)                                                                                 |
+|               |         AggregateExec: mode=Partial, gby=[b@1 as b], aggr=[SUM(table.x)]                                                                                         |
+|               |           RepartitionExec: partitioning=RoundRobinBatch(16)                                                                                                    |
+|               |             CsvExec: source=Path(/tmp/table.csv: [/tmp/table.csv]), has_header=false, limit=None, projection=[x, b]                                            |
+|               |                                                                                                                                                                |
++---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+```
+
+## EXPLAIN ANALYZE
+
+Shows the execution plan and metrics of a statment.
+If you need more information output, try to use `EXPLAIN ANALYZE VERBOSE`.
+
+```sql
+EXPLAIN ANALYZE SELECT SUM(x) FROM table GROUP BY b;
++-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
+| plan_type         | plan                                                                                                                                                      |
++-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
+| Plan with Metrics | CoalescePartitionsExec, metrics=[]                                                                                                                        |
+|                   |   ProjectionExec: expr=[SUM(table.x)@1 as SUM(x)], metrics=[]                                                                                             |
+|                   |     HashAggregateExec: mode=FinalPartitioned, gby=[b@0 as b], aggr=[SUM(x)], metrics=[outputRows=2]                                                       |
+|                   |       CoalesceBatchesExec: target_batch_size=4096, metrics=[]                                                                                             |
+|                   |         RepartitionExec: partitioning=Hash([Column { name: "b", index: 0 }], 16), metrics=[sendTime=839560, fetchTime=122528525, repartitionTime=5327877] |
+|                   |           HashAggregateExec: mode=Partial, gby=[b@1 as b], aggr=[SUM(x)], metrics=[outputRows=2]                                                          |
+|                   |             RepartitionExec: partitioning=RoundRobinBatch(16), metrics=[fetchTime=5660489, repartitionTime=0, sendTime=8012]                              |
+|                   |               CsvExec: source=Path(/tmp/table.csv: [/tmp/table.csv]), has_header=false, metrics=[]                                                        |
++-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
+```
diff --git a/docs/source/user-guide/sql/index.rst b/docs/source/user-guide/sql/index.rst
index ff98d95f3..373d60eb1 100644
--- a/docs/source/user-guide/sql/index.rst
+++ b/docs/source/user-guide/sql/index.rst
@@ -25,6 +25,7 @@ SQL Reference
    select
    subqueries
    ddl
+   explain
    information_schema
    aggregate_functions
    scalar_functions