Re: no partition pruning when partitioning using array type

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: no partition pruning when partitioning using array type
Date: 2018-05-08 06:18:25
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2018/03/01 17:16, Amit Langote wrote:
> Added this to CF (actually moved to the September one after first having
> added it to the CF that is just getting started).
> It seems to me that we don't need to go with my originally proposed
> approach to teach predtest.c to strip RelabelType nodes. Apparently, it's
> only partition.c that's adding the RelableType node around partition key
> nodes in such cases. That is, in the case of having an array, record,
> enum, and range type as the partition key. No other part of the system
> ends up adding one as far as I can see. Parser's make_op(), for example,
> that is used to generate an OpExpr for a qual involving the partition key,
> won't put RelabelType around the partition key node if the operator in
> question has "pseudo"-types listed as declared types of its left and right
> arguments.
> So I revised the patch to drop all the predtest.c changes and instead
> modify get_partition_operator() to avoid generating RelabelType in such
> cases. Please find it attached.

I would like to revisit this as a bug fix for get_partition_operator() to
be applied to both PG 10 and HEAD. In the former case, it fixes the bug
that constraint exclusion code will fail to prune correctly when partition
key is of array, enum, range, or record type due to the structural
mismatch between the OpExpr that partitioning code generates and one that
the parser generates for WHERE clauses involving partition key columns.

In HEAD, since we already fixed that case in e5dcbb88a15d [1] which is a
different piece of code anyway, the patch only serves to improve the
deparse output emitted by ruleutils.c for partition constraint expressions
where pseudo-type partition key is involved. The change can be seen in
the updated test output for create_table test.

Attached are patches for PG 10 and HEAD, which implement a slightly
different approach to fixing this. Now, instead of passing the partition
key's type as lefttype and righttype to look up the operator, the operator
class declared type is passed. Also, we now decide whether to create a
RelabelType node on top based on whether the partition key's type is
different from the selected operator's input type, with exception for
pseudo-type types.



Attachment Content-Type Size
PG10-v1-0001-Fix-how-get_partition_operator-looks-up-the-opera.patch text/plain 4.7 KB
HEAD-v4-0001-Fix-how-get_partition_operator-looks-up-the-opera.patch text/plain 4.7 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Lakhin 2018-05-08 06:42:23 Re: Porting PG Extension from UNIX to Windows
Previous Message Fabien COELHO 2018-05-08 06:00:57 Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors