Re: Output affected rows in EXPLAIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Damir Belyalov <dam(dot)bel07(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, a(dot)lepikhov(at)postgrespro(dot)ru, Daniel Gustafsson <dgustafsson(at)postgresql(dot)org>
Subject: Re: Output affected rows in EXPLAIN
Date: 2023-09-06 14:00:20
Message-ID: 1509167.1694008820@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Damir Belyalov <dam(dot)bel07(at)gmail(dot)com> writes:
> I create a patch that outputs affected rows in EXPLAIN that occur by
> INSERT/UPDATE/DELETE.
> Despite the fact that commands in EXPLAIN ANALYZE query are executed as
> usual, EXPLAIN doesn't show outputting affected rows as in these commands.
> The patch fixes this problem.

This creates a bug, not fixes one. It's intentional that "insert into a"
is shown as returning zero rows, because that's what it did. If you'd
written "insert ... returning", you'd have gotten a different result:

=# explain analyze insert into a values (1);
QUERY PLAN
------------------------------------------------------------------------------------------
Insert on a (cost=0.00..0.01 rows=0 width=0) (actual time=0.015..0.016 rows=0 loops=1)
-> Result (cost=0.00..0.01 rows=1 width=4) (actual time=0.001..0.001 rows=1 loops=1)
Planning Time: 0.015 ms
Execution Time: 0.027 ms
(4 rows)

=# explain analyze insert into a values (1) returning *;
QUERY PLAN
------------------------------------------------------------------------------------------
Insert on a (cost=0.00..0.01 rows=1 width=4) (actual time=0.026..0.028 rows=1 loops=1)
-> Result (cost=0.00..0.01 rows=1 width=4) (actual time=0.003..0.003 rows=1 loops=1)
Planning Time: 0.031 ms
Execution Time: 0.051 ms
(4 rows)

Now admittedly, if you want to know the number of rows that went to disk,
you have to infer that from the number of rows emitted by the
ModifyTable's child plan. But that's a matter for documentation
(and I'm pretty sure it's documented someplace).

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2023-09-06 14:20:06 Re: generic plans and "initial" pruning
Previous Message Anthonin Bonnefoy 2023-09-06 13:43:36 Re: POC: Extension for adding distributed tracing - pg_tracing