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: Index ignored on pkid = curval('some_seq'), used with pkid = (select curval(''some_seq') )
Date: Wed, 27 Feb 2019 10:54:11 +0200
Message-ID: <0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com> (raw)

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





view thread (3+ messages)  latest in thread

Message-ID: <0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com>
Permalink:  ../0ee1a3a2-7394-d518-2e22-790a84ef558c@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/0ee1a3a2-7394-d518-2e22-790a84ef558c@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: <0ee1a3a2-7394-d518-2e22-790a84ef558c@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