forked from docs/doc-exports
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>
81 lines
4.0 KiB
HTML
81 lines
4.0 KiB
HTML
<a name="mrs_01_0982"></a><a name="mrs_01_0982"></a>
|
|
|
|
<h1 class="topictitle1">Optimizing SQL Statements</h1>
|
|
<div id="body1590395285873"><div class="section" id="mrs_01_0982__section54613993212"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_0982__p3461139163215">When SQL statements are executed on Hive, if the <span class="parmname" id="mrs_01_0982__p2195a583a20f4de89c794e8089af52da"><b>(a&b) or (a&c)</b></span> logic exists in the statements, you are advised to change the logic to <span class="parmname" id="mrs_01_0982__p20135311881549babc02a2f6bb15e8bc"><b>a & (b or c)</b></span>.</p>
|
|
</div>
|
|
<div class="section" id="mrs_01_0982__section54619912329"><h4 class="sectiontitle">Example</h4><p id="mrs_01_0982__p124611917324">If condition a is <span class="parmvalue" id="mrs_01_0982__p5eff0f20e43642dbaf429777f5716bf9"><b>p_partkey = l_partkey</b></span>, the statements before optimization are as follows:</p>
|
|
<pre class="screen" id="mrs_01_0982__screen20461139153215">select
|
|
sum(l_extendedprice* (1 - l_discount)) as revenue
|
|
from
|
|
lineitem,
|
|
part
|
|
where
|
|
(
|
|
<strong id="mrs_01_0982__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 >= 7 and l_quantity <= 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__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 >= 15 and l_quantity <= 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__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 >= 26 and l_quantity <= 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__p11462198321">The statements after optimization are as follows:</p>
|
|
<pre class="screen" id="mrs_01_0982__screen1946213983214">select
|
|
sum(l_extendedprice* (1 - l_discount)) as revenue
|
|
from
|
|
lineitem,
|
|
part
|
|
where <strong id="mrs_01_0982__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 >= 7 and l_quantity <= 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 >= 15 and l_quantity <= 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 >= 26 and l_quantity <= 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>
|
|
|