pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: mario.splivalo@mobart.hr
Cc: pgsql-sql@postgresql.org
Subject: Re: Slow query - SELECTing one row from 'big' table.
Date: Thu, 03 Nov 2005 10:17:35 -0500
Message-ID: <22145.1131031055@sss.pgh.pa.us> (raw)
In-Reply-To: <1131026341.18615.20.camel@ekim>
References: <1131026341.18615.20.camel@ekim>

Mario Splivalo <mario.splivalo@mobart.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



view thread (2+ messages)

Message-ID: <22145.1131031055@sss.pgh.pa.us>
Permalink:  ../22145.1131031055@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22145.1131031055@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mario.splivalo@mobart.hr
  Subject: Re: Slow query - SELECTing one row from 'big' table.
  In-Reply-To: <22145.1131031055@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox