From: | Damir Belyalov <dam(dot)bel07(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
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-07 14:57:12 |
Message-ID: | CALH1Lgvpj7cMKLn4Xu+jJ_ra4TLocCpELCHqt1UYzYWQqmi_Rw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | Content-Type | Size |
---|---|---|
0002-Output-affected-rows-in-EXPLAIN.patch | text/x-patch | 9.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Aleksander Alekseev | 2023-09-07 15:09:40 | Re: Fix bogus Asserts in calc_non_nestloop_required_outer |
Previous Message | Masahiko Sawada | 2023-09-07 13:22:14 | Re: Subscription statistics are not dropped at DROP SUBSCRIPTION in some cases |