aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/index/indexam.c
diff options
context:
space:
mode:
authorTomas Vondra <tomas.vondra@postgresql.org>2023-11-27 16:52:59 +0100
committerTomas Vondra <tomas.vondra@postgresql.org>2023-11-27 16:53:06 +0100
commita82ee7ef3aacc2073d3ef5f4b7e5067fa08ea76c (patch)
tree5f31814440cafd3c633f0e8cd89fb54a5fc50cf0 /src/backend/access/index/indexam.c
parent1f395354d8742d57c166104874114b6e0d01e104 (diff)
downloadpostgresql-a82ee7ef3aacc2073d3ef5f4b7e5067fa08ea76c.tar.gz
postgresql-a82ee7ef3aacc2073d3ef5f4b7e5067fa08ea76c.zip
Check if ii_AmCache is NULL in aminsertcleanup
Fix a bug introduced by c1ec02be1d79. It may happen that the executor opens indexes on the result relation, but no rows end up being inserted. Then the index_insert_cleanup still gets executed, but passes down NULL to the AM callback. The AM callback may not expect this, as is the case of brininsertcleanup, leading to a crash. Fixed by only calling the cleanup callback if (ii_AmCache != NULL). This way the AM can simply assume to only see a valid cache. Reported-by: Richard Guo Discussion: https://postgr.es/m/CAMbWs4-w9qC-o9hQox9UHvdVZAYTp8OrPQOKtwbvzWaRejTT=Q@mail.gmail.com
Diffstat (limited to 'src/backend/access/index/indexam.c')
-rw-r--r--src/backend/access/index/indexam.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 597b763d1f6..f23e0199f08 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -207,7 +207,7 @@ index_insert_cleanup(Relation indexRelation,
RELATION_CHECKS;
Assert(indexInfo);
- if (indexRelation->rd_indam->aminsertcleanup)
+ if (indexRelation->rd_indam->aminsertcleanup && indexInfo->ii_AmCache)
indexRelation->rd_indam->aminsertcleanup(indexInfo);
}