Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options
Tatsuo Ishii <ishii@postgresql.org>
From: Tatsuo Ishii <ishii@postgresql.org>
To: krasiyan@gmail.com, ojford@gmail.com, tgl@sss.pgh.pa.us,
vik@postgresfriends.org, andrew@tao11.riddles.org.uk, david@fetter.org
Cc: pgsql-hackers@postgresql.org
Date: 2025-06-11T22:52:35Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix coding style with "else".
- 20628b62e46e 19 (unreleased) landed
-
Fix multi WinGetFuncArgInFrame/Partition calls with IGNORE NULLS.
- 2d7b247cb414 19 (unreleased) landed
-
Fix Coverity issue reported in commit 2273fa32bce.
- dd766a441d69 19 (unreleased) landed
-
Use ereport rather than elog in WinCheckAndInitializeNullTreatment.
- 5f3808646f67 19 (unreleased) landed
-
Avoid uninitialized-variable warnings from older compilers.
- 71540dcdcb22 19 (unreleased) cited
-
Fix Coverity issues reported in commit 25a30bbd423.
- 2273fa32bce7 19 (unreleased) landed
-
Improve EXPLAIN's display of window functions.
- 8b1b342544b6 18.0 cited
-
Automatically generate node support functions
- 964d01ae90c3 16.0 cited
Attachments
- v12-0001-Add-IGNORE-NULLS-RESPECT-NULLS-option-to-Window-.patch (application/octet-stream) patch v12-0001
- (unnamed) (text/plain)
> One thing I worry about the patch is, now the non-nulls array > optimization was removed. Since then I have been thinking about if > there could be other way to optimize searching for non null rows. Here is the v12 patch to implement the optimization on top of Oliver's v11 patch. Only src/backend/executor/nodeWindowAgg.c was modified (especially ignorenulls_getfuncarginframe). In the patch I created 2-bit not null information array, representing following status for each row: UNKNOWN: the row is not determined whether it's NULL or NOT yet. This is the initial value. NULL: the row has been determined to be NULL. NOT NULL: the row has been determined to be NOT NULL. In ignorenulls_getfuncarginframe: For the first time window function visits a row in a frame, the row is fetched using window_gettupleslot() and it is checked whether it is in the frame using row_is_in_frame(). If it's in the frame and the information in the array is UNKNOWN, ExecEvalExpr() is executed to find out if the expression on the function argument is NULL or not. And the result (NULL or NOT NULL) is stored in the array. If the information in the array is not UNKNOWN, we can skip calling ExecEvalExpr() because the information is already in the array. Note that I do not skip calling window_gettupleslot() and row_is_in_frame(), skip only calling ExecEvalExpr(), because whether a row is in a frame or not could be changing as the current row position moves while processing window functions. With this technique I observed around 40% speed up in my environment using the script attached, comparing with Oliver's v11 patch. v11: rows duration (msec) 1000 41.019 2000 148.957 3000 248.291 4000 442.478 5000 687.395 v12: rows duration (msec) 1000 27.515 2000 78.913 3000 174.737 4000 311.412 5000 482.156 The patch is now generated using the standard git format-patch. Also I have slightly adjusted the coding style so that it aligns with the one used in nodeWindowAgg.c, and ran pgindent. Note that I have not modified ignorenulls_getfuncarginpartition yet. I think we could optimize it using the not null info infrastructure as well. Will come up with it. Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp