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

From: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>
To: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Optimize MCV stats for sortable types and utilize sorted-order properties
Date: 2026-12-03 10:48:41
Message-ID: tencent_DCE117DA1A682F26B6BFD52C99A8711ACD09@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Original
>From: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>
>Date: 2026-12-01 20:05
>To: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
>Subject: Re: Optimize MCV stats for sortable types and utilize sorted-order properties
>
>Hi,
>
>I tested the v16 patch on master with JOB. JOB seemed like a good fit
>for this patch because its queries contain many joins and WHERE col = const.
>
>I set default_statistics_target = 10000 to allow for larger MCV lists.
>In this run, however, I did NOT see an overall improvement in planning time.
>
>Do you have a workload where you see a measureable improvement in
>overall planning time?
>
>--
>Best regards,
>Ilia Evdokimov,
>Tantor Labs LLC,
>https://tantorlabs.com/

Hi, Ilia

I tried running a few more tests to see if they met your requirements.

Tables with SET STATISTICS 10000 and 0000 distinct values :
- int4_n10000_uniform,int8_n10000_uniform,numeric_n10000_uniform,text_n10000_uniform,

In the test scenario "int4.in.sql /text.in.sql", since eqjoinsel() exceeded EQJOINSEL_MCV_HASH_THRESHOLD 200,
the following table and test were added:
Table with SET STATISTICS 99 and 9 distinct values :
- int4_n99_uniform, text_n99_uniform
and the corresponding test scenarios “int4.in.99.sql/text.in.99.sql”

Here is a summary of my test results:
eq.100000.sql
var_eq_const Planning Time
master(ms) 0.061 0.123
patch(ms) 0.034 0.093
detal 0.026 0.031
detal% 43.50% 24.92%

lt.1.sql
mcv_selectivity Planning Time
master(ms) 0.070 0.128
patch(ms) 0.047 0.102
detal 0.022 0.027
detal% 32.14% 20.70%

int4.in.sql
eqjoinsel-toal mergejoinscansel Planning Time:
maseter 1.29124507 0.60180316 2.06165
patch 1.35768326 0.32950809 1.84561
detal -0.066 0.272 0.282
detal% -5.15% 45.25% 13.70%
-- eqjoinsel go hash patch, please ignore

text.in.sql
eqjoinsel-toal mergejoinscansel Planning Time:
maseter 73.72562597 28.49585269 102.64107
patch 74.34294464 20.66907106 95.39703
detal -0.617 7.827 7.861
detal% -0.84% 27.47% 7.66%
-- eqjoinsel go hash patch, please ignore

int4.in.99.sql
eqjoinsel-toal mergejoinscansel Planning Time:
maseter 0.01840156 0.03563112 0.18804
patch 0.00931159 0.03294026 0.17443
detal 0.009 0.003 0.014
detal% 49.40% 7.55% 7.24%
--mergejoinscansel() only increased slightly, which does not match my expectations, but I have not yet found the reason.

text.in.99.sql
eqjoinsel-toal mergejoinscansel Planning Time:
maseter 0.28732113 0.11458608 0.52979
patch 0.27169292 0.08107434 0.47878
detal 0.016 0.034 0.051
detal% 5.44% 29.25% 9.63%

Test process:
1.setup.sql
2.perf_test_20261202.tar --test sql & shell
2.Performance Comparison for Common Data Types-2026-12-03-master_v15_timing.xlsx
- Methods for initiating tests, such as: sh master.text.in.99.sh
- and methods for extracting metrics, such as: cat master.text.in.99.out|grep "eqjoinsel("|grep -n "eqjoinsel("|awk 'NR%2==1' | awk '{print $NF'}
- as well as analysis of the test results

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

Attachment Content-Type Size
setup.sql application/octet-stream 2.8 KB
perf_test_20261202.tar application/octet-stream 90.0 KB
Performance Comparison for Common Data Types-2026-12-03-master_v15_timing.xlsx application/octet-stream 84.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-12-03 10:55:00 Re: Unused code in brin_minmax_multi_consistent
Previous Message shveta malik 2026-12-03 10:36:54 Re: Show the conflict log table in \dRs+ output