pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Achilleas Mantzios <achill@matrix.gatewaynet.com>
Cc: pgsql-admin@lists.postgresql.org
Subject: Re: Index ignored on pkid = curval('some_seq'), used with pkid = (select curval(''some_seq') )
Date: Wed, 27 Feb 2019 10:21:49 -0500
Message-ID: <14554.1551280909@sss.pgh.pa.us> (raw)
In-Reply-To: <0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com>
References: <0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com>

Achilleas Mantzios <achill@matrix.gatewaynet.com> writes:
> dynacom=# explain analyze update itemshist set reason='{foo,bar}' where pkid = currval(('public.itemshist_pkid_seq'::text)::regclass);

currval() is marked volatile, so that's not a legal index
qualification.

(Perhaps there's an argument that it'd be more useful to consider it
stable, but certainly if you used it in the same query as a nextval()
on the same sequence, you'd have trouble.)

> -- but if I compare against select currval it uses the index:

> dynacom=# explain analyze update itemshist set reason='{foo,bar}' where pkid = ( SELECT currval(('public.itemshist_pkid_seq'::text)::regclass));

Yeah, the planner does not consider uncorrelated scalar sub-selects
to be volatile; they'll be evaluated only once per query, regardless
of what they contain.  So this is sort of a traditional hack for
freezing a volatile function's result.  (I have no idea whether other
RDBMSes read the SQL spec the same way on this point.)

			regards, tom lane




view thread (3+ messages)  latest in thread

Message-ID: <14554.1551280909@sss.pgh.pa.us>
Permalink:  ../14554.1551280909@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14554.1551280909@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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, achill@matrix.gatewaynet.com, pgsql-admin@lists.postgresql.org
  Subject: Re: Index ignored on pkid = curval('some_seq'), used with pkid = (select curval(''some_seq') )
  In-Reply-To: <14554.1551280909@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