Re: Is there value in having optimizer stats for joins/foreignkeys?

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Alexandra Wang <alexandra(dot)wang(dot)oss(at)gmail(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, ilya(dot)evdokimov(at)tantorlabs(dot)com
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Andrei Lepikhov <lepihov(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, hs(at)cybertec(dot)at, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: Re: Is there value in having optimizer stats for joins/foreignkeys?
Date: 2026-08-09 14:05:34
Message-ID: 378266ed-ff65-4624-9fa1-cd4ffeb7212a@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 8/9/26 00:08, Tomas Vondra wrote:
> ...
>
> 0002 - Unify extended statistics columns and expressions
>
> I think there's a couple issuses.
>
> - The psql describe code still checks (sversion >= 190000), but that's
> now wrong, it needs to check 200000. A simple rebase omission, but
> it can lead to failures on 19.
>
I noticed another minor issue in the psql describe code, in parsing the
statistics definition. If you do this

create statistics "aaaa ON bbbb" (mcv) ON a, b, c FROM t;

then "\d t" shows

Statistics objects:
"public.aaaa ON bbbb" (mcv) ON bbbb" (mcv) ON a, b, c FROM t

which is clearly confused. AFIAK this happens because
pg_get_statisticsobjdef_columns_from does about this

res = pg_get_statisticsobj_worker(statextid, true);
...
on_ptr = strstr(res, " ON ");

but the strstr() fails to consider the stxname could already contain the
string " ON ", and gets confused by it.

I think it could be fixed by adding a flag to
pg_get_statisticsobj_worker, to simply not generate the initial part at
all (and then the strstr is not needed at all). Or maybe it could return
the offset where the columns begin, also makes strstr unnecessary.

regards

--
Tomas Vondra

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-08-09 14:17:14 Re: Is there value in having optimizer stats for joins/foreignkeys?
Previous Message Greg Burd 2026-08-09 13:37:49 Re: problems with toast.* reloptions