| From: | Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com> |
|---|---|
| To: | Damil Shahzad <shahzaddamil(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | ZizhuanLiu X-MAN <44973863(at)qq(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Fix var_eq_const: sum selectivity of all matching MCV entries instead of stopping at first match |
| Date: | 2026-08-05 07:33:14 |
| Message-ID: | 9000641c-0ed7-4690-a4f4-58294a96b0c8@tantorlabs.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 8/4/26 14:29, Damil Shahzad wrote:
> Tom's concern still seems important. Scanning the whole MCV list every
> time would cost more in the common case, and it only changes the
> result when the comparison operator or collation is different from the
> equality used to build the statistics. Before this can move forward, I
> think we need a stronger reason for that tradeoff.
>
+1
A cheaper way to get some benefit here without touching that tradeoff:
when there are no MCV matches, var_eq_const does a second full pass over
MCV list just to compute `sumcommon` - but that branch is only reached
after the first loop has already scanned every entry. So `sumcommon` can
be accumulated inline in that same scan, and the separate summing loop
dropped. The match case is unaffected; only the no-match path gets
faster, by skipping a redundant second traversal.
I attached patch with these changes. What do you think?
--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Merge-MCV-match-and-sum-loops-in-var_eq_cons.patch | text/x-patch | 1.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Mihail Nikalayeu | 2026-08-05 07:58:14 | Re: RI fast path gets cross-type foreign keys wrong |
| Previous Message | Chao Li | 2026-08-05 07:29:17 | pg_createsubscriber: allow duplicate subscription names |