Re: Slow query - SELECTing one row from 'big' table.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: mario(dot)splivalo(at)mobart(dot)hr
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Slow query - SELECTing one row from 'big' table.
Date: 2005-11-03 15:17:35
Message-ID: 22145.1131031055@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mario Splivalo <mario(dot)splivalo(at)mobart(dot)hr> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Don Drake 2005-11-03 16:14:28 Encoding on 8.0.4
Previous Message Achilleus Mantzios 2005-11-03 14:42:10 Re: Welcome to the pgsql-sql list!