Widen lossy and exact page counters for Bitmap Heap Scan
authorDavid Rowley <[email protected]>
Mon, 8 Jul 2024 02:43:09 +0000 (14:43 +1200)
committerDavid Rowley <[email protected]>
Mon, 8 Jul 2024 02:43:09 +0000 (14:43 +1200)
Both of these counters were using the "long" data type.  On MSVC that's
a 32-bit type.  On modern hardware, I was able to demonstrate that we can
wrap those counters with a query that only takes 15 minutes to run.

This issue may manifest itself either by not showing the values of the
counters because they've wrapped and are less than zero, resulting in
them being filtered by the > 0 checks in show_tidbitmap_info(), or bogus
numbers being displayed which are modulus 2^32 of the actual number.

Widen these counters to uint64.

Discussion: https://postgr.es/m/CAApHDvpS_97TU+jWPc=T83WPp7vJa1dTw3mojEtAVEZOWh9bjQ@mail.gmail.com

src/backend/commands/explain.c
src/include/nodes/execnodes.h

index 1e80fd8b68c4c104bb7d54a5f623452485e57634..6defd26df50b1dbf2c546e1ea8ba40fa207d746a 100644 (file)
@@ -3635,10 +3635,10 @@ show_tidbitmap_info(BitmapHeapScanState *planstate, ExplainState *es)
 {
    if (es->format != EXPLAIN_FORMAT_TEXT)
    {
-       ExplainPropertyInteger("Exact Heap Blocks", NULL,
-                              planstate->exact_pages, es);
-       ExplainPropertyInteger("Lossy Heap Blocks", NULL,
-                              planstate->lossy_pages, es);
+       ExplainPropertyUInteger("Exact Heap Blocks", NULL,
+                               planstate->exact_pages, es);
+       ExplainPropertyUInteger("Lossy Heap Blocks", NULL,
+                               planstate->lossy_pages, es);
    }
    else
    {
@@ -3647,9 +3647,9 @@ show_tidbitmap_info(BitmapHeapScanState *planstate, ExplainState *es)
            ExplainIndentText(es);
            appendStringInfoString(es->str, "Heap Blocks:");
            if (planstate->exact_pages > 0)
-               appendStringInfo(es->str, " exact=%ld", planstate->exact_pages);
+               appendStringInfo(es->str, " exact=" UINT64_FORMAT, planstate->exact_pages);
            if (planstate->lossy_pages > 0)
-               appendStringInfo(es->str, " lossy=%ld", planstate->lossy_pages);
+               appendStringInfo(es->str, " lossy=" UINT64_FORMAT, planstate->lossy_pages);
            appendStringInfoChar(es->str, '\n');
        }
    }
index b62c96f2064895831dca89ab945777fcda9b2017..abfcd5f590586ebaa225d6d07b56f91716f5104f 100644 (file)
@@ -1817,8 +1817,8 @@ typedef struct BitmapHeapScanState
    TBMIterator *tbmiterator;
    TBMIterateResult *tbmres;
    Buffer      pvmbuffer;
-   long        exact_pages;
-   long        lossy_pages;
+   uint64      exact_pages;
+   uint64      lossy_pages;
    TBMIterator *prefetch_iterator;
    int         prefetch_pages;
    int         prefetch_target;