pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: Index ignored on pkid = curval('some_seq'), used with pkid = (select curval(''some_seq') )
Date: Thu, 28 Feb 2019 12:25:34 +0200
Message-ID: <650a8870-5047-8adf-451e-45d8b5237de0@matrix.gatewaynet.com> (raw)
In-Reply-To: <14554.1551280909@sss.pgh.pa.us>
References: <0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com>
	<14554.1551280909@sss.pgh.pa.us>

On 27/2/19 5:21 μ.μ., Tom Lane wrote:
> 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.)
Thanks Tom.
>
> 			regards, tom lane
>


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt





view thread (3+ messages)

Message-ID: <650a8870-5047-8adf-451e-45d8b5237de0@matrix.gatewaynet.com>
Permalink:  ../650a8870-5047-8adf-451e-45d8b5237de0@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/650a8870-5047-8adf-451e-45d8b5237de0@matrix.gatewaynet.com

 · 

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: 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: <650a8870-5047-8adf-451e-45d8b5237de0@matrix.gatewaynet.com>

* 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