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:17:14
Message-ID: 746bbfa8-f77a-4c17-9bee-853b77c146e7@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

There seems to be an issue in CreateStatistics(), triggering an assert.

Consider this:

CREATE TABLE t1 (id int);
CREATE TABLE t2 (id int, y int);

CREATE INDEX t2_idx ON t2 (id);

-- this errors-out
CREATE STATISTICS s
ON t2.y
FROM t2;

-- this crashes
CREATE STATISTICS s
ON t2.y
FROM t1 JOIN t2 ON t1.id = t2.id;

With a single-table stats, this this fails with

ERROR: cannot create extended statistics on a single non-virtual column

but with the join, this gets skipped, because it's gated by

if (numcols == 1 && !isjoin)
{
...
}

and so it hits the assert on line ~714:

Assert(ntypes > 0 && ntypes <= lengthof(types));

I suppose we joins we want to allow single-column stats, but in that
case we should be careful about properly filling some join kinds. It
probably should be treated as expression (STATS_EXT_EXPRESSIONS), but I
haven't tried.

regards

--
Tomas Vondra

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-08-09 15:04:53 Re: [PATCH] Make select_views regression test output deterministic
Previous Message Tomas Vondra 2026-08-09 14:05:34 Re: Is there value in having optimizer stats for joins/foreignkeys?