Re: Optimize MCV stats for sortable types and utilize sorted-order properties

From: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>, tgl <tgl(at)sss(dot)pgh(dot)pa(dot)us>, tomas <tomas(at)vondra(dot)me>, dean(dot)a(dot)rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, guofenglinux <guofenglinux(at)gmail(dot)com>
Subject: Re: Optimize MCV stats for sortable types and utilize sorted-order properties
Date: 2026-10-14 04:24:32
Message-ID: tencent_4F6D5EB43E1325DF94969AD4E88D35F05F08@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

In v12, the CF tests showed failures in the following two TAP tests:
&nbsp; 271/429 postgresql:scripts / scripts/102_vacuumdb_stages&nbsp; ERROR &nbsp;6.22s exit status 2
&nbsp; 272/429 postgresql:scripts / scripts/100_vacuumdb&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ERROR 10.90s exit status 2

It was also able to reproduce the issue manually with the following commands:
SELECT pg_catalog.set_config('search_path', '', false);
SET default_statistics_target=10;
RESET vacuum_cost_delay;
ANALYZE pg_catalog.pg_proc;

The issue was caused by the MCV tracking logic. The fix is to remove the rightmost entry
with the smallest count and shift the following elements when the number of tracked
values reaches num_mcv, making room for the new value at the end:
/*
&nbsp;* If track_cnt reaches num_mcv, remove the rightmost
&nbsp;* entry with the smallest count and shift the
&nbsp;* following elements to the left, making room for the
&nbsp;* new value at the end.
&nbsp;*/

After applying this fix, the three related test cases pass successfully in my environment.

Thanks again.

regards,
--
ZizhuanLiu&nbsp;(X-MAN)&nbsp;
44973863(at)qq(dot)com

Attachment Content-Type Size
v13-0001-Optimize-MCV-statistics-for-sortable-types.patch application/octet-stream 115.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-10-14 04:26:28 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Tom Lane 2026-10-14 04:11:33 Re: [PG19] psql backslash commands fail with translated messages and a non UTF-8 client encoding