Re: extremely slow planner when DISTINCT clause holds more columns

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: extremely slow planner when DISTINCT clause holds more columns
Date: 2026-12-06 00:55:18
Message-ID: 0bc75a98-e7f1-45d5-b831-1fa0fe320570@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12/5/26 22:57, Tomas Vondra wrote:
>
> ...
>
> I haven't tried, but I think the key to improving this is to get rid of
> the linear search, likely by replacing it with a lookup in a hash table,
> or something like that.
>
> ISTM that if we extracted info about the EC for the "var" expression
> (I'm assuming there can be just one, but maybe we'd need to keep a
> list?), and keep a hash of those. And use that to quickly find if
> there's a matching expression, without the linear search.
>
> It'd need to be a bit more elaborate, because we only eliminate
> expressions from different relations, so we'd need to keep a list of
> rels for each EC, probably.
>

I meant something like the attached patch. It's a dirty PoC patch, it
passes "make check" but it can be broken in some way. I've also not
checked if it doesn't hurt simple queries etc.

--
Tomas Vondra

Attachment Content-Type Size
add_unique_group_var.patch text/x-patch 9.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2026-12-06 01:07:59 Re: Tracking per-RelOptInfo uniqueness during planning
Previous Message Abed Alawieh 2026-12-06 00:05:44 [PATCH] psql: Add tab completion for INSERT ... ON CONFLICT