Re: Try a presorted outer path when referenced by an ORDER BY prefix

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Try a presorted outer path when referenced by an ORDER BY prefix
Date: 2026-05-13 14:03:28
Message-ID: CAN4CZFNXiuLztwqUCStR4VrCKH0WqHcsthP2CzkkFf5-k55=mA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello!

+ NestLoopState *nlstate = (NestLoopState *) child_node;
+ JoinType jointype = nlstate->js.jointype;
+
+ if (jointype == JOIN_LEFT)

Isn't a `nlstate->js.ps.qual == NULL` missing from here?

CREATE TABLE outer_t (id int, k int, payload text);
CREATE TABLE inner_t (id int, fk int, val int);
INSERT INTO outer_t
SELECT g, g, 'row_' || g FROM generate_series(1, 200) g;
INSERT INTO inner_t
SELECT g, g, g FROM generate_series(1, 200) g;
SET enable_hashjoin = off;
SET enable_mergejoin = off;
SET enable_material = off;
SELECT o.id, i.val
FROM outer_t o
LEFT JOIN inner_t i ON o.k = i.fk
WHERE (i.val IS NULL OR i.val > 50)
ORDER BY o.id
LIMIT 10;

+ else if (jointype == JOIN_RIGHT)
+ ExecSetTupleBound(tuples_needed, innerPlanState(child_node));

Is this branch reachable? If I follow the code correctly, it can't
happen with create_nestloop_path.

pg_plan_advice also has test failures with the patch applied.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alena Rybakina 2026-05-13 14:04:18 Re: pull-up subquery if JOIN-ON contains refs to upper-query
Previous Message SungJun Jang 2026-05-13 13:52:36 Re: Remove invalid SS2/SS3 handling from EUC-KR routines