pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tsunakawa.takay@fujitsu.com <tsunakawa.takay@fujitsu.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: [bug?] EXPLAIN outputs 0 for rows and width in cost estimate for update nodes
Date: Wed, 20 Jan 2021 08:12:34 +0000
Message-ID: <TYAPR01MB29905674F41693BBA9DA28CAFEA20@TYAPR01MB2990.jpnprd01.prod.outlook.com> (raw)

Hello,


While I'm investigating problems with parallel DML on another thread, I encountered a fishy behavior of EXPLAIN on HEAD.  Is this a bug?


As follows, the rows and width values of Update node is 0.  These were 1 and 10 respectively in versions 9.4.26 and 10.12 at hand.


postgres=# create table a (c int);
CREATE TABLE
postgres=# insert into a values(1);
INSERT 0 1
postgres=# analyze a;
ANALYZE
postgres=# begin;
BEGIN
postgres=*# explain analyze update a set c=2;
                                            QUERY PLAN                          
--------------------------------------------------------------------------------------------------
 Update on a  (cost=0.00..1.01 rows=0 width=0) (actual time=0.189..0.191 rows=0 loops=1)
   ->  Seq Scan on a  (cost=0.00..1.01 rows=1 width=10) (actual time=0.076..0.079 rows=1 loops=1)
 Planning Time: 0.688 ms
 Execution Time: 0.494 ms
(4 rows)


With RETURNING, the values are not 0 as follows.

postgres=*# rollback;
ROLLBACK
postgres=# begin;
BEGIN
postgres=# explain analyze update a set c=2 returning *;
                                            QUERY PLAN                          
--------------------------------------------------------------------------------------------------
 Update on a  (cost=0.00..1.01 rows=1 width=10) (actual time=0.271..0.278 rows=1 loops=1)
   ->  Seq Scan on a  (cost=0.00..1.01 rows=1 width=10) (actual time=0.080..0.082 rows=1 loops=1)
 Planning Time: 0.308 ms
 Execution Time: 0.392 ms
(4 rows)

The above holds true for Insert and Delete nodes as well.

In the manual, they are not 0.

https://www.postgresql.org/docs/devel/using-explain.html
--------------------------------------------------
EXPLAIN ANALYZE UPDATE tenk1 SET hundred = hundred + 1 WHERE unique1 < 100;

                                                           QUERY PLAN
-------------------------------------------------------------------​-------------------------------------------------------------
 Update on tenk1  (cost=5.07..229.46 rows=101 width=250) (actual time=14.628..14.628 rows=0 loops=1)
   ->  Bitmap Heap Scan on tenk1  (cost=5.07..229.46 rows=101 width=250) (actual time=0.101..0.439 rows=100 loops=1)
...
--------------------------------------------------


This behavior may possibly be considered as an intended behavior for the reason that Update/Insert/Delete nodes don't output rows without RETURNING.  Is this a bug or a correct behavior?


Regards
Takayuki Tsunakawa



view thread (5+ messages)  latest in thread

Message-ID: <TYAPR01MB29905674F41693BBA9DA28CAFEA20@TYAPR01MB2990.jpnprd01.prod.outlook.com>
Permalink:  ../TYAPR01MB29905674F41693BBA9DA28CAFEA20@TYAPR01MB2990.jpnprd01.prod.outlook.com/
Also on:    postgresql.org/message-id/TYAPR01MB29905674F41693BBA9DA28CAFEA20@TYAPR01MB2990.jpnprd01.prod.outlook.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tsunakawa.takay@fujitsu.com
  Subject: Re: [bug?] EXPLAIN outputs 0 for rows and width in cost estimate for update nodes
  In-Reply-To: <TYAPR01MB29905674F41693BBA9DA28CAFEA20@TYAPR01MB2990.jpnprd01.prod.outlook.com>
  References: <TYAPR01MB29905674F41693BBA9DA28CAFEA20@TYAPR01MB2990.jpnprd01.prod.outlook.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