Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e596e07

Browse files
committed
Assert that ExecOpenIndices and ExecCloseIndices are not repeated.
These functions should be called at most once per ResultRelInfo; it's wasteful to do otherwise, and certainly the pattern of opening twice and then closing twice is a bad idea. Moreover, aminsertcleanup functions might not be prepared to be called twice, as the just-hardened code in BRIN demonstrates. This amounts to an API change, since such coding patterns were safe even if wasteful before v17. Hence, apply to HEAD only. (Extension code violating this new rule faces some risk in v17, but we just fixed brininsertcleanup and there are probably few other aminsertcleanup functions as yet. So the odds of breaking usable code seem higher than the odds of doing something useful with a back-patch.) Bug: #18815 Reported-by: Sergey Belyashov <sergey.belyashov@gmail.com> Discussion: https://postgr.es/m/18815-2a0407cc7f40b327@postgresql.org
1 parent 9ff6867 commit e596e07

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/executor/execIndexing.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
181181
if (len == 0)
182182
return;
183183

184+
/* This Assert will fail if ExecOpenIndices is called twice */
185+
Assert(resultRelInfo->ri_IndexRelationDescs == NULL);
186+
184187
/*
185188
* allocate space for result arrays
186189
*/
@@ -246,19 +249,23 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
246249

247250
for (i = 0; i < numIndices; i++)
248251
{
249-
if (indexDescs[i] == NULL)
250-
continue; /* shouldn't happen? */
252+
/* This Assert will fail if ExecCloseIndices is called twice */
253+
Assert(indexDescs[i] != NULL);
251254

252255
/* Give the index a chance to do some post-insert cleanup */
253256
index_insert_cleanup(indexDescs[i], indexInfos[i]);
254257

255258
/* Drop lock acquired by ExecOpenIndices */
256259
index_close(indexDescs[i], RowExclusiveLock);
260+
261+
/* Mark the index as closed */
262+
indexDescs[i] = NULL;
257263
}
258264

259265
/*
260-
* XXX should free indexInfo array here too? Currently we assume that
261-
* such stuff will be cleaned up automatically in FreeExecutorState.
266+
* We don't attempt to free the IndexInfo data structures or the arrays,
267+
* instead assuming that such stuff will be cleaned up automatically in
268+
* FreeExecutorState.
262269
*/
263270
}
264271

0 commit comments

Comments
 (0)