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

From Damir Belyalov
Subject Re: Output affected rows in EXPLAIN
Date
Msg-id CALH1Lgvpj7cMKLn4Xu+jJ_ra4TLocCpELCHqt1UYzYWQqmi_Rw@mail.gmail.com
Whole thread Raw
In response to Re: Output affected rows in EXPLAIN  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Output affected rows in EXPLAIN
List pgsql-hackers
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:
Maybe I didn't understand you correctly, but I didn't touch the number of affected rows in EXPLAIN output.
It's just a simple patch that adds 1 row after using commands: EXPLAIN INSERT, EXPLAIN UPDATE, EXPLAIN DELETE.
It was done because the commands INSERT/UPDATE/DELETE return one row after execution: "UPDATE 7" or "INSERT 0 4".
EXPLAIN (ANALYZE) INSERT/UPDATE/DELETE does the same thing as these commands, but doesn't output this row. So I added it.


Patch is fixed. There is no row "EXPLAIN" in queries like:
postgres=# explain (analyze) select * from t;
                                          QUERY PLAN
-----------------------------------------------------------------------------------------------
 Seq Scan on t  (cost=0.00..35.50 rows=2550 width=4) (actual time=0.064..0.075 rows=5 loops=1)
 Planning Time: 1.639 ms
 Execution Time: 0.215 ms
(3 rows)

EXPLAIN


What is about queries EXPLAIN INSERT/UPDATE/DELETE without ANALYZE?
Now it is outputting a row with 0 affected (inserted) rows at the end: "INSERT 0 0", "UPDATE 0". Example:
explain update a set n = 2;
                         QUERY PLAN                        
------------------------------------------------------------
 Update on a  (cost=0.00..35.50 rows=0 width=0)
   ->  Seq Scan on a  (cost=0.00..35.50 rows=2550 width=10)
(2 rows)

UPDATE 0

Regards,
Damir Belyalov
Postgres Professional
Attachment

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Subscription statistics are not dropped at DROP SUBSCRIPTION in some cases
Next
From: Aleksander Alekseev
Date:
Subject: Re: Fix bogus Asserts in calc_non_nestloop_required_outer