Re: [HACKERS] path toward faster partition pruning
David Rowley <david.rowley@2ndquadrant.com>
On 7 March 2018 at 10:15, Robert Haas <robertmhaas@gmail.com> wrote: > On Fri, Mar 2, 2018 at 7:32 PM, David Rowley > <david.rowley@2ndquadrant.com> wrote: >> It appears to me, for your method to work we'd need to try every >> combination of the clauses matching each partition key, which in this >> case is 3 * 3 * 3 searches. Amit's current method is 1 search, after >> the clause reduction which is 3 + 3 + 3 (O(N) per partition key) > [...] >> With that considered, is it still a good idea to do it this way? > > I dunno. What do you think? > > That case is indeed pretty unfortunate, but it's also pretty > artificial. It's not obvious to me that we shouldn't care about it, > but it's also not obvious to me that we should. If we have some > bizarre cases that slip through the cracks or don't perform terribly > well, maybe nobody would ever notice or care. On the other hand, > maybe they would. One thing I've learned in my time working with PostgreSQL is that, if there's a known hole, someone's probably going to fall down it eventually. I like working with PostgreSQL because we're pretty careful to not make holes that people can fall down, or if there is some hole that cannot be filled in, we try to put a fence around it with a sign, (e.g rename pg_xlog to pg_wal). I'm not strongly opposed to your ideas, I probably don't have a complete understanding of the idea anyway. But from what I understand it looks like you want to take something that works quite well and make it work less well, and there appears not to be a good reason provided of why you want to do that. Is it because you want to simplify the patch due to concerns about it being too much logic to get right for PG11? > One thing that we could do is just only accept one clause for each > column-strategy pairing, presumably either the first one or the last > one. The problem with that is it can cause surprising behaviour. We reorder clauses and clauses get pushed down from upper parts of the query. Let's say there was some view like: CREATE VIEW vw_ledger_2018 AS SELECT * FROM ledger WHERE postdate BETWEEN '2018-01-01' AND '2018-12-13'; And a user comes along and does: SELECT * FROM vw_ledger_2018 WHERE postdate BETWEEN '2018-03-01' AND '2018-03-31' We're going to end up with base quals something like: postdate >= '2018-01-01' AND postdate <= '2018-12-31' AND postdate >= '2018-03-01' AND postdate <= '2018-03-31' If we just take the first from each op strategy then we'll not have managed to narrow the case down to just the March partition. You might argue that this should be resolved at some higher level in the planner, but that does nothing for the run-time pruning case. I don't really want to do or say anything that jeopardises this patch from getting into PG11, so if the path of least resistance is to go with the option you've proposed then I'd much rather that than this getting pushed out to PG12. I really just want to try to make sure we've thought of everything before we create too many surprises for users. Perhaps a compromise would be to check all quals from the first partition key and only the first or last one from the remaining keys. I imagine most cases will have just 1 key anyway. This would significantly reduce the number of possible combinations of quals to try, but unfortunately, it still does have that element of surprise. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
Commits
-
Fix assorted partition pruning bugs
- d758d9702e2f 11.0 landed
-
Make gen_partprune_steps static
- d1e2cac5ff7e 11.0 landed
-
Remove useless 'default' clause
- c775fb9e18ac 11.0 landed
-
Reorganize partitioning code
- da6f3e45ddb6 11.0 landed
-
Use custom hash opclass for hash partition pruning
- fafec4cce814 11.0 landed
-
Blindly attempt to fix sepgsql tests broken due to 9fdb675fc5.
- 4f813c7203e0 11.0 landed
-
Attempt to fix endianess issues in new hash partition test.
- 40e42e1024c5 11.0 landed
-
Faster partition pruning
- 9fdb675fc5d2 11.0 landed
-
For partitionwise join, match on partcollation, not parttypcoll.
- 2af28e603319 11.0 landed
-
Revise API for partition bound search functions.
- f724022d0ae0 11.0 landed
-
Revise API for partition_rbound_cmp/partition_rbound_datum_cmp.
- b0229235564f 11.0 landed
-
Fix possible crash in partition-wise join.
- f069c91a5793 11.0 cited
-
Refactor code for partition bound searching
- 9aef173163ae 11.0 landed
-
New C function: bms_add_range
- 84940644de93 11.0 landed
-
Add extensive tests for partition pruning.
- 8d4e70a63bf8 11.0 landed
-
Add null test to partition constraint for default range partitions.
- 7b88d63a9122 11.0 cited
-
Remove BufFile's isTemp flag.
- 11e264517dff 11.0 cited
-
Make OWNER TO subcommand mention consistent
- bf54c0f05c0a 11.0 cited
-
Fix index matching for operators with mixed collatable/noncollatable inputs.
- cb37c291060d 9.2.0 cited