X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id E68C111F6B2F for ; Thu, 13 Apr 2006 07:25:52 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -2.599 X-Spam-Level: X-Spam-Status: No, score=-2.599 required=5 tests=[BAYES_00=-2.599] Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id 2-T143hLMwEv for ; Thu, 13 Apr 2006 07:25:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id D46EF11F6B1E for ; Thu, 13 Apr 2006 07:25:43 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 78A9930CC7; Thu, 13 Apr 2006 12:25:43 +0200 (MET DST) From: Cris Carampa X-Newsgroups: pgsql.performance Subject: index is not used if I include a function that returns current time in my query Date: Thu, 13 Apr 2006 12:25:02 +0200 Organization: Hub.Org Networking Services Lines: 74 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040114 X-Accept-Language: it, en-us To: pgsql-performance@postgresql.org X-Archive-Number: 200604/354 X-Sequence-Number: 18438 Hello, postgresql 7.4.8 on SuSE Linux here. I have a table called DMO with a column called ORA_RIF defined as=20 "timestamp without time zone" ; I created an index on this table based on this column only. If I run a query against a text literal the index is used: > explain select * from dmo where ora_rif>'2006-01-01'; QUERY PLAN -------------------------------------------------------------------------= ---------------- Index Scan using dmo_ndx02 on dmo (cost=3D0.00..1183.23 rows=3D736 wid= th=3D156) Index Cond: (ora_rif > '2006-01-01 00:00:00'::timestamp without time = zone) If I try to use a function that returns the current time instead, a=20 sequential scan is always performed: > explain select * from dmo where ora_rif>localtimestamp; QUERY PLAN -------------------------------------------------------------------------= ----- Seq Scan on dmo (cost=3D0.00..1008253.22 rows=3D2703928 width=3D156) Filter: (ora_rif > ('now'::text)::timestamp(6) without time zone) > explain select * from dmo where ora_rif>localtimestamp::timestamp=20 without time zone; QUERY PLAN -------------------------------------------------------------------------= ----- Seq Scan on dmo (cost=3D0.00..1008253.22 rows=3D2703928 width=3D156) Filter: (ora_rif > ('now'::text)::timestamp(6) without time zone) =2E.. etc. ... (tried with all datetime functions with and without cast) I even tried to write a function that explicitly returns a "timestamp=20 without time zone" value: create or replace function f () returns timestamp without time zone as ' declare x timestamp without time zone ; begin x :=3D ''2006-01-01 00:00:00''; return x ; end ; ' language plpgsql ; But the result is the same: > explain select * from dmo ora_rif>f(); QUERY PLAN -------------------------------------------------------------------------= ---- Seq Scan on dmo (cost=3D0.00..987973.76 rows=3D2703928 width=3D156) Filter: (ora_rif > f()) Any suggestion? Kind regards, --=20 Cris Carampa (spamto:cris119@operamail.com) potevo chiedere come si chiama il vostro cane il mio =E8 un po' di tempo che si chiama Libero