Re: Row pattern recognition
Henson Choi <assam258@gmail.com>
From: Henson Choi <assam258@gmail.com>
To: Tatsuo Ishii <ishii@postgresql.org>
Cc: ssam258@gmail.com, vik@postgresfriends.org, er@xs4all.nl, jacob.champion@enterprisedb.com, david.g.johnston@gmail.com, peter@eisentraut.org, pgsql-hackers@postgresql.org
Date: 2026-02-12T12:04:52Z
Lists: pgsql-hackers
Hi Tatsuo,
Thank you for the detailed analysis and references to the standard.
However in my uderstanding the SQL standard allows A{0}.
>
> PATTERN (A{0} B)
> is equivalant to:
> PATTERN (B)
>
I agree. We should support A{0} to comply with the standard.
> BTW, after studied this more, I found that A{0,0} is not allowed. In
> this form the right hand side number shall be greater than 0. From
> ISO/IEC 9075-2 7.9 <row pattern syntax> "Syntax Rules 20)
>
> "If <left brace> <unsigned integer> <comma> <unsigned integer> <right
> brace> is specified, then let VUI1 and VUI2 be the values of the first
> and second <unsigned integer>'s, respectively. VUI1 shall be less than
> or equal to VUI2, and VUI2 shall be greater than 0 (zero)."
>
Good catch. I agree we should follow the standard strictly. Since I
don't have direct access to the ISO/IEC 9075-2 document, I trust your
interpretation that A{0,0} should be rejected per SR 20.
However, this raises interesting questions: should we optimize patterns
by removing {0} quantifiers or simplifying them? And if so, how should
we handle patterns that become empty after such optimization?
For example:
- PATTERN (A{0}) → empty pattern
- PATTERN (A{0} B{0}) → empty pattern
- PATTERN (A{0} B) → PATTERN (B) after optimization
Empty patterns would result in zero-length matches, which our current
implementation explicitly treats as invalid (see initialAdvance flag
logic in nodeWindowAgg.c).
More importantly, I recall that zero-length matches caused serious
issues during development, which is why we added logic to explicitly
avoid them.
The reason I cannot immediately provide a concrete plan for A{0}
support is that I need to deeply understand the semantic meaning of
zero-length matches in the SQL standard first. Without this
understanding, any implementation approach could be fundamentally
flawed.
Specifically, I need to investigate:
- What zero-length matches mean semantically in RPR
- How to handle empty patterns according to the standard
- The correct behavior when a pattern optimizes to nothing
After the current code review phase is complete, I'm also considering
setting up an Oracle test environment to observe how it handles these
edge cases. This could provide valuable insights into the expected
behavior, especially for zero-length matches and empty patterns.
Do you have insights on how the standard handles empty patterns or
zero-length matches?
Best regards,
Henson
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Adjust cross-version upgrade tests for seg_out() fix
- 3e3d7875e956 19 (unreleased) cited
-
Rationalize error comments in partition split/merge tests
- ecb2508aaf9b 19 (unreleased) cited
-
Add fast path for foreign key constraint checks
- 2da86c1ef9b5 19 (unreleased) cited
-
Fix assorted pretty-trivial memory leaks in the backend.
- e78d1d6d47dc 19 (unreleased) cited
-
Add temporal FOREIGN KEY contraints
- 89f908a6d0ac 18.0 cited
-
Add trailing commas to enum definitions
- 611806cd726f 17.0 cited
-
Remove obsolete executor cleanup code
- d060e921ea5a 17.0 cited