Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 43D244C800 for ; Tue, 10 Jul 2012 01:08:17 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SoRkG-0006cV-22 for pgsql-bugs@postgresql.org; Tue, 10 Jul 2012 04:08:16 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q6A483cE001771; Tue, 10 Jul 2012 00:08:03 -0400 (EDT) From: Tom Lane To: heiko.helmbrecht@xclinical.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6723: Exception for correct query In-reply-to: References: Comments: In-reply-to heiko.helmbrecht@xclinical.com message dated "Mon, 09 Jul 2012 12:25:18 -0000" Date: Tue, 10 Jul 2012 00:08:03 -0400 Message-ID: <1768.1341893283@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/70 X-Sequence-Number: 33546 heiko.helmbrecht@xclinical.com writes: > The optimizer is using a where condition for a full table, not to the > results of a join/subselect result, that's why it is tried to use casts, > that cannot work on the whole table, here are the easy steps to reproduce > the problems: This is not a bug. The optimizer is allowed to push conditions down into subqueries; many people would be exceedingly unhappy if it failed to do that. There is a workaround you can use if you need it to not work like that, though: add an "OFFSET 0" to the subquery. LIMIT and OFFSET clauses on subqueries serve as optimization fences, because the planner can't push a WHERE condition down through one for fear of changing the set of rows selected. regards, tom lane