sql - Partition elimination in Greenplum -
i have scenario this:
select * package package_type in ('box','card')
the table partitioned package_type
field. assume there twenty possible values package_type
field. there twenty partitions including box
, card
, default
partitions. when above query run, partition elimination happens correctly , box
, card
partitions scanned. result quick.
however, when same query written this:
select * package package_type in (select package_type package_list_table)
, column package_type
in package_list_table
contains 2 values box
, card
.
when above query run, 20 partitions being scanned. degrades performance.
it seems compiler failing identify second query correctly , result partitions getting accessed.
any workarounds overcome this?
thanks in advance.
the postgres manual page on partitioning includes caveat
constraint exclusion works when query's clause contains constants (or externally supplied parameters). example, comparison against non-immutable function such current_timestamp cannot optimized, since planner cannot know partition function value might fall @ run time.
in order eliminate seek on partition, postgres must know when creating query plan no rows partition relevant. in query, occurs after sub-query has completed, query have split two, second part planned after first completes.
if partitions include index on partitioned column (package_type
) constraint, planner may elect use index scan on each partition, leading incorrect partitions being reasonably efficiently eliminated @ runtime anyway. (that is, there 20 index scans, each require little resource.)
an alternative split query yourself, , build sql dynamically. since select package_type package_list_table
can ever return 20 distinct values, select array/set in application or user-defined function. can pass these in literals in in ( ... )
clause in first example (or equivalently = any(array_expression)
), , achieve partition elimination.
Comments
Post a Comment