forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
90 lines
18 KiB
HTML
90 lines
18 KiB
HTML
<a name="EN-US_TOPIC_0000001188323576"></a><a name="EN-US_TOPIC_0000001188323576"></a>
|
|
|
|
<h1 class="topictitle1">SQL Self-Diagnosis</h1>
|
|
<div id="body1530499427336"><p id="EN-US_TOPIC_0000001188323576__p11285145044511">Performance problems may occur when you run the <strong id="EN-US_TOPIC_0000001188323576__b114717457190">INSERT/UPDATE/DELETE/SELECT/MERGE INTO</strong> or <strong id="EN-US_TOPIC_0000001188323576__b84021550141914">CREATE TABLE AS</strong> statement. The product supports automatic performance diagnosis and saves related diagnosis information to the <a href="dws_04_0397.html">Real-time Top SQL</a>. When <strong id="EN-US_TOPIC_0000001188323576__b1501832232">enable_resource_track</strong> is set to <strong id="EN-US_TOPIC_0000001188323576__b32416652316">on</strong>, the diagnosis information is dumped to the <a href="dws_04_0398.html">Historical Top SQL</a>. You can query the warning field in the views <a href="dws_04_0706.html">GS_WLM_SESSION_STATISTICS</a>, <a href="dws_04_0705.html">GS_WLM_SESSION_HISTORY</a>, <a href="dws_04_0566.html">GS_WLM_SESSION_INFO</a> in <em id="EN-US_TOPIC_0000001188323576__i155235132914">Developer Guide</em> to obtain the corresponding performance diagnosis information for performance optimization.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p3467204017162">Alarms that can trigger SQL self-diagnosis depend on the settings of <a href="dws_04_0922.html#EN-US_TOPIC_0000001233563121__section153571329142612">resource_track_level</a>. When <strong id="EN-US_TOPIC_0000001188323576__b14513153993417">resource_track_level</strong> is set to <strong id="EN-US_TOPIC_0000001188323576__b392185523419">query</strong>, you can diagnose alarms such as uncollected multi-column/single-column statistics, partitions not pruned, and failure of pushing down SQL statements. When <strong id="EN-US_TOPIC_0000001188323576__b6689102113388">resource_track_level</strong> is set to <strong id="EN-US_TOPIC_0000001188323576__b7569192519381">perf</strong> or <strong id="EN-US_TOPIC_0000001188323576__b19609132810389">operator</strong>, all alarms can be diagnosed.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p17329109171812">Whether a SQL plan will be diagnosed depends on the settings of <a href="dws_04_0922.html#EN-US_TOPIC_0000001233563121__section1089022732713">resource_track_cost</a>. A SQL plan will be diagnosed only if its execution cost is greater than <strong id="EN-US_TOPIC_0000001188323576__b1889174383417">resource_track_cost</strong>. You can use the <strong id="EN-US_TOPIC_0000001188323576__b1858105916359">EXPLAIN</strong> keyword to check the plan execution cost.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p129625506495">When <strong id="EN-US_TOPIC_0000001188323576__b1728216227394">EXPLAIN PERFORMANCE</strong> or <strong id="EN-US_TOPIC_0000001188323576__b95991925193912">EXPLAIN VERBOSE</strong> is executed, SQL self-diagnosis information, except that without multi-column statistics, will be generated. For details, see <a href="dws_04_0432.html">SQL Execution Plan</a>.</p>
|
|
<div class="section" id="EN-US_TOPIC_0000001188323576__section1451592315913"><h4 class="sectiontitle">Alarms</h4><p id="EN-US_TOPIC_0000001188323576__p18285150154514">Currently, the following performance alarms will be reported:</p>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul17921548181010"><li id="EN-US_TOPIC_0000001188323576__li8793648191014">Statistics of a single column or multiple columns are not collected.<p id="EN-US_TOPIC_0000001188323576__p18528555185111"><a name="EN-US_TOPIC_0000001188323576__li8793648191014"></a><a name="li8793648191014"></a>If statistics of a single column or multiple columns are not collected, an alarm is reported. To handle this alarm, you are advised to perform <strong id="EN-US_TOPIC_0000001188323576__b13259538454">ANALYZE</strong> on related tables. For details, see <a href="dws_04_0436.html">Updating Statistics</a> and <a href="dws_04_0449.html">Optimizing Statistics</a>.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p3793144801018">If no statistics are collected for the OBS foreign table and HDFS foreign table in the query statement, an alarm indicating that statistics are not collected will be reported. Because the <strong id="EN-US_TOPIC_0000001188323576__b1242195174711">ANALYZE</strong> performance of the OBS foreign table and HDFS foreign table is poor, you are not advised to perform <strong id="EN-US_TOPIC_0000001188323576__b20387824134716">ANALYZE</strong> on these tables. Instead, you are advised to use the <strong id="EN-US_TOPIC_0000001188323576__b149974384810">ALTER FOREIGN TABLE</strong> syntax to modify the <strong id="EN-US_TOPIC_0000001188323576__b461151112482">totalrows</strong> attribute of the foreign table to correct the estimated number of rows.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p117951648201020">Example alarms:</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p4795194821018">The statistics about a table are not collected.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen207961348111019">Statistic Not Collect
|
|
schema_test.t1</pre>
|
|
<p id="EN-US_TOPIC_0000001188323576__p379744891020">The statistics about a single column are not collected.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen18797448111011">Statistic Not Collect
|
|
schema_test.t2(c1)</pre>
|
|
<p id="EN-US_TOPIC_0000001188323576__p147991248161018">The statistics about multiple columns are not collected.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen1979914881015">Statistic Not Collect
|
|
schema_test.t3((c1,c2))</pre>
|
|
<p id="EN-US_TOPIC_0000001188323576__p1680010488108">The statistics about a single column and multiple columns are not collected.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen188008483108">Statistic Not Collect
|
|
schema_test.t4(c1)
|
|
schema_test.t5((c1,c2))</pre>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul158021484107"><li id="EN-US_TOPIC_0000001188323576__li9624192019915">Partitions are not pruned (supported by 8.1.2 and later versions).<p id="EN-US_TOPIC_0000001188323576__p18797152116913"><a name="EN-US_TOPIC_0000001188323576__li9624192019915"></a><a name="li9624192019915"></a>When a partitioned table is queried, the partition is pruned based on the constraints on the partition key to improve the query performance. However, the partition table may not be pruned due to improper constraints, deteriorating the query performance. For details, see <a href="dws_04_0488.html">Case: Rewriting SQL Statements and Eliminating Prune Interference</a>.</p>
|
|
</li><li id="EN-US_TOPIC_0000001188323576__li4802148181010">SQL statements are not pushed down.<p id="EN-US_TOPIC_0000001188323576__p187099393226"><a name="EN-US_TOPIC_0000001188323576__li4802148181010"></a><a name="li4802148181010"></a>The cause details are displayed in the alarms. For details, see <a href="dws_04_0447.html">Optimizing Statement Pushdown</a>.</p>
|
|
<div class="p" id="EN-US_TOPIC_0000001188323576__p168039487109">The potential causes for the pushdown failure are as follows:<ul id="EN-US_TOPIC_0000001188323576__ul28031481105"><li id="EN-US_TOPIC_0000001188323576__li1780414871010">Caused by functions<p id="EN-US_TOPIC_0000001188323576__p370463462012"><a name="EN-US_TOPIC_0000001188323576__li1780414871010"></a><a name="li1780414871010"></a>The function name is displayed in the diagnosis information. Function pushdown is determined by the <strong id="EN-US_TOPIC_0000001188323576__b8387448115717">shippable</strong> attribute of the function. For details, see the <strong id="EN-US_TOPIC_0000001188323576__b143471559105718">CREATE FUNCTION</strong> syntax.</p>
|
|
</li><li id="EN-US_TOPIC_0000001188323576__li980424818107">Caused by syntax<p id="EN-US_TOPIC_0000001188323576__p3190163932720"><a name="EN-US_TOPIC_0000001188323576__li980424818107"></a><a name="li980424818107"></a>The diagnosis information displays the syntax that causes the pushdown failure. For example, if the statement contains the <strong id="EN-US_TOPIC_0000001188323576__b1318295155913">With Recursive</strong>, <strong id="EN-US_TOPIC_0000001188323576__b10285135413590">Distinct On</strong>, or <strong id="EN-US_TOPIC_0000001188323576__b20446205715595">row</strong> expression and the return value is of the record type, an alarm is reported, indicating that the syntax does not support pushdown.</p>
|
|
</li></ul>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001188323576__p4805144811108">Example alarms:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen580512486107">SQL is not plan-shipping
|
|
"enable_stream_operator" is off
|
|
|
|
SQL is not plan-shipping
|
|
"Distinct On" can not be shipped
|
|
|
|
SQL is not plan-shipping
|
|
"v_test_unshipping_log" is VIEW that will be treated as Record type can't be shipped</pre>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul6807448101012"><li id="EN-US_TOPIC_0000001188323576__li1980710481108">In a hash join, the larger table is used as the inner table.<p id="EN-US_TOPIC_0000001188323576__p7808134821017"><a name="EN-US_TOPIC_0000001188323576__li1980710481108"></a><a name="li1980710481108"></a>An alarm will be reported if the number of rows in the inner table reaches or exceeds 10 times of that in the foreign table, more than 100,000 inner-table rows are processed on each DN in average, and data has been flushed to disks. You can view the <strong id="EN-US_TOPIC_0000001188323576__b11565313135417">query_plan</strong> column in <a href="dws_04_0705.html">GS_WLM_SESSION_HISTORY</a> to check whether hash joins are used. In this scenario, you need to adjust the sequence of the HashJoin internal and foreign tables. For details, see <a href="dws_04_0456.html">Join Order Hints</a>.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p1981034815106">Example alarm:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen13947193117383">Execute diagnostic information
|
|
PlanNode[7] Large Table is INNER in HashJoin "Vector Hash Aggregate"</pre>
|
|
<p id="EN-US_TOPIC_0000001188323576__p1394710318387">In the preceding command, <strong id="EN-US_TOPIC_0000001188323576__b10123536123510">7</strong> indicates the operator whose ID is <strong id="EN-US_TOPIC_0000001188323576__b216817425350">7</strong> in the <strong id="EN-US_TOPIC_0000001188323576__b1945594473512">query_plan</strong> column.</p>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul17811154811106"><li id="EN-US_TOPIC_0000001188323576__li118124480107"><strong id="EN-US_TOPIC_0000001188323576__b136648167564">nestloop</strong> is used in a large-table equivalent join.<p id="EN-US_TOPIC_0000001188323576__p108121248131010">An alarm will be reported if nested loop is used in an equivalent join where more than 100,000 larger-table rows are processed on each DN in average. You can view the <strong id="EN-US_TOPIC_0000001188323576__b1646744015456">query_plan</strong> column of <a href="dws_04_0705.html">GS_WLM_SESSION_HISTORY</a> to check whether nested loop is used. In this scenario, you need to adjust the table join mode and disable the NestLoop join mode between the current internal and foreign tables. For details, see <a href="dws_04_0457.html">Join Operation Hints</a>.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p118142048161012">Example alarm:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen6814848181012">Execute diagnostic information
|
|
PlanNode[5] Large Table with Equal-Condition use Nestloop"Nested Loop"</pre>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul10815194841010"><li id="EN-US_TOPIC_0000001188323576__li178159483108">A large table is broadcasted.<p id="EN-US_TOPIC_0000001188323576__p381664819104"><a name="EN-US_TOPIC_0000001188323576__li178159483108"></a><a name="li178159483108"></a>An alarm will be reported if more than 100 thousand of rows are broadcasted on each DN in average. In this scenario, the broadcast operation of the BroadCast lower-layer operator needs to be disabled. For details, see <a href="dws_04_0459.html">Stream Operation Hints</a>.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p1381704815100">Example alarm:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen3817174811011">Execute diagnostic information
|
|
PlanNode[5] Large Table in Broadcast "Streaming(type: BROADCAST dop: 1/2)"</pre>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul1281820487104"><li id="EN-US_TOPIC_0000001188323576__li7818248171010">Data skew occurs.<p id="EN-US_TOPIC_0000001188323576__p3819154821018"><a name="EN-US_TOPIC_0000001188323576__li7818248171010"></a><a name="li7818248171010"></a>An alarm will be reported if the number of rows processed on any DN exceeds 100 thousand, and the number of rows processed on a DN reaches or exceeds 10 times of that processed on another DN. Generally, this alarm is generated due to storage layer skew or computing layer skew. For details, see <a href="dws_04_0451.html">Optimizing Data Skew</a>.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p2820948151017">Example alarm:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen1082094818101">Execute diagnostic information
|
|
PlanNode[6] DataSkew:"Seq Scan", min_dn_tuples:0, max_dn_tuples:524288</pre>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul19636114414589"><li id="EN-US_TOPIC_0000001188323576__li13636164410583">The index is improper.<p id="EN-US_TOPIC_0000001188323576__p930916541614"><a name="EN-US_TOPIC_0000001188323576__li13636164410583"></a><a name="li13636164410583"></a>During base table scanning, an alarm is reported if the following conditions are met:</p>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul2048918479205"><li id="EN-US_TOPIC_0000001188323576__li19363164514202">For row-store tables:<ul id="EN-US_TOPIC_0000001188323576__ul1296675572010"><li id="EN-US_TOPIC_0000001188323576__li15234115415203">When the index scanning is used, the ratio of the number of output lines to the number of scanned lines is greater than 1/1000 and the number of output lines is greater than 10,000.</li><li id="EN-US_TOPIC_0000001188323576__li123505420206">When sequential scanning is used, the number of output lines to the number of scanned lines is less than 1/1000, the number of output lines is less than or equal to 10,000, and the number of scanned lines is greater than 10,000.</li></ul>
|
|
</li><li id="EN-US_TOPIC_0000001188323576__li11368144513206">For column-store tables:<ul id="EN-US_TOPIC_0000001188323576__ul9716195902015"><li id="EN-US_TOPIC_0000001188323576__li8369645142017">When the index scanning is used, the ratio of the number of output lines to the number of scanned lines is greater than 1/10000 and the number of output lines is greater than 100.</li><li id="EN-US_TOPIC_0000001188323576__li337194552016">When sequential scanning is used, the number of output lines to the number of scanned lines is less than 1/10,000, the number of output lines is less than or equal to 100, and the number of scanned lines is greater than 10,000.</li></ul>
|
|
</li></ul>
|
|
<p id="EN-US_TOPIC_0000001188323576__p963684435813">For details, see <a href="dws_04_0450.html">Optimizing Operators</a>. You can also refer to <a href="dws_04_0476.html">Case: Creating an Appropriate Index</a> and <a href="dws_04_0490.html">Case: Setting Partial Cluster Keys</a>.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p19636114410584">Example alarms:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen1932122116599">Execute diagnostic information
|
|
PlanNode[4] Indexscan is not properly used:"Index Only Scan", output:524288, filtered:0, rate:1.00000
|
|
PlanNode[5] Indexscan is ought to be used:"Seq Scan", output:1, filtered:524288, rate:0.00000</pre>
|
|
<p id="EN-US_TOPIC_0000001188323576__p1153751663812">The diagnosis result is only a suggestion for the current SQL statement. You are advised to create an index only for frequently used filter criteria.</p>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001188323576__ul382164871019"><li id="EN-US_TOPIC_0000001188323576__li13821124881013">Estimation is inaccurate.<p id="EN-US_TOPIC_0000001188323576__p18221448171018"><a name="EN-US_TOPIC_0000001188323576__li13821124881013"></a><a name="li13821124881013"></a>An alarm will be reported if the maximum number or the estimated maximum number of rows processed on a DN is over 100,000, and the larger number reaches or exceeds 10 times of the smaller one. In this scenario, you can refer to <a href="dws_04_0458.html">Rows Hints</a> to correct the estimation on the number of rows, so that the optimizer can re-design the execution plan based on the correct number.</p>
|
|
<p id="EN-US_TOPIC_0000001188323576__p1082234851011">Example alarm:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen8823174831010">Execute diagnostic information
|
|
PlanNode[5] Inaccurate Estimation-Rows: "Hash Join" A-Rows:0, E-Rows:52488</pre>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188323576__section728715105125"><h4 class="sectiontitle">Restrictions</h4><ol id="EN-US_TOPIC_0000001188323576__ol3766410193914"><li id="EN-US_TOPIC_0000001188323576__li376601043910">An alarm contains a maximum of 2048 characters. If the length of an alarm exceeds this value (for example, a large number of long table names and column names are displayed in the alarm when their statistics are not collected), a warning instead of an alarm will be reported.<pre class="screen" id="EN-US_TOPIC_0000001188323576__screen8176184920816">WARNING, "Planner issue report is truncated, the rest of planner issues will be skipped"</pre>
|
|
</li><li id="EN-US_TOPIC_0000001188323576__li927851164020">If a query statement contains the <strong id="EN-US_TOPIC_0000001188323576__b26611304576">Limit</strong> operator, alarms of operators lower than <strong id="EN-US_TOPIC_0000001188323576__b166637304571">Limit</strong> will not be reported.</li><li id="EN-US_TOPIC_0000001188323576__li6364189104016">For alarms about data skew and inaccurate estimation, only alarms on the lower-layer nodes in a plan tree will be reported. This is because the same alarms on the upper-level nodes may be triggered by problems on the lower-layer nodes. For example, if data skew occurs on the <strong id="EN-US_TOPIC_0000001188323576__b11886105310294">Scan</strong> node, data skew may also occur in operators (for example, <strong id="EN-US_TOPIC_0000001188323576__b568793414315">Hashagg</strong>) at the upper layer.</li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0445.html">Typical SQL Optimization Methods</a></div>
|
|
</div>
|
|
</div>
|
|
|