| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
| Cc: | assam258(at)gmail(dot)com, zsolt(dot)parragi(at)percona(dot)com, 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, li(dot)evan(dot)chao(at)gmail(dot)com, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: Row pattern recognition |
| Date: | 2026-08-19 07:34:55 |
| Message-ID: | CACJufxEFwed7MwSVgPG-tYjo2WN_QF=kd3QnqAJePaScx+otVw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi.
Please check the attached refactoring for nodeWindowAgg.c and execRPR.c.
It's based on https://github.com/assam258-5892/postgres/commits/RPR.
What is being changes:
1. ExecRPRFreeContext: we should also reset other field values.
2. nfa_update_absorption_flags() now takes the WindowAggState and walks
the context list itself. This is more intuitive, I think.
I did the similar thing for nfa_absorb_contexts.
3. Remove some duplicated Asserts; preceding callers have already done
the equivalent Asserts.
4. Some local variable, used only once, should be just removed.
5. Add some elog(ERROR) to avoid circular winstate->nfaContext,
RPRNFAContext->states.
6. Only ExecRPRProcessRow uses the variable frameOffset, refactor to
make it as a local variable.
7. ExecRPRStartContext->nfa_context_make. nfa_context_make() used to return a
bare struct, leaving the initial state, matchStartRow, and active-list linkage
for the caller to fill in, that is not intuitive, it looks like a half-built
context. Have nfa_context_make() return a fully-formed one: allocate the
initial state, set the start row, and append it to the list tail.
8. ExecRPRGetHeadContext(pos) external function can be removed.
9. Refactoring update_reduced_frame. Now update_reduced_frame code
flow is more intuitive: look up or
create the context for pos, drive the NFA forward with
advance_reduced_frame_nfa(), then record the match result.
10. Restructure get_reduced_frame_status as a single decision tree: first
"no record" (start < 0), then "the record's own row" (pos == start),
where length alone gives the verdict (-1 unmatched, 0 empty match,
>= 1 frame head), then the range test for everything else.
Summary: The code flow in update_reduced_frame, advance_reduced_frame_nfa, and
get_reduced_frame_status is now much more intuitive. Using elog(ERROR) prevents
us from getting stuck in an infinite loop if something goes wrong.
See the commit message also.
| Attachment | Content-Type | Size |
|---|---|---|
| v51-0001-refactor-nodeWindowAgg.c-and-execRPR.c.nocfbot | application/octet-stream | 32.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Haibo Yan | 2026-08-19 07:24:42 | Re: Fix CPU cost of right-semi and right-anti hash joins |