Skip to content

Commit 598ac10

Browse files
committed
Make EXPLAIN MERGE output format more compact
We can use a single line to print all tuple counts that MERGE processed, for conciseness, and elide those that are zeroes. Non-text formats report all numbers, as is typical. Per comment from Justin Pryzby <pryzby@telsasoft.com> Discussion: https://postgr.es/m/20220511163350.GL19626@telsasoft.com
1 parent 81e3c83 commit 598ac10

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

src/backend/commands/explain.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4068,10 +4068,27 @@ show_modifytable_info(ModifyTableState *mtstate, List *ancestors,
40684068
skipped_path = total - insert_path - update_path - delete_path;
40694069
Assert(skipped_path >= 0);
40704070

4071-
ExplainPropertyFloat("Tuples Inserted", NULL, insert_path, 0, es);
4072-
ExplainPropertyFloat("Tuples Updated", NULL, update_path, 0, es);
4073-
ExplainPropertyFloat("Tuples Deleted", NULL, delete_path, 0, es);
4074-
ExplainPropertyFloat("Tuples Skipped", NULL, skipped_path, 0, es);
4071+
if (es->format == EXPLAIN_FORMAT_TEXT && total > 0)
4072+
{
4073+
ExplainIndentText(es);
4074+
appendStringInfoString(es->str, "Tuples:");
4075+
if (insert_path > 0)
4076+
appendStringInfo(es->str, " inserted=%.0f", insert_path);
4077+
if (update_path > 0)
4078+
appendStringInfo(es->str, " updated=%.0f", update_path);
4079+
if (delete_path > 0)
4080+
appendStringInfo(es->str, " deleted=%.0f", delete_path);
4081+
if (skipped_path > 0)
4082+
appendStringInfo(es->str, " skipped=%.0f", skipped_path);
4083+
appendStringInfoChar(es->str, '\n');
4084+
}
4085+
else
4086+
{
4087+
ExplainPropertyFloat("Tuples Inserted", NULL, insert_path, 0, es);
4088+
ExplainPropertyFloat("Tuples Updated", NULL, update_path, 0, es);
4089+
ExplainPropertyFloat("Tuples Deleted", NULL, delete_path, 0, es);
4090+
ExplainPropertyFloat("Tuples Skipped", NULL, skipped_path, 0, es);
4091+
}
40754092
}
40764093
}
40774094

src/test/regress/expected/merge.out

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,10 +1329,7 @@ WHEN MATCHED THEN
13291329
explain_merge
13301330
----------------------------------------------------------------------
13311331
Merge on ex_mtarget t (actual rows=0 loops=1)
1332-
Tuples Inserted: 0
1333-
Tuples Updated: 50
1334-
Tuples Deleted: 0
1335-
Tuples Skipped: 0
1332+
Tuples: updated=50
13361333
-> Merge Join (actual rows=50 loops=1)
13371334
Merge Cond: (t.a = s.a)
13381335
-> Sort (actual rows=50 loops=1)
@@ -1343,7 +1340,7 @@ WHEN MATCHED THEN
13431340
Sort Key: s.a
13441341
Sort Method: quicksort Memory: xxx
13451342
-> Seq Scan on ex_msource s (actual rows=100 loops=1)
1346-
(15 rows)
1343+
(12 rows)
13471344

