Incremental sorts and EXEC_FLAG_REWIND

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
Subject: Incremental sorts and EXEC_FLAG_REWIND
Date: 2020-04-14 06:53:36
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


When initializing an incremental sort node, we have the following as
of ExecInitIncrementalSort():
* Incremental sort can't be used with either EXEC_FLAG_REWIND,
* EXEC_FLAG_BACKWARD or EXEC_FLAG_MARK, because we only one of many sort
* batches in the current sort state.
Assert((eflags & (EXEC_FLAG_BACKWARD |
While I don't quite follow why EXEC_FLAG_REWIND should be allowed here
to begin with (because incremental sorts don't support rescans without
parameter changes, right?), the comment and the assertion are telling
a different story. And I can see that child nodes of an
IncrementalSort one use a set of eflags where these three are removed:
* Initialize child nodes.
* We shield the child node from the need to support REWIND, BACKWARD, or

I can also spot one case in the regression tests where we actually pass
down a REWIND flag (see incremental_sort.sql) when initializing an
IncrementalSort node:
-- We force the planner to choose a plan with incremental sort on the right side
-- of a nested loop join node. That way we trigger the rescan code path.
set local enable_hashjoin = off;
set local enable_mergejoin = off;
set local enable_material = off;
set local enable_sort = off;
explain (costs off) select * from t left join (select * from (select *
from t order by a) v order by a, b) s on s.a = t.a where t.a in (1,
select * from t left join (select * from (select * from t order by a)
v order by a, b) s on s.a = t.a where t.a in (1, 2);

Alexander, Tomas, any thoughts?


Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2020-04-14 07:12:56 Re: index paths and enable_indexscan
Previous Message Amit Langote 2020-04-14 06:43:36 index paths and enable_indexscan