Re: Bug in row_number() optimization
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Sergey Shinderuk <s.shinderuk@postgrespro.ru>
Cc: Richard Guo <guofenglinux@gmail.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>,
David Rowley <drowley@postgresql.org>
Date: 2022-11-24T23:34:29Z
Lists: pgsql-hackers
Attachments
- windowagg_fix.patch (text/plain) patch
On Fri, 25 Nov 2022 at 00:52, Sergey Shinderuk <s.shinderuk@postgrespro.ru> wrote: > 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. Thanks for reporting this and to you and Richard for working on a fix. I've just looked at it and it seems that valgrind is complaining because a tuple formed by an upper-level WindowAgg contains a pointer to free'd memory due to the byref type and eval_windowaggregates() not having been executed to fill in ecxt_aggvalues and ecxt_aggnulls on the lower-level WindowAgg. Since upper-level WindowAggs cannot reference values calculated in some lower-level WindowAgg, why can't we just NULLify the pointers instead? See attached. It is possible to have a monotonic window function that does not return int8. Technically something like MAX(text_col) OVER (PARTITION BY somecol ORDER BY text_col) is monotonically increasing, it's just that I didn't add a support function to tell the planner about that. Someone could come along in the future and suggest we do that and show us some convincing use case. So whatever the fix, it cannot assume the window function's return type is int8. David
Commits
-
Fix 32-bit build dangling pointer issue in WindowAgg
- 2a535620cec5 15.2 landed
- a8583272218a 16.0 landed
-
Teach planner and executor about monotonic window funcs
- 9d9c02ccd1ae 15.0 cited