13481345
-- only updates to selected tuples
13491346
SELECT explain_merge('
@@ -1353,10 +1350,7 @@ WHEN MATCHED AND t.a < 10 THEN
13531350
explain_merge
13541351
----------------------------------------------------------------------
13551352
Merge on ex_mtarget t (actual rows=0 loops=1)
1356-
Tuples Inserted: 0
1357-
Tuples Updated: 5
1358-
Tuples Deleted: 0
1359-
Tuples Skipped: 45
1353+
Tuples: updated=5 skipped=45
13601354
-> Merge Join (actual rows=50 loops=1)
13611355
Merge Cond: (t.a = s.a)
13621356
-> Sort (actual rows=50 loops=1)
@@ -1367,7 +1361,7 @@ WHEN MATCHED AND t.a < 10 THEN
13671361
Sort Key: s.a
13681362
Sort Method: quicksort Memory: xxx
13691363
-> Seq Scan on ex_msource s (actual rows=100 loops=1)
1370-
(15 rows)
1364+
(12 rows)
13711365

13721366
-- updates + deletes
13731367
SELECT explain_merge('
@@ -1379,10 +1373,7 @@ WHEN MATCHED AND t.a >= 10 AND t.a <= 20 THEN
13791373
explain_merge
13801374
----------------------------------------------------------------------
13811375
Merge on ex_mtarget t (actual rows=0 loops=1)
1382-
Tuples Inserted: 0
1383-
Tuples Updated: 5
1384-
Tuples Deleted: 5
1385-
Tuples Skipped: 40
1376+
Tuples: updated=5 deleted=5 skipped=40
13861377
-> Merge Join (actual rows=50 loops=1)
13871378
Merge Cond: (t.a = s.a)
13881379
-> Sort (actual rows=50 loops=1)
@@ -1393,7 +1384,7 @@ WHEN MATCHED AND t.a >= 10 AND t.a <= 20 THEN
13931384
Sort Key: s.a
13941385
Sort Method: quicksort Memory: xxx
13951386
-> Seq Scan on ex_msource s (actual rows=100 loops=1)
1396-
(15 rows)
1387+
(12 rows)
13971388

13981389
-- only inserts
13991390
SELECT explain_merge('
@@ -1403,10 +1394,7 @@ WHEN NOT MATCHED AND s.a < 10 THEN
14031394
explain_merge
14041395
----------------------------------------------------------------------
14051396
Merge on ex_mtarget t (actual rows=0 loops=1)
1406-
Tuples Inserted: 4
1407-
Tuples Updated: 0
1408-
Tuples Deleted: 0
1409-
Tuples Skipped: 96
1397+
Tuples: inserted=4 skipped=96
14101398
-> Merge Left Join (actual rows=100 loops=1)
14111399
Merge Cond: (s.a = t.a)
14121400
-> Sort (actual rows=100 loops=1)
@@ -1417,7 +1405,7 @@ WHEN NOT MATCHED AND s.a < 10 THEN
14171405
Sort Key: t.a
14181406
Sort Method: quicksort Memory: xxx
14191407
-> Seq Scan on ex_mtarget t (actual rows=45 loops=1)
1420-
(15 rows)
1408+
(12 rows)
14211409

14221410
-- all three
14231411
SELECT explain_merge('
@@ -1431,10 +1419,7 @@ WHEN NOT MATCHED AND s.a < 20 THEN
14311419
explain_merge
14321420
----------------------------------------------------------------------
14331421
Merge on ex_mtarget t (actual rows=0 loops=1)
1434-
Tuples Inserted: 10
1435-
Tuples Updated: 9
1436-
Tuples Deleted: 5
1437-
Tuples Skipped: 76
1422+
Tuples: inserted=10 updated=9 deleted=5 skipped=76
14381423
-> Merge Left Join (actual rows=100 loops=1)
14391424
Merge Cond: (s.a = t.a)
14401425
-> Sort (actual rows=100 loops=1)
@@ -1445,7 +1430,7 @@ WHEN NOT MATCHED AND s.a < 20 THEN
14451430
Sort Key: t.a
14461431
Sort Method: quicksort Memory: xxx
14471432
-> Seq Scan on ex_mtarget t (actual rows=49 loops=1)
1448-
(15 rows)
1433+
(12 rows)
14491434

14501435
DROP TABLE ex_msource, ex_mtarget;
14511436
DROP FUNCTION explain_merge(text);

0 commit comments

Comments
 (0)