X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9A576D6817 for ; Thu, 3 Nov 2005 11:17:35 -0400 (AST) 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 30351-08 for ; Thu, 3 Nov 2005 15:17:31 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id E9A57D85D2 for ; Thu, 3 Nov 2005 11:17:32 -0400 (AST) 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 jA3FHaeK022146; Thu, 3 Nov 2005 10:17:36 -0500 (EST) To: mario.splivalo@mobart.hr Cc: pgsql-sql@postgresql.org Subject: Re: Slow query - SELECTing one row from 'big' table. In-reply-to: <1131026341.18615.20.camel@ekim> References: <1131026341.18615.20.camel@ekim> Comments: In-reply-to Mario Splivalo message dated "Thu, 03 Nov 2005 14:59:01 +0100" Date: Thu, 03 Nov 2005 10:17:35 -0500 Message-ID: <22145.1131031055@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006] X-Spam-Score: 0.006 X-Spam-Level: X-Archive-Number: 200511/42 X-Sequence-Number: 23294 Mario Splivalo writes: > SELECT * > FROM messages > WHERE (id = currval(''public.message_id_seq''::text)) That cannot legally be converted into an indexscan, because currval() is a volatile function --- the planner cannot be certain that its value won't change during the query. (In this case we can assume it's safe because nothing in that query would call nextval(), but the planner isn't omniscient enough to make that conclusion.) Fetch the currval into a local variable and use the variable in the query. regards, tom lane