Skip to content

EXPLAIN ANALYZE fails on INSERT ... ON CONFLICT: ON CONFLICT Tuples Inserted/Conflicting Tuples need ntuples2 accounting #112

Description

@lrweck

EXPLAIN ANALYZE fails on INSERT ... ON CONFLICT: ON CONFLICT Tuples Inserted/Conflicting Tuples need ntuples2 accounting

pgrust version: 0.2 (binary pgrust-0.2-linux-x86_64, PostgreSQL 18 compatible)
Component: show_modifytable_info() in explain.c (ModifyTable instrument, ntuples2)

Summary

EXPLAIN ANALYZE on any INSERT ... ON CONFLICT statement fails during plan display. pgrust's show_modifytable_info() needs the ntuples2 accounting from nodeModifyTable.c instrumentation (tuples inserted vs. tuples that hit the conflict path) and that counter is not wired up, so EXPLAIN aborts instead of printing the plan.

Reproducer

CREATE TABLE t (id int PRIMARY KEY, v int);
EXPLAIN (ANALYZE) INSERT INTO t (id, v) VALUES (1, 1)
ON CONFLICT (id) DO UPDATE SET v = EXCLUDED.v;

Also reproduces with ON CONFLICT DO NOTHING — any ON CONFLICT clause is enough.

Expected behaviour

A normal query plan like PostgreSQL 18.6 produces, including a Tuples Inserted / Tuples Conflicted breakdown on the Insert node.

Actual behaviour

ERROR:  show_modifytable_info (explain.c): ON CONFLICT Tuples Inserted/Conflicting Tuples need ntuples2 accounting nodeModifyTable instrument)

No plan is printed. There is no workaround — removing ANALYZE avoids the failure but then no execution stats (the reason you use EXPLAIN ANALYZE)
appear.

Notes

  • Independent of VERBOSE/BUFFERS/WAL; ANALYZE alone is sufficient.
  • Also breaks DO NOTHING, not just DO UPDATE.
  • This blocks EXPLAIN (ANALYZE) on any upsert, a very common write pattern.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions