Re: Some ExecSeqScan optimizations

From: Andres Freund <andres(at)anarazel(dot)de>
To: Nikita Malakhov <hukutoc(at)gmail(dot)com>
Cc: Amit Langote <amitlangote09(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Vladlen Popolitov <v(dot)popolitov(at)postgrespro(dot)ru>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Junwang Zhao <zhjwpku(at)gmail(dot)com>
Subject: Re: Some ExecSeqScan optimizations
Date: 2025-07-11 14:37:24
Message-ID: h3bwxhgettdha54rezczzn7b7tlgbno2zagvkldvk3jhi4upnr@3uqng7ezjtk7
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2025-07-11 14:03:42 +0300, Nikita Malakhov wrote:
> It's a pity I missed this thread when you developed the patch.
> I've developed a feature recently and discovered that SeqScan
> does not make use of scan keys, and there is a Tom Lane's
> comment regarding this:
> * Note that unlike IndexScan, SeqScan never use keys in heap_beginscan
> * (and this is very bad) - so, here we do not check are keys ok or not.
>
> Have you considered passing scan keys like it is done in IndexScan?

You can't easily do that without causing issues:

1) ScanKeys are evaluated while holding a buffer lock, we shouldn't do that
with arbitrary functions (since they could recurse and acquire other locks
in a non-correct order)

2) ScanKeys are rather restrictive in what they can express, but not
restrictive enough to make 1) not a problem. That means that you can't just
evaluate the whole predicate using ScanKeys.

3) ScanKey evaluation is actually sometimes *more* expensive than expression
evaluation, because the columns are deformed one-by-one.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2025-07-11 14:51:40 Re: Horribly slow pg_upgrade performance with many Large Objects
Previous Message Andres Freund 2025-07-11 14:34:33 Re: Some ExecSeqScan optimizations