Yang, Tong 3f5759eed2 MRS comp-lts 2.0.38.SP20 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2023-01-19 17:08:45 +00:00

81 lines
4.4 KiB
HTML

<a name="mrs_01_0982"></a><a name="mrs_01_0982"></a>
<h1 class="topictitle1">Optimizing SQL Statements</h1>
<div id="body8662426"><div class="section" id="mrs_01_0982__en-us_topic_0000001219149073_section54613993212"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_0982__en-us_topic_0000001219149073_p3461139163215">When SQL statements are executed on Hive, if the <span class="parmname" id="mrs_01_0982__en-us_topic_0000001219149073_p2195a583a20f4de89c794e8089af52da"><b>(a&amp;b) or (a&amp;c)</b></span> logic exists in the statements, you are advised to change the logic to <span class="parmname" id="mrs_01_0982__en-us_topic_0000001219149073_p20135311881549babc02a2f6bb15e8bc"><b>a &amp; (b or c)</b></span>.</p>
</div>
<div class="section" id="mrs_01_0982__en-us_topic_0000001219149073_section54619912329"><h4 class="sectiontitle">Example</h4><p id="mrs_01_0982__en-us_topic_0000001219149073_p124611917324">If condition a is <span class="parmvalue" id="mrs_01_0982__en-us_topic_0000001219149073_p5eff0f20e43642dbaf429777f5716bf9"><b>p_partkey = l_partkey</b></span>, the statements before optimization are as follows:</p>
<pre class="screen" id="mrs_01_0982__en-us_topic_0000001219149073_screen20461139153215">select
sum(l_extendedprice* (1 - l_discount)) as revenue
from
lineitem,
part
where
(
<strong id="mrs_01_0982__en-us_topic_0000001219149073_b24613933211">p_partkey = l_partkey </strong>
and p_brand = 'Brand#32'
and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
and l_quantity &gt;= 7 and l_quantity &lt;= 7 + 10
and p_size between 1 and 5
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
)
or
( <strong id="mrs_01_0982__en-us_topic_0000001219149073_b74611297322">p_partkey = l_partkey</strong>
and p_brand = 'Brand#35'
and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
and l_quantity &gt;= 15 and l_quantity &lt;= 15 + 10
and p_size between 1 and 10
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
)
or
( <strong id="mrs_01_0982__en-us_topic_0000001219149073_b134629973216">p_partkey = l_partkey</strong>
and p_brand = 'Brand#24'
and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
and l_quantity &gt;= 26 and l_quantity &lt;= 26 + 10
and p_size between 1 and 15
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
)</pre>
<p id="mrs_01_0982__en-us_topic_0000001219149073_p11462198321">The statements after optimization are as follows:</p>
<pre class="screen" id="mrs_01_0982__en-us_topic_0000001219149073_screen1946213983214">select
sum(l_extendedprice* (1 - l_discount)) as revenue
from
lineitem,
part
where <strong id="mrs_01_0982__en-us_topic_0000001219149073_b1146217983216"> p_partkey = l_partkey</strong> and
((
p_brand = 'Brand#32'
and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
and l_quantity &gt;= 7 and l_quantity &lt;= 7 + 10
and p_size between 1 and 5
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
)
or
(
p_brand = 'Brand#35'
and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
and l_quantity &gt;= 15 and l_quantity &lt;= 15 + 10
and p_size between 1 and 10
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
)
or
(
p_brand = 'Brand#24'
and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
and l_quantity &gt;= 26 and l_quantity &lt;= 26 + 10
and p_size between 1 and 15
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
))</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_0977.html">Hive Performance Tuning</a></div>
</div>
</div>