Re: no partition pruning when partitioning using array type
Amit Langote <langote_amit_f8@lab.ntt.co.jp>
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2018-05-08T06:18:25Z
Lists: pgsql-hackers
Attachments
- PG10-v1-0001-Fix-how-get_partition_operator-looks-up-the-opera.patch (text/plain) patch v1-0001
- HEAD-v4-0001-Fix-how-get_partition_operator-looks-up-the-opera.patch (text/plain) patch v4-0001
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. Thanks, Amit [1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=e5dcbb88a15d
Commits
-
Better handle pseudotypes as partition keys
- b6e3a3a492db 12.0 landed
- e7df94f317c9 11.0 landed
- 7c644b7d3f83 10.5 landed