auto_explain crashes on EXPLAIN (BUFFERS) of an index scan (19, master)

From: Xiaoxuan Li <xiaoxuan(dot)li(dot)dev(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Peter Geoghegan <pg(at)bowt(dot)ie>
Subject: auto_explain crashes on EXPLAIN (BUFFERS) of an index scan (19, master)
Date: 2026-11-14 03:44:17
Message-ID: CANuORAZumpvu2PJwGhVWihKfmUTNcWEbknBZG5-O3aq0uuKbhw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On REL_19_STABLE (e2b2267d24e, 19rc2) and master (206e71935e1),
EXPLAIN (BUFFERS) without ANALYZE of a query that uses an index
crashes the backend when auto_explain logs it with log_analyze on:

CREATE TABLE t (a int PRIMARY KEY, b int);
LOAD 'auto_explain';
SET auto_explain.log_min_duration = 0;
SET auto_explain.log_analyze = on;
EXPLAIN (BUFFERS) SELECT * FROM t WHERE a = 5;
server closed the connection unexpectedly

#0 show_indexscan_info ()
#1 ExplainNode ()
#2 ExplainPrintPlan ()
#3 explain_ExecutorEnd ()

Index Scan, Index Only Scan and Bitmap Index Scan plans all crash.
18.6 is fine. f026fbf059f crashes and its parent does not.

Since f026fbf059f the index scan nodes do not allocate their
IndexScanInstrumentation under EXEC_FLAG_EXPLAIN_ONLY. auto_explain
still prints such a plan with es->analyze set, because EXPLAIN
(BUFFERS) asks for buffer instrumentation, and show_indexscan_info()
(show_indexsearches_info() in 19) dereferences the NULL pointer.

The attached patch treats the missing instrumentation as zero counts,
so the log shows "(never executed)" and "Index Searches: 0" as it did
before f026fbf059f, and adds cases to auto_explain's TAP test that
crash without the fix. The master patch does not apply to
REL_19_STABLE, so there is a separate version for it.

I fixed this in explain.c rather than in auto_explain because
ExplainNode already tolerates es->analyze without instrumentation,
and ExplainPrintPlan() can be called by other extensions.

--
Xiaoxuan Li
Amazon Web Services

Attachment Content-Type Size
v1-0001-Fix-auto_explain-crash-REL_19_STABLE.patch.txt text/plain 5.0 KB
v1-0001-Fix-auto_explain-crash-for-EXPLAIN-without-ANALYZE-on.patch application/octet-stream 5.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayush Tiwari 2026-11-14 05:42:09 Re: Index drops during phase 1 of REINDEX CONCURRENTLY
Previous Message Amit Kapila 2026-11-14 03:34:57 Re: Assertion failure in update_local_synced_slot(), slotsync.c:364