pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Heiden <markus@markusheiden.de>
To: David Rowley <david.rowley@2ndquadrant.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: How to make runtime partition pruning work?
Date: Tue, 15 Oct 2019 11:33:30 +0200
Message-ID: <ed78c2c4-c3ee-77cd-ab27-06b620463747@markusheiden.de> (raw)
In-Reply-To: <CAKJS1f9nWfAYDMF8-ysG=TQZ5r9vB=pkk7-y7zQKdZExOraJ3w@mail.gmail.com>
References: <1a47e5be-7d21-e625-f8bc-7e9979f1b14b@markusheiden.de>
	<CAKJS1f9nWfAYDMF8-ysG=TQZ5r9vB=pkk7-y7zQKdZExOraJ3w@mail.gmail.com>


> Notice that only subqueries and parameterized nested loop joins are
> mentioned.  The above text does not really go into the detail of which
> types of subqueries can be used, but I can confirm that they must be
> subqueries that can only return a scalar value. e.g WHERE x = (SELECT
> y FROM ...).  The executor would raise an error if that subquery
> returned more than 1 row. The IN() clause you have is not eligible.
> This will be converted into a semi-join during planning, and even if
> it wasn't, the executor wouldn't be raising an error if it returned
> multiple rows.
>
> Unfortunately, to do what you mention with a hash join, we'd need to
> scan through the entire hash table and incrementally build the set of
> partitions which could match each value in the table.  I'm sure there
> are times where that would be well worth the trouble, but I imagine in
> the average case we might find that the cost of scanning the entire
> table this way would be more than just executing the query without any
> partition pruning. I don't see any good way to know in advance if it
> would be worthwhile or not.

First thanks for the detailed answer. Now at least I known that I can't 
make it work this way.

What I do not understand is, why for the IN() clause a hash join will be 
used in this case (instead of a semi join too)?

In this case (x is the partition key) using a semi join would be optimal 
for IN() clauses too IMHO.
This way only the query providing the y's has to executed first to 
provide the partition keys to filter.
In other cases where x is not the partition key, I agree with your 
argumentation.






view thread (3+ messages)

Message-ID: <ed78c2c4-c3ee-77cd-ab27-06b620463747@markusheiden.de>
Permalink:  ../ed78c2c4-c3ee-77cd-ab27-06b620463747@markusheiden.de/
Also on:    postgresql.org/message-id/ed78c2c4-c3ee-77cd-ab27-06b620463747@markusheiden.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: markus@markusheiden.de, david.rowley@2ndquadrant.com
  Subject: Re: How to make runtime partition pruning work?
  In-Reply-To: <ed78c2c4-c3ee-77cd-ab27-06b620463747@markusheiden.de>
  References: <1a47e5be-7d21-e625-f8bc-7e9979f1b14b@markusheiden.de> <CAKJS1f9nWfAYDMF8-ysG=TQZ5r9vB=pkk7-y7zQKdZExOraJ3w@mail.gmail.com> <ed78c2c4-c3ee-77cd-ab27-06b620463747@markusheiden.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox