forked from docs/doc-exports
Reviewed-by: Wagner, Fabian <fabian.wagner@t-systems.com> Co-authored-by: wangdengke2 <wangdengke2@huawei.com> Co-committed-by: wangdengke2 <wangdengke2@huawei.com>
32 lines
8.4 KiB
HTML
32 lines
8.4 KiB
HTML
<a name="EN-US_TOPIC_0000002088517706"></a><a name="EN-US_TOPIC_0000002088517706"></a>
|
|
|
|
<h1 class="topictitle1">Overview</h1>
|
|
<div id="body0000001161466628"><p id="EN-US_TOPIC_0000002088517706__p14942mcpsimp">A SQL execution plan is a node tree, which displays detailed procedure when <span id="EN-US_TOPIC_0000002088517706__text665095915261">GaussDB</span> runs a SQL statement. A database operator indicates one step.</p>
|
|
<p id="EN-US_TOPIC_0000002088517706__p14943mcpsimp">You can run the <strong id="EN-US_TOPIC_0000002088517706__b576655816112930">EXPLAIN</strong> command to view execution plans generated for each query by an optimizer. The output of <strong id="EN-US_TOPIC_0000002088517706__b733314309536">EXPLAIN</strong> has one row for each execution node, showing the basic node type and the cost estimation that the optimizer made for the execution of this node. <a href="#EN-US_TOPIC_0000002088517706___d0e37190">Figure 1</a> shows an example.</p>
|
|
<div class="fignone" id="EN-US_TOPIC_0000002088517706___d0e37190"><a name="EN-US_TOPIC_0000002088517706___d0e37190"></a><a name="_d0e37190"></a><span class="figcap"><b>Figure 1 </b>SQL execution plan example</span><br><span><img id="EN-US_TOPIC_0000002088517706__image378" src="figure/en-us_image_0000002124277597.jpg" height="138.32" width="522.69" title="Click to enlarge" class="imgResize"></span></div>
|
|
<ul id="EN-US_TOPIC_0000002088517706__ul14946mcpsimp"><li id="EN-US_TOPIC_0000002088517706__li14947mcpsimp">The bottom-layer node is the table scan node, which scans the table and returns the original data rows. The types of scan nodes (sequential scans and index scans) vary depending on the table access methods. The scan object of the bottom-layer node may also be non-table row data (that is not directly read from the table), such as the VALUES clause and the function that returns a row set. They have their own scan node types.</li><li id="EN-US_TOPIC_0000002088517706__li14948mcpsimp">If a query requires joining, aggregation, sorting, or other operations on the original row, other nodes are added to the scan node. In addition, there is more than one way to perform these operations, so different types of execution nodes may be displayed.</li><li id="EN-US_TOPIC_0000002088517706__li14949mcpsimp">The first row (the upper-layer node) estimates the total execution cost of the execution plan. Such an estimate indicates the value that the optimizer tries to minimize.</li></ul>
|
|
<div class="section" id="EN-US_TOPIC_0000002088517706__section14950mcpsimp"><h4 class="sectiontitle">Execution Plan Display Format</h4><p id="EN-US_TOPIC_0000002088517706__p14952mcpsimp"><span id="EN-US_TOPIC_0000002088517706__text1113913122913">GaussDB</span> provides four display formats: <strong id="EN-US_TOPIC_0000002088517706__b474223314112930">normal</strong>, <strong id="EN-US_TOPIC_0000002088517706__b1666243905112930">pretty</strong>, <strong id="EN-US_TOPIC_0000002088517706__b1528295683112930">summary</strong>, and <strong id="EN-US_TOPIC_0000002088517706__b1689952077112930">run</strong>.</p>
|
|
<ul id="EN-US_TOPIC_0000002088517706__ul14953mcpsimp"><li id="EN-US_TOPIC_0000002088517706__li14954mcpsimp"><strong id="EN-US_TOPIC_0000002088517706__b19718472242">normal</strong> indicates that the default printing format is used, as shown in <a href="#EN-US_TOPIC_0000002088517706___d0e37190">Figure 1</a>.</li><li id="EN-US_TOPIC_0000002088517706__li14956mcpsimp"><strong id="EN-US_TOPIC_0000002088517706__b1254312010219">pretty</strong> indicates the optimized display format of <span id="EN-US_TOPIC_0000002088517706__text132568922913">GaussDB</span> is used. The new format contains a plan node ID, directly and effectively analyzing performance, as shown in <a href="#EN-US_TOPIC_0000002088517706___d0e37226">Figure 2</a>.</li><li id="EN-US_TOPIC_0000002088517706__li14958mcpsimp"><strong id="EN-US_TOPIC_0000002088517706__b1758111812267">summary</strong> indicates that analysis of the <strong id="EN-US_TOPIC_0000002088517706__b127641518122613">pretty</strong> printed information is added.</li><li id="EN-US_TOPIC_0000002088517706__li14959mcpsimp"><strong id="EN-US_TOPIC_0000002088517706__b1010203716265">run</strong> indicates that the system exports the printed information specified by <strong id="EN-US_TOPIC_0000002088517706__b1618437162611">summary</strong> as a CSV file for further analysis.</li></ul>
|
|
<div class="fignone" id="EN-US_TOPIC_0000002088517706___d0e37226"><a name="EN-US_TOPIC_0000002088517706___d0e37226"></a><a name="_d0e37226"></a><span class="figcap"><b>Figure 2 </b>Example of an execution plan using the pretty format</span><br><span><img id="EN-US_TOPIC_0000002088517706__image379" src="figure/en-us_image_0000002124197301.png" height="119.7" width="518.7" title="Click to enlarge" class="imgResize"></span></div>
|
|
<p id="EN-US_TOPIC_0000002088517706__p14961mcpsimp">You can change the display formats of execution plans by configuring <strong id="EN-US_TOPIC_0000002088517706__b705173623112930">explain_perf_mode</strong>. Later examples use the pretty format by default.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000002088517706__section14962mcpsimp"><h4 class="sectiontitle">Execution Plan Information</h4><p id="EN-US_TOPIC_0000002088517706__p14964mcpsimp">In addition to configuring different display formats for execution plans, you can use different <strong id="EN-US_TOPIC_0000002088517706__b1185101439112930">EXPLAIN</strong> syntax to display execution plan information in detail. </p>
|
|
<ul id="EN-US_TOPIC_0000002088517706__ul14967mcpsimp"><li id="EN-US_TOPIC_0000002088517706__li14968mcpsimp">EXPLAIN <em id="EN-US_TOPIC_0000002088517706__i14969mcpsimp">statement</em>: only generates an execution plan and does not execute. The <em id="EN-US_TOPIC_0000002088517706__i842352697164752">statement</em> indicates SQL statements.</li><li id="EN-US_TOPIC_0000002088517706__li14970mcpsimp">EXPLAIN ANALYZE <em id="EN-US_TOPIC_0000002088517706__i14971mcpsimp">statement</em>: generates and executes an execution plan, and displays the execution summary. Then actual execution time statistics are added, including the total elapsed time expended within each plan node (in milliseconds) and the total number of rows it actually returned.</li><li id="EN-US_TOPIC_0000002088517706__li14972mcpsimp">EXPLAIN PERFORMANCE <em id="EN-US_TOPIC_0000002088517706__i14973mcpsimp">statement</em>: generates and executes an execution plan, and displays all execution information.</li></ul>
|
|
<p id="EN-US_TOPIC_0000002088517706__p14974mcpsimp">To measure the run time cost of each node in the execution plan, the current execution of <strong id="EN-US_TOPIC_0000002088517706__b1599471915112930">EXPLAIN ANALYZE</strong> or <strong id="EN-US_TOPIC_0000002088517706__b1332928123112930">EXPLAIN PERFORMANCE</strong> adds profiling overhead to query execution. Running <strong id="EN-US_TOPIC_0000002088517706__b2080892317173155">EXPLAIN ANALYZE</strong> or <strong id="EN-US_TOPIC_0000002088517706__b1900799391173155">PERFORMANCE</strong> on a query sometimes takes longer time than executing the query normally. The amount of overhead depends on the nature of the query, as well as the platform being used. For details, see "SQL Reference" > "SQL Syntax" > "EXPLAIN" in <em id="EN-US_TOPIC_0000002088517706__i13871637288">GaussDB Developer Guide (1.x)</em>.</p>
|
|
<p id="EN-US_TOPIC_0000002088517706__p14975mcpsimp">Therefore, if a SQL statement is not finished after being running for a long time, run the <strong id="EN-US_TOPIC_0000002088517706__b1850153125820">EXPLAIN</strong> statement to view the execution plan and then locate the fault. If the SQL statement has been properly executed, run the <strong id="EN-US_TOPIC_0000002088517706__b1467171370112930">EXPLAIN ANALYZE</strong> or <strong id="EN-US_TOPIC_0000002088517706__b1338292865112930">EXPLAIN PERFORMANCE</strong> statement to check the execution plan and information to locate the fault.</p>
|
|
<p id="EN-US_TOPIC_0000002088517706__p14976mcpsimp">The <strong id="EN-US_TOPIC_0000002088517706__b1748818272112930">EXPLAIN PERFORMANCE</strong> lightweight execution is consistent with <strong id="EN-US_TOPIC_0000002088517706__b1717142157112930">EXPLAIN PERFORMANCE</strong> but greatly reduces the time spent on performance analysis.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="opengauss_opti_0031.html">Introduction to the SQL Execution Plan</a></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script language="JavaScript">
|
|
<!--
|
|
image_size('.imgResize');
|
|
var msg_imageMax = "view original image";
|
|
var msg_imageClose = "close";
|
|
//--></script> |