X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3DFD65E46CC for ; Mon, 30 Aug 2004 13:47:31 -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 63104-05 for ; Mon, 30 Aug 2004 16:47:34 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 89AB05E46EC for ; Mon, 30 Aug 2004 13:47:26 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i7UGlNIG008090; Mon, 30 Aug 2004 12:47:23 -0400 (EDT) To: "Steinar H. Gunderson" Cc: pgsql-performance@postgresql.org Subject: Re: Why does a simple query not use an obvious index? In-reply-to: <20040830160228.GB16847@uio.no> References: <1093804128.5493.22.camel@localhost.localdomain> <87fz65k5sq.fsf@stark.xeocode.com> <16093.1093817023@sss.pgh.pa.us> <20040830160228.GB16847@uio.no> Comments: In-reply-to "Steinar H. Gunderson" message dated "Mon, 30 Aug 2004 18:02:28 +0200" Date: Mon, 30 Aug 2004 12:47:23 -0400 Message-ID: <8089.1093884443@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/444 X-Sequence-Number: 8080 "Steinar H. Gunderson" writes: > On Sun, Aug 29, 2004 at 06:03:43PM -0400, Tom Lane wrote: >> The expression "now() - something" is not a constant, so the planner >> is faced with "timestampfield > unknownvalue". > Out of curiosity, does the subselect query I presented earlier in the thread > count as "a constant"? It gives the correct query plan, but this could of > course just be correct by accident... That was on 7.2, wasn't it? I don't remember any longer exactly how 7.2 does this stuff, but it's different from 7.3 and later (and certainly not any more "right"). You did at one time need to hide now() in a subselect to get the planner to consider an indexscan at all --- that was before we made the distinction between immutable and stable functions, and so now() had to be treated as unsafe to index against (just as random() still is). I think 7.2 behaved that way but I'm not totally sure. regards, tom lane