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

Started by Xiaoxuan Li9 days ago3 messageshackers
Jump to latest
#1Xiaoxuan Li
xiaoxuan.li.dev@gmail.com

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

Attachments:

v1-0001-Fix-auto_explain-crash-REL_19_STABLE.patch.txttext/plain; charset=US-ASCII; name=v1-0001-Fix-auto_explain-crash-REL_19_STABLE.patch.txtDownload+66-5
v1-0001-Fix-auto_explain-crash-for-EXPLAIN-without-ANALYZE-on.patchapplication/octet-stream; name=v1-0001-Fix-auto_explain-crash-for-EXPLAIN-without-ANALYZE-on.patchDownload+69-6
In reply to: Xiaoxuan Li (#1)
Re: auto_explain crashes on EXPLAIN (BUFFERS) of an index scan (19, master)

On Fri, Nov 13, 2026 at 10:44 PM Xiaoxuan Li <xiaoxuan.li.dev@gmail.com> wrote:

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.

I'll look into this next week, after 19.0 is released. Its branch is
currently frozen.

Thanks
--
Peter Geoghegan

In reply to: Peter Geoghegan (#2)
Re: auto_explain crashes on EXPLAIN (BUFFERS) of an index scan (19, master)

On Sat, Nov 14, 2026 at 11:27 AM Peter Geoghegan <pg@bowt.ie> wrote:

I'll look into this next week, after 19.0 is released. Its branch is
currently frozen.

Pushed, thanks.

--
Peter Geoghegan