Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id BB370EDF371 for ; Tue, 22 May 2012 22:46:20 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SX0eY-0007tr-BX for pgsql-bugs@postgresql.org; Wed, 23 May 2012 01:46:19 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q4N1k4LV018200; Tue, 22 May 2012 21:46:04 -0400 (EDT) To: maxim.boguk@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6662: Database do not push condition to subquery, test case for bug 6658 In-reply-to: References: Comments: In-reply-to maxim.boguk@gmail.com message dated "Wed, 23 May 2012 01:13:04 -0000" Date: Tue, 22 May 2012 21:46:04 -0400 Message-ID: <18199.1337737564@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/163 X-Sequence-Number: 33134 maxim.boguk@gmail.com writes: > I managed create simple self-contained test case for 6658. This works fine in HEAD. The reason it doesn't work fine in 9.1 (or 9.0) is that in those branches, anytextcat() and textanycat() are marked volatile, for reasons that were good at the time but were superseded by later policy changes. So you have a subselect containing a volatile output expression, which prevents flattening of the subselect, so the restriction clause doesn't get pushed down to where it could be used with the index. For some history see http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=c82d931dd180965a9a0c06acc764404f91de8170 http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=aab353a60b95aadc00f81da0c6d99bde696c4b75 http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=3db6524fe63f0598dcb2b307bb422bc126f2b15d If this is a big problem for you, you could safely adjust the provolatile marking of those functions by hand in 9.1. It might be better just to include an explicit cast to text, though, instead of relying on the assumption that the system will let you concat an integer directly to a text string. regards, tom lane