forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
26 lines
11 KiB
HTML
26 lines
11 KiB
HTML
<a name="EN-US_TOPIC_0000001147351103"></a><a name="EN-US_TOPIC_0000001147351103"></a>
|
|
|
|
<h1 class="topictitle1">Overview of the SQL Execution Plan</h1>
|
|
<div id="body0000001147351103"><p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_a1e0fa245530744908b4411c762439d3b">The SQL execution plan is a node tree, which displays detailed procedure when <span id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_text215991742">GaussDB(DWS)</span> runs an SQL statement. A database operator indicates one step.</p>
|
|
<p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_aca2729a5928e40c29e9b75c18f456aed">You can run the <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b842352706145225">EXPLAIN</strong> command to view the execution plan generated for each query by an optimizer. Explain outputs a row of information for each execution node, showing the basic node type and the expense estimate that the optimizer makes for executing the node. See <a href="#EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_fea51e22e1a004029882c2b264b9075e4">Figure 1</a>.</p>
|
|
<div class="fignone" id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_fea51e22e1a004029882c2b264b9075e4"><a name="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_fea51e22e1a004029882c2b264b9075e4"></a><a name="en-us_topic_0000001098974940_fea51e22e1a004029882c2b264b9075e4"></a><span class="figcap"><b>Figure 1 </b>SQL execution plan example</span><br><span><img id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_iebe46d2ab25d43c2acc81c1a42640e0b" src="figure/en-us_image_0000001145695169.jpg"></span></div>
|
|
<ul id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_u8984d754562c407fa7f95beef88303ab"><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_l94d41b9829904e3a9f9e00a7d3c1a123">Nodes at the bottom level are scan nodes. They scan tables and return raw rows. The types of scan nodes (sequential scans and index scans) vary depending on the table access methods. Objects scanned by the bottom layer nodes may not be row-store data (not directly read from a table), such as VALUES clauses and functions that return rows, which have their own types of scan nodes.</li><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_l61d560be339a4e9ba81d437bb1596aa1">If the query requires join, aggregation, sorting, or other operations on the raw rows, there will be other nodes above the scan nodes to perform these operations. In addition, there is more than one possible way to perform these operations, so different execution node types may be displayed here. </li><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_l64520351c7e84b72a61e741f1a7a2baa">The first row (the upper-layer node) estimates the total execution cost of the execution plan. This value indicates the value that the optimizer tries to minimize.</li></ul>
|
|
<div class="section" id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_s4923b1e02940419b9047c9af9e1fb4c1"><h4 class="sectiontitle">Execution Plan Display Format</h4><p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_a562ccc14b21444f5814960102e83c2ac"><span id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_text2007854486">GaussDB(DWS)</span> provides four display formats: <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b842352706163854">normal</strong>, <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b842352706163848">pretty</strong>, <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b842352706163858">summary</strong>, and <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b84235270616392">run</strong>.</p>
|
|
<ul id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_u2f18dd73393d40fb8e43e9576ec3a6e9"><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_l137c1ab965184b41aefeb9871cf1c85a"><strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b84235270693855">normal</strong> indicates that the default printing format is used. <a href="#EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_fea51e22e1a004029882c2b264b9075e4">Figure 1</a> shows the display format.</li><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_lb2dc49cc36ff4f82b7b901d96074cea9"><strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b673618517448">pretty</strong> indicates that the optimized display mode of <span id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_text1859916170">GaussDB(DWS)</span> is used. A new format contains a plan node ID, directly and effectively analyzing performance. as shown in <a href="#EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_f38ec674913084bccbe6bad67c4bc8fee">Figure 2</a>.</li><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_l1a5ba1959c0a4c38b4610ce6520b1469"><strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_en-us_topic_0059778871_en-us_topic_0058967732_b84235270693923">summary</strong> indicates that the analysis result based on such information is printed in addition to the printed information in the format specified by <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_en-us_topic_0059778871_b404011371162013">pretty</strong>.</li><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_lf53f1b60e3df4e14bb27ef0711022564"><strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b84235270694014">run</strong> indicates that in addition to the printed information specified by <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b1580299207175059">summary</strong>, the database exports the information as a CSV file.</li></ul>
|
|
</div>
|
|
<div class="fignone" id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_f38ec674913084bccbe6bad67c4bc8fee"><a name="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_f38ec674913084bccbe6bad67c4bc8fee"></a><a name="en-us_topic_0000001098974940_f38ec674913084bccbe6bad67c4bc8fee"></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_0000001147351103__en-us_topic_0000001098974940_image14875643161613" src="figure/en-us_image_0000001145815093.png"></span></div>
|
|
<p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_aae0ad96340e645eca237d0865ead8422">You can change the display format of execution plans by setting <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b842352706153639">explain_perf_mode</strong>. Later examples use the pretty format by default.</p>
|
|
<div class="section" id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_s33a790a7a44c443a891756b54f7b030b"><h4 class="sectiontitle">Execution Plan Information</h4><p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_a7071bf87821845cf8a3f77cd331a107c">In addition to setting different display formats for an execution plan, you can use different <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b84235270615446">EXPLAIN</strong> syntax to display execution plan information in details. The following lists the common <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b93492176323">EXPLAIN</strong> syntax. For details, see EXPLAIN.</p>
|
|
<ul id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_u0247f55773834ef6ac2156e0257869fe"><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_lf2b8ec64529f44a29493f776e45098ca">EXPLAIN <em id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_i899108806163022">statement</em>: only generates an execution plan and does not execute. The <em id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_i842352697164752">statement</em> indicates SQL statements.</li><li id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_lf45aac639fe44ed2a1467391a8e5e054">EXPLAIN ANALYZE <em id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_i1361122679163048">statement</em>: generates and executes an execution plan, and displays the execution summary. Then actual execution time statistics are added to the display, 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_0000001147351103__en-us_topic_0000001098974940_l10659f0ae8c24e50b11e0587adecd74b">EXPLAIN PERFORMANCE <em id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_i100039264164145">statement</em>: generates and executes the execution plan, and displays all execution information.</li></ul>
|
|
<p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_ac60e6a1b4bb4419aac6799b4eca2c3f8">To measure the run time cost of each node in the execution plan, the current execution of <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b372029376173110">EXPLAIN ANALYZE</strong> or <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b372029376173121">EXPLAIN PERFORMANCE</strong> adds profiling overhead to query execution. Running <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b2080892317173155">EXPLAIN ANALYZE</strong> or <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_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.</p>
|
|
<p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_p157271209356">Therefore, if an SQL statement is not finished after being running for a long time, run the <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b842352706165627">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_0000001147351103__en-us_topic_0000001098974940_b84235270611336">EXPLAIN ANALYZE</strong> or <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b84235270611348">EXPLAIN PERFORMANCE</strong> statement to check the execution plan and information to locate the fault.</p>
|
|
<p id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_ae40387b875ea495b8e22a740cf58725a">The <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b5516113013557">EXPLAIN PERFORMANCE</strong> lightweight execution is consistent with <strong id="EN-US_TOPIC_0000001147351103__en-us_topic_0000001098974940_b1427514520559">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="dws_04_0403.html">Query Analysis</a></div>
|
|
</div>
|
|
</div>
|
|
|