Re: Row pattern recognition

From: Henson Choi <assam258(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Tatsuo Ishii <ishii(at)postgresql(dot)org>, 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-10-14 00:35:29
Message-ID: CAAAe_zCK32gsnnddJUXU1voBYCPTwiyksn894=Q0oTGwm0to+w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Jian,

Thank you for the three patches. I answer them in order.

0001 Use WindowAggState instead of WindowObject in rpr routines
0002 minor, using palloc0_array instead of palloc0

> Most of the row pattern code already works on WindowAggState, so
> refactoring makes the remaining rpr routines take WindowAggState
> instead of WindowObject as well. This looks more consistent.

I will take 0001 and 0002.

0003 Remove WindowAggState.nfaStateSize

> I always want to get rid of WindowAggState.nfaStateSize. It's ugly.

I would like to keep that field. The size depends only on the
pattern, so it is computed once, and I do not want to repeat the
same computation on a path this frequent just to save a field. To
me the field is the cleaner choice.

> nfa_state_clone->nfa_state_make is hot path, but
> ExecRPRStartContext->nfa_state_make is not.
>
> In nfa_state_clone->nfa_state_make:
> memset(state, 0, winstate->nfaStateSize)
> is waste cycle, because nfa_state_clone would unconditionally memcpy
> from (int32 *counts) later.

I agree with this part, and I will take it. I went one step
further. nfa_state_clone calls nfa_state_make, so I would
merge the two into one, nfa_state_make:

static RPRNFAState *nfa_state_make(WindowAggState *winstate,
const RPRNFAState *src);

When src is NULL, it makes a new state on element 0 with counts[]
cleared (ExecRPRStartContext). Otherwise it copies elemIdx,
isAbsorbable and counts[] from src as they are. Of the 7 callers,
only the ALT branch sets elemIdx and isAbsorbable itself afterwards;
the others get them from nfa_state_exit_to() or stay on the same
element.

When Tatsuo prepares the next patch, I will make a patch for this
change on top of it and share it. I will send the accumulated
patches slowly, over time.

Best regards,
Henson

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-10-14 00:35:58 Re: [PG19] psql backslash commands fail with translated messages and a non UTF-8 client encoding
Previous Message David Geier 2026-10-13 23:20:28 Re: use radix tree for bitmap heap scan