| From: | Henson Choi <assam258(at)gmail(dot)com> |
|---|---|
| To: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
| Cc: | sjjang112233(at)gmail(dot)com, vik(at)postgresfriends(dot)org, er(at)xs4all(dot)nl, jacob(dot)champion(at)enterprisedb(dot)com, david(dot)g(dot)johnston(at)gmail(dot)com, peter(at)eisentraut(dot)org, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: Row pattern recognition |
| Date: | 2026-03-08 14:24:55 |
| Message-ID: | CAAAe_zCvHz=tHkggP37OoQH8R0ux4j_CJdBTiPUg-L=6cVMyWg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Tatsuo,
> Question is, should we fix optimize_window_clause as well?
Yes, we should. The comment in optimize_window_clauses explicitly
states "Perform the same duplicate check that is done in
transformWindowFuncCall", so the two checks must remain in sync.
Even if omitting the RPR fields produces no visible bug today (because
the early return guard in nocfbot-0006 already skips RPR windows), the
code would be misleading and fragile: a future change could remove
that guard and silently reintroduce the bug.
Adding the RPR fields explicitly also serves as defensive coding and
makes the intent clear to anyone reading or modifying the code later.
When incorporating nocfbot-0006 as patch 06/12, this fix was included:
wc->rpSkipTo == existing_wc->rpSkipTo &&
wc->initial == existing_wc->initial &&
equal(wc->defineClause, existing_wc->defineClause) &&
equal(wc->rpPattern, existing_wc->rpPattern)
Patch 06/12 now covers both the frame optimization guard and the
optimize_window_clauses deduplication fix, with EXPLAIN-based regression
tests added to verify the behavior.
> The two window definitions are regarded as identical and produces
> wrong result.
Thank you for finding this. Your patch has been incorporated as patch
09/12 ("Fix window deduplication for RPR windows at parse time"),
modified to add regression test cases covering the scenario. The fix
adds the missing RPR check in transformWindowFuncCall:
equal(refwin->rpCommonSyntax, windef->rpCommonSyntax)
This prevents incorrect merging of an RPR window with a non-RPR window
that has identical frame options.
The previous submission (nocfbot-0001..0008) has been extended to
12 patches. Changes since the last submission:
06/12 Disable frame optimization for RPR windows [updated]
optimize_window_clauses deduplication fix added, as discussed.
09/12 Fix window deduplication for RPR windows at parse time [new]
Incorporates your fix with test cases added.
10/12 Walk DEFINE clause in window tree traversal [new]
A newly discovered issue: nodeFuncs.c was not visiting the
DEFINE clause in expression_tree_walker, query_tree_walker,
and their mutator counterparts. The demonstrated case is SQL
function inlining: a SQL function with a parameter used in
DEFINE (e.g., DEFINE A AS v > $1) would fail to substitute
the actual argument, producing wrong results.
11/12 Use SQL standard term "empty match" in RPR comments [new]
Align NFA comment terminology with the SQL standard: replace
implementation-specific terms "zero-length match" and
"zero-consumption" with the standard term "empty match".
12/12 Extract RPR NFA engine into execRPR.c [new]
Following the earlier discussion about file layout, this
implements option (b): move the NFA engine to a dedicated
src/backend/executor/execRPR.c, keeping it close to
nodeWindowAgg.c while making the boundary explicit. Functions
still take WindowAggState as an argument (no signature change).
The public interface is declared in execRPR.h using the ExecRPR*
naming convention, consistent with other executor headers.
The NFA algorithm guide shared earlier in this thread has also
been incorporated as structured comments at the top of the file,
as suggested.
The full updated series (12 patches on top of v44) is attached.
Regards,
Henson
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-fix-elog-lowercase.txt | text/plain | 827 bytes |
| 0002-fix-reluctant-flag-view.txt | text/plain | 9.7 KB |
| 0003-expand-test-coverage.txt | text/plain | 266.0 KB |
| 0004-keep-test-objects.txt | text/plain | 151.1 KB |
| 0005-disable-run-condition.txt | text/plain | 1.7 KB |
| 0006-disable-frame-opt.txt | text/plain | 10.9 KB |
| 0007-stock-scenario-tests.txt | text/plain | 103.8 KB |
| 0008-fix-zero-min-reluctant.txt | text/plain | 15.4 KB |
| 0009-fix-window-dedup.txt | text/plain | 3.9 KB |
| 0010-walk-define-clause.txt | text/plain | 4.2 KB |
| 0011-use-empty-match-term.txt | text/plain | 2.8 KB |
| 0012-extract-nfa-engine.txt | text/plain | 209.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sahitya Chandra | 2026-03-08 14:28:06 | [PATCH] Remove trailing period from errmsg in subscriptioncmds.c |
| Previous Message | Henson Choi | 2026-03-08 11:30:39 | Re: SQL Property Graph Queries (SQL/PGQ) |