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 1gyuyx-0003Ji-8P for pgsql-admin@arkaria.postgresql.org; Wed, 27 Feb 2019 08:54:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyuyt-0005f6-Cw for pgsql-admin@arkaria.postgresql.org; Wed, 27 Feb 2019 08:54:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyuyt-0005ez-4d for pgsql-admin@lists.postgresql.org; Wed, 27 Feb 2019 08:54:23 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyuyq-00035w-LQ for pgsql-admin@lists.postgresql.org; Wed, 27 Feb 2019 08:54:22 +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 x1R8sBu5012228 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 27 Feb 2019 10:54:17 +0200 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id x1R8sBS9061009 for ; Wed, 27 Feb 2019 10:54:11 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) To: pgsql-admin@lists.postgresql.org From: Achilleas Mantzios Subject: Index ignored on pkid = curval('some_seq'), used with pkid = (select curval(''some_seq') ) Message-ID: <0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com> Date: Wed, 27 Feb 2019 10:54:11 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 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=-29.0 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_NAUTICAL 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 Postgresql 10 and 11 begin; insert into itemshist(id,repdate,systemdate,done,username) VALUES(1454349,current_date,current_timestamp,'t','foo'); dynacom=# explain analyze update itemshist set reason='{foo,bar}' where pkid = currval(('public.itemshist_pkid_seq'::text)::regclass);                                                        QUERY PLAN ------------------------------------------------------------------------------------------------------------------------  Update on itemshist  (cost=0.00..412082.16 rows=1 width=167) (actual time=15833.238..15833.238 rows=0 loops=1)    ->  Seq Scan on itemshist  (cost=0.00..412082.16 rows=1 width=167) (actual time=14444.143..15833.210 rows=1 loops=1)          Filter: (pkid = currval(('public.itemshist_pkid_seq'::text)::regclass))          Rows Removed by Filter: 14470046  Planning Time: 0.095 ms  Trigger for constraint $1: time=0.240 calls=1  Trigger itemshist_dbmirror_trig: time=3.101 calls=1  Execution Time: 15836.636 ms (8 rows) -- 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));                                                             QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------  Update on itemshist  (cost=0.45..8.47 rows=1 width=167) (actual time=0.048..0.048 rows=0 loops=1)    InitPlan 1 (returns $0)      ->  Result  (cost=0.00..0.01 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=1)    ->  Index Scan using itemshist_pkey on itemshist (cost=0.43..8.45 rows=1 width=167) (actual time=0.028..0.033 rows=1 loops=1)          Index Cond: (pkid = $0)  Planning Time: 0.095 ms  Trigger for constraint $1: time=0.145 calls=1  Trigger itemshist_dbmirror_trig: time=3.026 calls=1  Execution Time: 3.273 ms (9 rows) -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt