Avoid possible divide-by-zero in gincostestimate.
authorTom Lane <[email protected]>
Thu, 21 Apr 2011 23:28:36 +0000 (19:28 -0400)
committerTom Lane <[email protected]>
Thu, 21 Apr 2011 23:28:36 +0000 (19:28 -0400)
Per report from Jeff Janes.

src/backend/utils/adt/selfuncs.c

index 4d800f8a007980dbac1d221d48f0fa8b0e30db66..fa8cecafcbe5b4bef44d12549a35f7e27c838c3c 100644 (file)
@@ -6458,6 +6458,10 @@ gincostestimate(PG_FUNCTION_ARGS)
                numDataPages = Min(numDataPages, numPages - numEntryPages);
        }
 
+       /* In an empty index, numEntries could be zero.  Avoid divide-by-zero */
+       if (numEntries < 1)
+               numEntries = 1;
+
        /*
         * Include predicate in selectivityQuals (should match
         * genericcostestimate)