aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2024-07-05 16:56:16 +1200
committerDavid Rowley <drowley@postgresql.org>2024-07-05 16:56:16 +1200
commit53abb1e0ebc38818f31f2ddb15a06feba8e19e6c (patch)
tree89542734dc1d25fee5ef59dc5487c484e12198e4
parent18501841bcb4e693b9f1e9da2b2fb524c78940d8 (diff)
downloadpostgresql-53abb1e0ebc38818f31f2ddb15a06feba8e19e6c.tar.gz
postgresql-53abb1e0ebc38818f31f2ddb15a06feba8e19e6c.zip
Fix newly introduced issue in EXPLAIN for Materialize nodes
The code added in 1eff8279d was lacking a check to see if the tuplestore had been created. In nodeMaterial.c this is done by ExecMaterial() rather than by ExecInitMaterial(), so the tuplestore won't be created unless the node has been executed at least once, as demonstrated by Alexander in his report. Here we skip showing any of the new EXPLAIN ANALYZE information when the Materialize node has not been executed. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/fe7fc8fb-86e5-ecb0-3cb2-dd2c9a6c482f@gmail.com
-rw-r--r--src/backend/commands/explain.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 1b5ab503898..1e80fd8b68c 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -3333,14 +3333,17 @@ show_hash_info(HashState *hashstate, ExplainState *es)
static void
show_material_info(MaterialState *mstate, ExplainState *es)
{
- Tuplestorestate *tupstore;
+ Tuplestorestate *tupstore = mstate->tuplestorestate;
const char *storageType;
int64 spaceUsedKB;
- if (!es->analyze)
+ /*
+ * Nothing to show if ANALYZE option wasn't used or if execution didn't
+ * get as far as creating the tuplestore.
+ */
+ if (!es->analyze || tupstore == NULL)
return;
- tupstore = mstate->tuplestorestate;
storageType = tuplestore_storage_type_name(tupstore);
spaceUsedKB = BYTES_TO_KILOBYTES(tuplestore_space_used(tupstore));