Fix incorrect false positive rate formatting in create_and_test_bloom() - Mailing list pgsql-hackers

From Postgress Cybrosys
Subject Fix incorrect false positive rate formatting in create_and_test_bloom()
Date
Msg-id CAG+=MFUzje9-4jAbS=ZWGPA0Ggg7wuPkh5dadcY5MnwA10+gFg@mail.gmail.com
Whole thread
List pgsql-hackers
Hi,

I noticed a bug in src/test/modules/test_bloomfilter/test_bloomfilter.c where the false positive rate is displayed incorrectly in create_and_test_bloom().

The issue is in the ereport() call:

    errmsg_internal("seed: " UINT64_FORMAT " false positives: " INT64_FORMAT " (%.6f%%) bitset %.2f%% set",
                     seed, nfalsepos, (double) nfalsepos / nelements,
                     100.0 * bloom_prop_bits_set(filter))

The format specifier %.6f%% expects a value already scaled to a percentage, but (double) nfalsepos / nelements produces a raw fraction. This means a true false positive rate of 0.5% is displayed as 0.005000% — 100x smaller than the actual value.

This is inconsistent with the very next argument, bloom_prop_bits_set(), which is correctly multiplied by 100.0 before being passed to its %.2f%% format specifier.

The fix is straightforward — multiply the ratio by 100.0:

    - seed, nfalsepos, (double) nfalsepos / nelements,
    + seed, nfalsepos, 100.0 * (double) nfalsepos / nelements,

Patch is attached.

Thanks & Regards,

Jhon k

Postgres Specialist

Project & IT Department

Cybrosys Technologies


Mail

Mobile

WhatsApp


postgress@cybrosys.com

+91 8606827707

+91 8606827707


Attachment

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Introduce XID age based replication slot invalidation
Next
From: Lukas Fittl
Date:
Subject: Re: pg_buffercache: Add per-relation summary stats