<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Question about Partition Pruning in Impala in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Question-about-Partition-Pruning-in-Impala/m-p/53903#M15534</link>
    <description>&lt;P&gt;CDH 5.2.0 and 5.10.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems partition pruning is not working when using "or" and conditions with both partitioned and un-partitioned columns.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Creates partitioned table with 3 partitions, 1 file for each partition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;create table part_table (
strcol1 string,
intcol1 int
)
PARTITIONED BY (
  keycol STRING
);

insert into part_table partition (keycol='k1') values ('str1', 1);
insert into part_table partition (keycol='k2') values ('str2', 2);
insert into part_table partition (keycol='k3') values ('str3', 3);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Partition pruning worked normally when no un-partitioned columns used&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;explain select count(*) 
from part_table
where (
(keycol='k1')
or (keycol='k2' )
)

+-----------------------------------------------------+
| Explain String                                      |
+-----------------------------------------------------+
| Estimated Per-Host Requirements: Memory=0B VCores=0 |
|                                                     |
| PLAN-ROOT SINK                                      |
| |                                                   |
| 01:AGGREGATE [FINALIZE]                             |
| |  output: count(*)                                 |
| |                                                   |
| 00:SCAN HDFS [cdragg.part_table]                    |
|    partitions=2/3 files=2 size=14B                  |
+-----------------------------------------------------+&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When un-partitioned columns used in conditions, no partition pruning performed.&lt;/P&gt;&lt;PRE&gt;explain select count(*)
from part_table
where (
(keycol='k0' and intcol1=0)
or (keycol='k2' and intcol1=2)
)
+-------------------------------------------------------------------------------------+
| Explain String                                                                      |
+-------------------------------------------------------------------------------------+
| Estimated Per-Host Requirements: Memory=0B VCores=0                                 |
|                                                                                     |
| PLAN-ROOT SINK                                                                      |
| |                                                                                   |
| 01:AGGREGATE [FINALIZE]                                                             |
| |  output: count(*)                                                                 |
| |                                                                                   |
| 00:SCAN HDFS [cdragg.part_table]                                                    |
|    partitions=3/3 files=3 size=21B                                                  |
|    predicates: ((keycol = 'k0' AND intcol1 = 0) OR (keycol = 'k2' AND intcol1 = 2)) |
+-------------------------------------------------------------------------------------+&lt;/PRE&gt;&lt;P&gt;I can workaround the situation by another condition on partitioned columns. Is this the proper way to do?&lt;/P&gt;&lt;PRE&gt;explain select count(*)
from part_table
where (
(keycol='k0' and intcol1=0)
or (keycol='k2' and intcol1=2)
)
and keycol in ('k0', 'k2')

+-------------------------------------------------------------------------------------+
| Explain String                                                                      |
+-------------------------------------------------------------------------------------+
| Estimated Per-Host Requirements: Memory=0B VCores=0                                 |
|                                                                                     |
| PLAN-ROOT SINK                                                                      |
| |                                                                                   |
| 01:AGGREGATE [FINALIZE]                                                             |
| |  output: count(*)                                                                 |
| |                                                                                   |
| 00:SCAN HDFS [cdragg.part_table]                                                    |
|    partitions=1/3 files=1 size=7B                                                   |
|    predicates: ((keycol = 'k0' AND intcol1 = 0) OR (keycol = 'k2' AND intcol1 = 2)) |
+-------------------------------------------------------------------------------------+&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 11:29:19 GMT</pubDate>
    <dc:creator>athtsang</dc:creator>
    <dc:date>2022-09-16T11:29:19Z</dc:date>
    <item>
      <title>Question about Partition Pruning in Impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Question-about-Partition-Pruning-in-Impala/m-p/53903#M15534</link>
      <description>&lt;P&gt;CDH 5.2.0 and 5.10.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems partition pruning is not working when using "or" and conditions with both partitioned and un-partitioned columns.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Creates partitioned table with 3 partitions, 1 file for each partition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;create table part_table (
strcol1 string,
intcol1 int
)
PARTITIONED BY (
  keycol STRING
);

