Re: [PATCH] ANALYZE: hash-accelerate MCV tracking for equality-only types - Mailing list pgsql-hackers

From Ilia Evdokimov
Subject Re: [PATCH] ANALYZE: hash-accelerate MCV tracking for equality-only types
Date
Msg-id 2e204485-8bf3-4ef4-add8-0563c536a537@tantorlabs.com
Whole thread Raw
In response to Re: [PATCH] ANALYZE: hash-accelerate MCV tracking for equality-only types  (Chengpeng Yan <chengpeng_yan@Outlook.com>)
List pgsql-hackers

On 22.01.2026 12:40, Chengpeng Yan wrote:

The v2 patch is attached.

I took a deeper look at the v2 patch. The hash-based lookup itself looks correct, and when testing ANALYZE runtime with large default_statistics_target values, the patch indeed provides a noticeable speedup.

I have one small suggestion regarding the handling of firstcount1 and c1_cursor in the 'match' path.

When we find a match in track[], we increment count and perform bubble-up swaps to keep the array ordered by frequency. If the value previously has count = 1, it is effectively leaving the singleton (count = 1) region and becoming part of the count>1. Conceptually, this means that the boundary between these two regions (firstcount1) should move left by one.

Given that, it seems sufficient to update the boundary and then ensure that c1_cursor still point inside the singleton region:

if (was_count1 && j < firstcount1)
    firstcount1--;
if (c1_cursor < firstcount1)
    c1_cursor = firstcount1;

This avoids reasoning about specific shifted subranges (firstcount1..match_index). FIFO behavior is still preserved because c1_cursor is only advanced when an eviction actually happens.

Let me know if I'm overlooking any corner cases.

--
Best regards.
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Buffer locking is special (hints, checksums, AIO writes)
Next
From: Nathan Bossart
Date:
Subject: Re: Pasword expiration warning