Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iKJCz-0004Df-QB for pgsql-general@arkaria.postgresql.org; Tue, 15 Oct 2019 09:33:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iKJCy-0001Ux-CE for pgsql-general@arkaria.postgresql.org; Tue, 15 Oct 2019 09:33:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iKJCy-0001Uk-02 for pgsql-general@lists.postgresql.org; Tue, 15 Oct 2019 09:33:36 +0000 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::12]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iKJCw-0002qd-DX for pgsql-general@lists.postgresql.org; Tue, 15 Oct 2019 09:33:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1571132012; s=strato-dkim-0002; d=markusheiden.de; h=In-Reply-To:Date:Message-ID:From:References:Cc:To:Subject: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=oOVCCYIDshxAVrnKzmnBtIg5zDN4Vs+UYorZH+7l+Ng=; b=No7q9EDFHEfB7BoKHTHTewD9k8/dl3bz8/glNnD1FRpGdX62vI4gtiXyP9K64QEBYm Iaz0w/ldhKhdVudEDWf7w/T3hb1UWZttv6mj/aphJbpK/ptsaWnLwfEiOZagyt8O+PRR 9EXWJuZgfojuMehqQZ/gZkdIlNoFcVbK9b7NTY3rfLuPZjdnNn1mBFoJL6Ho1JHxP8ju 6/FAL3VQYPe2FVvB6yv0TnG0g+6/o5l1eTvwbnbBPNRhkl8WWdUpPuKmnmp02KKy874e Akcik6FXkRKA7e4Ve/OJCA+sZEokgSIDOn7TRYrqgUj3CGoOKhqDZrnvWT4KBmf8dGvI 93ag== X-RZG-AUTH: ":IW0WflW7W/LvUSzh74v5yySCICdyteMz/xaatG0hpjM/4WdtQR5FjsliDIwUVdARyyUpw1nS" X-RZG-CLASS-ID: mo00 Received: from Markus.local by smtp.strato.de (RZmta 44.28.0 AUTH) with ESMTPSA id L064bcv9F9XV5AG (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Tue, 15 Oct 2019 11:33:31 +0200 (CEST) Subject: Re: How to make runtime partition pruning work? To: David Rowley Cc: "pgsql-generallists.postgresql.org" References: <1a47e5be-7d21-e625-f8bc-7e9979f1b14b@markusheiden.de> From: Markus Heiden Message-ID: Date: Tue, 15 Oct 2019 11:33:30 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > 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.