]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use add_size/mul_size for index instrumentation size calculations
authorTomas Vondra <tomas.vondra@postgresql.org>
Tue, 7 Apr 2026 10:47:26 +0000 (12:47 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Tue, 7 Apr 2026 10:47:28 +0000 (12:47 +0200)
Use overflow-safe size arithmetic in the Index[Only]Scan and parallel
instrumentation functions, consistent with other executor nodes (Hash,
Sort, Agg, Memoize). This was an oversight in dd78e69cfc3.

Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Lukas Fittl <lukas@fittl.com>
Discussion: https://postgr.es/m/flat/a177a6dd-240b-455a-8f25-aca0b1c08c6e%40vondra.me

src/backend/executor/nodeIndexonlyscan.c
src/backend/executor/nodeIndexscan.c

index c4ff422756eb2af598203f18e92576d54c14fd9b..d52012e8a6987ab34dcef47afbdfe9b211ff093e 100644 (file)
@@ -854,8 +854,8 @@ ExecIndexOnlyScanInstrumentEstimate(IndexOnlyScanState *node,
         * in the IndexOnlyScanState. We'll recalculate the needed size in
         * ExecIndexOnlyScanInstrumentInitDSM().
         */
-       size = offsetof(SharedIndexScanInstrumentation, winstrument) +
-               pcxt->nworkers * sizeof(IndexScanInstrumentation);
+       size = add_size(offsetof(SharedIndexScanInstrumentation, winstrument),
+                                       mul_size(pcxt->nworkers, sizeof(IndexScanInstrumentation)));
        shm_toc_estimate_chunk(&pcxt->estimator, size);
        shm_toc_estimate_keys(&pcxt->estimator, 1);
 }
@@ -872,8 +872,8 @@ ExecIndexOnlyScanInstrumentInitDSM(IndexOnlyScanState *node,
        if (!node->ss.ps.instrument || pcxt->nworkers == 0)
                return;
 
-       size = offsetof(SharedIndexScanInstrumentation, winstrument) +
-               pcxt->nworkers * sizeof(IndexScanInstrumentation);
+       size = add_size(offsetof(SharedIndexScanInstrumentation, winstrument),
+                                       mul_size(pcxt->nworkers, sizeof(IndexScanInstrumentation)));
        node->ioss_SharedInfo =
                (SharedIndexScanInstrumentation *) shm_toc_allocate(pcxt->toc, size);
 
index 6cc927f24547e51c394a8e54a268b41942a13655..39f6691ee35ed2fa68fc59df454d5da2ccf5d2f5 100644 (file)
@@ -1789,8 +1789,8 @@ ExecIndexScanInstrumentEstimate(IndexScanState *node,
         * in the IndexScanState. We'll recalculate the needed size in
         * ExecIndexScanInstrumentInitDSM().
         */
-       size = offsetof(SharedIndexScanInstrumentation, winstrument) +
-               pcxt->nworkers * sizeof(IndexScanInstrumentation);
+       size = add_size(offsetof(SharedIndexScanInstrumentation, winstrument),
+                                       mul_size(pcxt->nworkers, sizeof(IndexScanInstrumentation)));
        shm_toc_estimate_chunk(&pcxt->estimator, size);
        shm_toc_estimate_keys(&pcxt->estimator, 1);
 }
@@ -1807,8 +1807,8 @@ ExecIndexScanInstrumentInitDSM(IndexScanState *node,
        if (!node->ss.ps.instrument || pcxt->nworkers == 0)
                return;
 
-       size = offsetof(SharedIndexScanInstrumentation, winstrument) +
-               pcxt->nworkers * sizeof(IndexScanInstrumentation);
+       size = add_size(offsetof(SharedIndexScanInstrumentation, winstrument),
+                                       mul_size(pcxt->nworkers, sizeof(IndexScanInstrumentation)));
        node->iss_SharedInfo =
                (SharedIndexScanInstrumentation *) shm_toc_allocate(pcxt->toc, size);