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 ------ master Details ------- https://git.postgresql.org/pg/commitdiff/a20d50a00edc40ff11b08b1e3e3be6e4f9da51f6 Modified Files -------------- contrib/auto_explain/t/001_auto_explain.pl | 11 +++++++++++ src/backend/commands/explain.c | 13 +++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-)
