Re: Row pattern recognition

Tatsuo Ishii <ishii@postgresql.org>

From: Tatsuo Ishii <ishii@postgresql.org>
To: assam258@gmail.com
Cc: jacob.champion@enterprisedb.com, david.g.johnston@gmail.com, vik@postgresfriends.org, er@xs4all.nl, peter@eisentraut.org, pgsql-hackers@postgresql.org
Date: 2026-01-16T04:44:22Z
Lists: pgsql-hackers

Attachments

Hi Henson,

> Hi Ishii-san,
> 
> Thank you for raising the frame boundary concern. You're right that
> different contexts have different frame boundaries.

Ok.

> Your suggestion was to use row_is_in_frame() to check frame boundaries
> for each row. However, I took a simpler approach: just disable context
> absorption entirely when the frame is limited.
> 
> The root cause is that context absorption assumes all contexts see
> the same rows. With limited frames, each context starting at a different
> row has a different visible range, so we cannot absorb one context into
> another.
> 
> As I mentioned before, I think we should use absorption conservatively
> for now - only in cases where it's clearly safe (e.g., A* at the
> beginning of the pattern). We can extend it later through more in-depth
> research.

Agreed.

> The fix:
> 
>     if (winstate->rpSkipTo == ST_PAST_LAST_ROW && !hasLimitedFrame)
>         nfa_absorb_contexts(winstate, targetCtx, currentPos);
> 
> I added a test case to verify this:
[snip]
> I'm attaching three related commits:
> 
> 1. Row pattern recognition: Improve NFA state memory management
> 
>    This commit refactors NFA state management for better readability
>    and maintainability.
> 
> 2. Row pattern recognition: Disable context absorption for limited frame
> 
>    This commit further restricts absorption: even with SKIP PAST LAST ROW,
>    absorption is disabled when the frame is limited. With limited frames,
>    different contexts have different frame boundaries, making absorption
>    unsafe.

I have applied the patches on top of v38 to create v39 patches.
In addition to these patches, I have made following changes:

- Add check for frame option "EXCLUDE". With RPR, using EXCLUDE is not
  permitted by the SQL standard. A test case added.

- Remove unused typedef from windowfuncs.c (which causes removal of the
  typedef from typedes.list). The typedef was accidentally left by me
  while developing RPR.

- Update the Copyright year to 2026 in some newly added files.

Best regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Adjust cross-version upgrade tests for seg_out() fix

  2. Rationalize error comments in partition split/merge tests

  3. Add fast path for foreign key constraint checks

  4. Fix assorted pretty-trivial memory leaks in the backend.

  5. Add temporal FOREIGN KEY contraints

  6. Add trailing commas to enum definitions

  7. Remove obsolete executor cleanup code