X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3E7D5D6F74 for ; Tue, 23 Aug 2005 12:14:33 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45705-05 for ; Tue, 23 Aug 2005 15:14:30 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 5B1D7D6F63 for ; Tue, 23 Aug 2005 12:14:28 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j7NFEKD3002639; Tue, 23 Aug 2005 11:14:22 -0400 (EDT) To: =?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= Cc: "pgsql-performance@postgresql.org" Subject: Re: fake condition causes far better plan In-reply-to: <430B379A.7090204@gmail.com> References: <430B379A.7090204@gmail.com> Comments: In-reply-to =?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= message dated "Tue, 23 Aug 2005 16:50:02 +0200" Date: Tue, 23 Aug 2005 11:14:19 -0400 Message-ID: <2638.1124810059@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/342 X-Sequence-Number: 14089 =?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= writes: > [ bad query plan ] Most of the problem is here: > -> Index Scan using muvelet_vonalkod_ny_idopont on > muvelet_vonalkod_ny ny (cost=0.00..1351.88 rows=24649 width=4) (actual > time=0.161..10.735 rows=3943 loops=1) > Index Cond: (idopont >= (now() - > ('00:00:00'::interval + ('1 days'::text)::interval))) (BTW, you lied about the query, because this index condition doesn't match anything in the given query text.) Pre-8.0 releases aren't capable of making useful statistical estimates for conditions involving nonconstant subexpressions, so you get a badly-mistaken row count estimate that leads to a poor choice of plan. If you can't update to 8.0, the best answer is to do the date arithmetic on the client side. Another way is to create an allegedly-immutable function along the lines of "ago(interval) returns timestamptz" to hide the now() call --- this is dangerous but sometimes it's the easiest answer. See the archives. regards, tom lane