Fix auto_explain index scan NULL pointer dereference. Commit f026fbf059f, which made IndexScanInstrumentation into a pointer stored in various executor scan nodes, allocated the underlying instrumentation state at the point where the executor first initialized these nodes, though only when the plan was actually going to be run. This scheme assumed that EXPLAIN would only need to show the relevant counters for a plan that had actually run.
That was correct for EXPLAIN, but failed to account for contrib/auto_explain's auto_explain.log_analyze option. This option sets es->analyze when logging the plan of an EXPLAIN (BUFFERS) without ANALYZE. The plan wouldn't run there, leading to a NULL pointer dereference crash. To fix, check that the instrumentation was allocated before using it. Author: Xiaoxuan Li <[email protected]> Discussion: https://postgr.es/m/canuorazumpvu2pjwghvwihkfmutncwebknbzg5-o3aq0uuk...@mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/921c555eb2e32d246383d92183c06df4112e96b9 Modified Files -------------- contrib/auto_explain/t/001_auto_explain.pl | 11 +++++++++++ src/backend/commands/explain.c | 9 ++++++--- 2 files changed, 17 insertions(+), 3 deletions(-)
