Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1avwxp-0003hW-SG for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Apr 2016 01:11:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1avwxo-00032q-UL for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Apr 2016 01:11:24 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1avwxB-0002L7-TV for pgsql-bugs@postgresql.org; Fri, 29 Apr 2016 01:10:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1avwx8-0007yn-CA for pgsql-bugs@postgresql.org; Fri, 29 Apr 2016 01:10:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u3T1AcWX018636; Thu, 28 Apr 2016 21:10:38 -0400 From: Tom Lane To: Mathias Kunter cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14107: Major query planner bug regarding subqueries and indices In-reply-to: <629ecf23-b7b2-2d73-6792-150b111e83ab@gmail.com> References: <20160421115638.22895.78902@wrigleys.postgresql.org> <69e376c7-6c2c-c96d-2ad6-3734affb59b7@gmail.com> <44df2e58-87f5-282c-9871-c735240c55e4@gmail.com> <1461406942121-5900147.post@n5.nabble.com> <3ac6f379-08f8-d1db-639f-2dc3075d2eb4@gmail.com> <1461610493986-5900430.post@n5.nabble.com> <629ecf23-b7b2-2d73-6792-150b111e83ab@gmail.com> Comments: In-reply-to Mathias Kunter message dated "Thu, 28 Apr 2016 21:07:00 +0200" Date: Thu, 28 Apr 2016 21:10:38 -0400 Message-ID: <18635.1461892238@sss.pgh.pa.us> X-Pg-Spam-Score: -2.9 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Mathias Kunter writes: > Does anybody care? Shouldn't something like this be fixed ASAP?? As was already stated upthread, this is not a bug; it's an opportunity for future improvement. It's unlikely to get "fixed ASAP" because there would be quite a bit of work involved, possibly including new executor infrastructure not just planner work. As far as the first case goes, the executor doesn't currently have any direct way to treat "a.x IN (SELECT ...)" as an indexqual for a.x. In simple cases the planner can work around that by transforming the query into a join against a unique-ified version of the sub-select, but that doesn't work if the IN is underneath an OR. If you know that the sub-select isn't going to return very many rows, you could do SELECT ... FROM a WHERE a.x = ? OR a.y = ANY(ARRAY(SELECT ...)); but this would blow up rather badly with a large sub-select result, so I'm not sure I want to try to make the planner transform it that way automatically. I don't actually see any way to do very much with your second example at all: > SELECT ... FROM a JOIN b ON (...) WHERE a.x = ? OR b.y = ?; There's no way to push anything down to either the A or B scans from that WHERE condition: you can't remove any rows before the join because they might join to rows on the other side that satisfy the other half of the OR. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs