Re: Bug in row_number() optimization
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Sergey Shinderuk <s.shinderuk@postgrespro.ru>,
Richard Guo <guofenglinux@gmail.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>,
David Rowley <drowley@postgresql.org>
Date: 2022-11-28T00:23:16Z
Lists: pgsql-hackers
Attachments
- windowagg_fix_v2.patch (text/plain) patch v2
On Sat, 26 Nov 2022 at 05:19, Tom Lane <tgl@sss.pgh.pa.us> wrote: > > Sergey Shinderuk <s.shinderuk@postgrespro.ru> writes: > > What about user-defined operators? I created my own <= operator for int8 > > which returns true on null input, and put it in a btree operator class. > > Admittedly, it's weird that (null <= 1) evaluates to true. But does it > > violate the contract of the btree operator class or something? Didn't > > find a clear answer in the docs. > > It's pretty unlikely that this would work during an actual index scan. > I'm fairly sure that btree (and other index AMs) have hard-wired > assumptions that index operators are strict. If we're worried about that then we could just restrict this optimization to only work with strict quals. The proposal to copy the datums into the query context does not seem to me to be a good idea. If there are a large number of partitions then it sounds like we'll leak lots of memory. We could invent some partition context that we reset after each partition, but that's probably more complexity than it would be worth. I've attached a draft patch to move the code to nullify the aggregate results so that's only done once per partition and adjusted the planner to limit this to strict quals. 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