Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzIsv-0002EJ-6M for pgsql-admin@arkaria.postgresql.org; Thu, 28 Feb 2019 10:25:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzIst-0004Nf-Ti for pgsql-admin@arkaria.postgresql.org; Thu, 28 Feb 2019 10:25:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzIst-0004Ee-HE for pgsql-admin@lists.postgresql.org; Thu, 28 Feb 2019 10:25:47 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzIsp-0006gR-IE for pgsql-admin@lists.postgresql.org; Thu, 28 Feb 2019 10:25:46 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTPS id x1SAPYru028999 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Feb 2019 12:25:39 +0200 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id x1SAPYrd029525 for ; Thu, 28 Feb 2019 12:25:34 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: Index ignored on pkid = curval('some_seq'), used with pkid = (select curval(''some_seq') ) To: pgsql-admin@lists.postgresql.org References: <0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com> <14554.1551280909@sss.pgh.pa.us> From: Achilleas Mantzios Message-ID: <650a8870-5047-8adf-451e-45d8b5237de0@matrix.gatewaynet.com> Date: Thu, 28 Feb 2019 12:25:34 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 In-Reply-To: <14554.1551280909@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Virus-Scanned: clamav-milter 0.100.2 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-38.0 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_IT_PARTNERS,DYN_HAM_NAUTICAL,DYN_HAM_SIGNAT1 autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 27/2/19 5:21 μ.μ., Tom Lane wrote: > Achilleas Mantzios 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