pgsql: Use default limitOption in subquery generated for MIN/MAX index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use default limitOption in subquery generated for MIN/MAX index
Date: 2026-09-18 15:02:24
Message-ID: E1x7a6a-00000000H8x-2fh9@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use default limitOption in subquery generated for MIN/MAX index scan.

We unintentionally copied the original query's limitOption field while
building the modified subquery. If it was LIMIT_OPTION_WITH_TIES,
that behavior would propagate through to execution, potentially
causing a "more than one row returned by a subquery used as an
expression" error. Fix by resetting to the default LIMIT_OPTION_COUNT.
This bug dates back to the introduction of WITH TIES.

Bug: #19694
Reported-by: Chaitanya Choudhary <chaitanyyachoudhary(at)gmail(dot)com>
Author: Chaitanya Choudhary <chaitanyyachoudhary(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/19694-4e61bd0475398eef@postgresql.org
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/32872d0c9790e570105f55682e92fba22ae1b38d

Modified Files
--------------
src/backend/optimizer/plan/planagg.c | 1 +
1 file changed, 1 insertion(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2026-09-18 17:19:35 pgsql: Fix memory leak in pgoutput with streamed prepared transactions.
Previous Message Álvaro Herrera 2026-09-18 11:41:44 pgsql: Tighten definition of ON CONFLICT arbiter index equivalence