Re: Output affected rows in EXPLAIN - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Output affected rows in EXPLAIN
Date
Msg-id 1509167.1694008820@sss.pgh.pa.us
Whole thread Raw
In response to Output affected rows in EXPLAIN  (Damir Belyalov <dam.bel07@gmail.com>)
Responses Re: Output affected rows in EXPLAIN
List pgsql-hackers
Damir Belyalov <dam.bel07@gmail.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



pgsql-hackers by date:

Previous
From: Anthonin Bonnefoy
Date:
Subject: Re: POC: Extension for adding distributed tracing - pg_tracing
Next
From: Robert Haas
Date:
Subject: Re: generic plans and "initial" pruning