Skip to content

Commit

Permalink
Fix incorrect row count in EXPLAIN ANALYZE INSERT .. ON CONFLICT output
Browse files Browse the repository at this point in the history
INSERT ... ON CONFLICT statements record few metrics in the ModifyTable
node's instrument but they get overwritten by hypertable_modify_explain
causing wrong output in EXPLAIN ANALYZE statments. Fix it by saving the
metrics into HypertableModify node before replacing them.

Fixes timescale#6014
  • Loading branch information
lkshminarayanan committed Aug 29, 2023
1 parent 3b6dc7d commit db017a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .unreleased/bugfix_6014
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #6014 Correct row count in EXPLAIN ANALYZE INSERT .. ON CONFLICT output
11 changes: 10 additions & 1 deletion src/nodes/hypertable_modify.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,18 @@ hypertable_modify_explain(CustomScanState *node, List *ancestors, ExplainState *
}
#endif
/*
* Since we hijack the ModifyTable node instrumentation on ModifyTable will
* Since we hijack the ModifyTable node, instrumentation on ModifyTable will
* be missing so we set it to instrumentation of HypertableModify node.
*/
if (mtstate->ps.instrument)
{
/*
* INSERT .. ON CONFLICT statements record few metrics in the ModifyTable node.
* So, copy them into HypertableModify node before replacing them.
*/
node->ss.ps.instrument->ntuples2 = mtstate->ps.instrument->ntuples2;
node->ss.ps.instrument->nfiltered1 = mtstate->ps.instrument->nfiltered1;
}
mtstate->ps.instrument = node->ss.ps.instrument;
#endif

Expand Down

0 comments on commit db017a4

Please sign in to comment.