Re: Bug in row_number() optimization

Sergey Shinderuk <s.shinderuk@postgrespro.ru>

From: Sergey Shinderuk <s.shinderuk@postgrespro.ru>
To: Richard Guo <guofenglinux@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>, David Rowley <drowley@postgresql.org>
Date: 2022-11-24T11:52:30Z
Lists: pgsql-hackers
On 24.11.2022 06:16, Richard Guo wrote:
> Regarding how to fix this problem, firstly I believe we need to evaluate
> window functions in the per-tuple memory context, as the HEAD does.
> When we decide we need to go into pass-through mode, I'm thinking that
> we can just copy out the results of the last evaluation to the per-query
> memory context, while still storing their pointers in ecxt_aggvalues.
> 
> Does this idea work?
Although I'm not familiar with the code, this makes sense to me.

You proposed:

+#ifdef USE_FLOAT8_BYVAL
+       evalWfuncContext = 
winstate->ss.ps.ps_ExprContext->ecxt_per_tuple_memory;
+#else
+       evalWfuncContext = 
winstate->ss.ps.ps_ExprContext->ecxt_per_query_memory;
+#endif

Shouldn't we handle any pass-by-reference type the same? I suppose, a 
user-defined window function can return some other type, not int8.

Best regards,

-- 
Sergey Shinderuk		https://postgrespro.com/




Commits

  1. Fix 32-bit build dangling pointer issue in WindowAgg

  2. Teach planner and executor about monotonic window funcs