insert into part_table partition (keycol='k1') values ('str1', 1);
insert into part_table partition (keycol='k2') values ('str2', 2);
insert into part_table partition (keycol='k3') values ('str3', 3);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Partition pruning worked normally when no un-partitioned columns used&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;explain select count(*) 
from part_table
where (
(keycol='k1')
or (keycol='k2' )
)

+-----------------------------------------------------+
| Explain String                                      |
+-----------------------------------------------------+
| Estimated Per-Host Requirements: Memory=0B VCores=0 |
|                                                     |
| PLAN-ROOT SINK                                      |
| |                                                   |
| 01:AGGREGATE [FINALIZE]                             |
| |  output: count(*)                                 |
| |                                                   |
| 00:SCAN HDFS [cdragg.part_table]                    |
|    partitions=2/3 files=2 size=14B                  |
+-----------------------------------------------------+&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When un-partitioned columns used in conditions, no partition pruning performed.&lt;/P&gt;&lt;PRE&gt;explain select count(*)
from part_table
where (
(keycol='k0' and intcol1=0)
or (keycol='k2' and intcol1=2)
)
+-------------------------------------------------------------------------------------+
| Explain String                                                                      |
+-------------------------------------------------------------------------------------+
| Estimated Per-Host Requirements: Memory=0B VCores=0                                 |
|                                                                                     |
| PLAN-ROOT SINK                                                                      |
| |                                                                                   |
| 01:AGGREGATE [FINALIZE]                                                             |
| |  output: count(*)                                                                 |
| |                                                                                   |
| 00:SCAN HDFS [cdragg.part_table]                                                    |
|    partitions=3/3 files=3 size=21B                                                  |
|    predicates: ((keycol = 'k0' AND intcol1 = 0) OR (keycol = 'k2' AND intcol1 = 2)) |
+-------------------------------------------------------------------------------------+&lt;/PRE&gt;&lt;P&gt;I can workaround the situation by another condition on partitioned columns. Is this the proper way to do?&lt;/P&gt;&lt;PRE&gt;explain select count(*)
from part_table
where (
(keycol='k0' and intcol1=0)
or (keycol='k2' and intcol1=2)
)
and keycol in ('k0', 'k2')

+-------------------------------------------------------------------------------------+
| Explain String                                                                      |
+-------------------------------------------------------------------------------------+
| Estimated Per-Host Requirements: Memory=0B VCores=0                                 |
|                                                                                     |
| PLAN-ROOT SINK                                                                      |
| |                                                                                   |
| 01:AGGREGATE [FINALIZE]                                                             |
| |  output: count(*)                                                                 |
| |                                                                                   |
| 00:SCAN HDFS [cdragg.part_table]                                                    |
|    partitions=1/3 files=1 size=7B                                                   |
|    predicates: ((keycol = 'k0' AND intcol1 = 0) OR (keycol = 'k2' AND intcol1 = 2)) |
+-------------------------------------------------------------------------------------+&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:29:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Question-about-Partition-Pruning-in-Impala/m-p/53903#M15534</guid>
      <dc:creator>athtsang</dc:creator>
      <dc:date>2022-09-16T11:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Question about Partition Pruning in Impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Question-about-Partition-Pruning-in-Impala/m-p/53904#M15535</link>
      <description>&lt;P&gt;You are correct, this is a limitation:&lt;/P&gt;&lt;P&gt;&lt;A href="https://issues.cloudera.org/browse/IMPALA-2108" target="_blank"&gt;https://issues.cloudera.org/browse/IMPALA-2108&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Impala would basically need to do infer the IN predicate that you are using in your workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are welcome to take a stab at contributing a patch!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 04:44:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Question-about-Partition-Pruning-in-Impala/m-p/53904#M15535</guid>
      <dc:creator>alex.behm</dc:creator>
      <dc:date>2017-04-20T04:44:17Z</dc:date>
    </item>
  </channel>
</rss>

