Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUXNg-001EZV-2k for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jun 2026 22:14:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUXNf-00GB7U-2h for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jun 2026 22:14:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUXNf-00GB7L-1L for pgsql-hackers@lists.postgresql.org; Tue, 02 Jun 2026 22:14:39 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUXNd-00000000oXw-33x4 for pgsql-hackers@postgresql.org; Tue, 02 Jun 2026 22:14:38 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-68bd167797dso6700304a12.0 for ; Tue, 02 Jun 2026 15:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780438475; cv=none; d=google.com; s=arc-20240605; b=i0ZbH76QrGjZL3Lf41zH/IQaBIqLECCh4PwH5hWuuyq3x059iy+LdNp9intvB5DfaV iLVU2UMrQr71wNyMrtvfaXeDWJd52GRlmVpwqZ15hSX/qF8sBt6ghHedimh28CVxrKta I9pPc2jdPuFyw38yFflu5p80k58H5X+utP/exU3M7/4TDfDQ5Bvx2nH3UfRxqJPBA2gV ZLLQZa/QLA4VAgkxIEfqKzCzQTAEcmeSVS+CQm+fx/tE/QmJZbYFwgwNhIQVbU7jnMgj bFtiMDn2mBRYulqoyZEu94yzzSAjufUgkX0oHuclMmx/BLpKkxuGZJk7Dfa0yeQq0/kc Bwkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:dkim-signature; bh=PGGzcXKyVhvMLO0NehG2hV50lDN1juqNJcPLXOBWI34=; fh=TBJY+mXHFWd6EbbERWAMFDEKNntJRFo+ScIiVrCTe/A=; b=GV1xKg6as+3dccCKRBmjgjIO6R5+CNYgk7z5ypA66juYJ8THf0WuzPFpkMvQB1DOkK 8KSv7rYLC9Ypo2PBIOCqgKEnVf4hi+B6UjEMRziVVULNmlw9VqY8Ql/+yCtFdKexVet4 DetbcGN1ZexZHhx7W5cbHsq0XCwey7Lv7KMXZjF+txiJsvG/fI8e+4IO7BM/vKBksoBq TFSWh4343P+nH22yC3G9JBcTgjIpBvzb78tqygUEphVtK5/fIzpCDYYYEiL5UMtglwD7 XieVoP/0F75F1W1Y1HVgq1qeNPuCrO1t6EJ81ytdnpw5rREM1QqS1PRRqRRS2Xh3DIQL QBYg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780438475; x=1781043275; darn=postgresql.org; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PGGzcXKyVhvMLO0NehG2hV50lDN1juqNJcPLXOBWI34=; b=X/HiQ89/vJe1vu1XcE+ytuzu8E7RMxVm9E0TjbDFhBIvz8kWR4lWssCM6subeAg4E2 DD/FZzOG9sWf6YGDwygemkJzaApOxoa68S/PcdH0xzuHTtYv5YQc2bnsl3WgI6uH2nnm CKw5dsmSsAwwyPEYrJxLlaisvknDyQyEdt8yA1MkU0odkeQiBOriMV1M049eWAWk15ix MhXICcnKThf+R9UTGaJWJc9yE1kYaRE7ov6DpLkPX2ZStJt87oCEp66o8YsyvetIcgEJ 16iBSx0YpWZh+hUVnlrr6OjOzyBBZZV5d8iToXA91T93a8IdWMJi6TfAwsKel63X5Be0 BQ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780438475; x=1781043275; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PGGzcXKyVhvMLO0NehG2hV50lDN1juqNJcPLXOBWI34=; b=YQDIs1kgrhgG7qy477nH7CU4hoDecMBV4Jw3asUPB/PgsrZs4Oep9K9AY8sFRZ0aDu 2oysXax9dOrgvACXuoMY3OjN+FCQZsJuWzAf6pTZYBKEAvDS+5muEEaHjuoRQbI9eFYM IEO8W+qdpkcVNqlE8j7IPN3LWG3vgR9b7sKEszGg1+NDJiZFDWVUe/oZc08R4l235FAg WEkk4RFgaYrZYu/iJRkctbmItRSOcXdzL43ZuaX88ihFxyI9jozBv51nb3HmQlUIVhHI V8G98TsUQ4sQryzlvb+Kfuwo5BDdl2chEg0jTZZfmMoeDrt8sVtZ/xRRLlHWpoSRAXvr UahQ== X-Forwarded-Encrypted: i=1; AFNElJ+mE/UC+gusvLfDlZ/4ZRSp6SDq5wksfOn535tCM8oq1EaqawJKYdO4O35VUNyBPnbV6jxkra/5V78tt3uZ@postgresql.org X-Gm-Message-State: AOJu0YxgaSBoAu627uDE9I0R62+vVH4XxFpnPuM60sxAryntP/e/x4KC gOPWs4sL0RL2GtxUV4cJTbcfBNXgNuvQ/vJa6mqeAD8ddf4k6AuEHxYoT7+j/g747pMe/mkGYxD 4J+BjSPAbr+yQszL4aSRuh7wMPa6soFI= X-Gm-Gg: Acq92OEJ86zV2OGZvWvGcaK+Ibb3+uU6lFAzxKjZsqEFn/7lJ/qfn6ytuIjkGKUIUNO nJsmMnK8Q53KzU+tUxkr8OixZB5EVdsZFARHS2hQ/EVlxDfvAsurf0nSXafQ0/pocibRdghKQw8 ddRPunWK8nzmV/0xHjC2kgV4dLf0MTqjyZ+d13XZ+eeVTXdXf3vrN0wHYhGGJDoo1bozcsBa1nV 4kIqCH+kUNbQI00o6LLRZTR0y4uviddzTeKTNBaUyVqoH6OIyUA9y60YssN3TnLL+2M1Q9Plgah Cz9tK5O2MunC8k49yZlREcaxqEwyXYaMqL2UdIV19M37FvGw87M= X-Received: by 2002:a17:907:6d07:b0:bec:228e:26e5 with SMTP id a640c23a62f3a-bf0ac50c0f8mr15122066b.7.1780438474634; Tue, 02 Jun 2026 15:14:34 -0700 (PDT) MIME-Version: 1.0 References: <20260601.111119.1029884790276077667.ishii@postgresql.org> <20260601.114703.1561993497414705173.ishii@postgresql.org> In-Reply-To: Reply-To: assam258@gmail.com From: Henson Choi Date: Wed, 3 Jun 2026 07:14:21 +0900 X-Gm-Features: AVHnY4ItPp9MaHD8Zi6WGMtcHritjg5XHMsRXKbNXeQGiyOIQgtRr2zl6LsSIzA Message-ID: Subject: Re: Row pattern recognition To: jian he Cc: Tatsuo Ishii , zsolt.parragi@percona.com, sjjang112233@gmail.com, vik@postgresfriends.org, er@xs4all.nl, jacob.champion@enterprisedb.com, david.g.johnston@gmail.com, peter@eisentraut.org, li.evan.chao@gmail.com, pgsql-hackers@postgresql.org Content-Type: multipart/alternative; boundary="000000000000d338e506534ca2c0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d338e506534ca2c0 Content-Type: text/plain; charset="UTF-8" Subject: Re: Row pattern recognition Hi Jian, > 3. > 240 variables is enough, as each variable supports multiple complex > AND/OR conditions. [...] reserving the remaining ones in advance is a > future-proof approach. Thanks -- that's (3), and Tatsuo landed on the same choice, so it's settled. I'll make the change for v48. > XII-4. Memory Pool Management > Choice: Custom free list [...] > It would be better simply to mention that: > RPRNFAState and RPRNFAContext are allocated in a partition-lifespan > memory context; they will be destroyed in release_partition. Agreed -- that's clearer than the rationale list. I'll replace XII-4 with that wording. > If ctx->matchedState points to one of the states already in ctx->states, > will nfa_state_free() be called on the same RPRNFAState twice? Is this > double-free permitted, or do we have a mechanism in place to guard > against it? No -- they're disjoint by construction, so the two frees never touch the same state. Step by step: - nfa_advance() detaches ctx->states up front (sets it to NULL) and rebuilds the list from scratch. - Each old state is pulled off and advanced; the one that reaches FIN is moved into matchedState and never re-added to ctx->states. - So at any moment a state is either on ctx->states or it is matchedState, never both. - ExecRPRFreeContext frees the list and frees matchedState -- disjoint sets, no overlap, so no guard is needed. - (When a new FIN replaces matchedState, the previous one is freed right there.) > if (currentPos == ctxFrameEnd) { > nfa_match(winstate, ctx, NULL); > continue; > } > If I comment out the CONTINUE, the entire regression still succeeds. It isn't dead -- it's the N-FOLLOWING boundary handler. nfa_match(ctx, NULL) forces a mismatch that finalizes the context on its matchedState, and the continue skips the rest since it's done for this row. Without the continue, that finalized context is matched a second time in the same row -- a context-matched-twice error. It only looks harmless because the forced mismatch already emptied ctx->states, so the second nfa_match iterates nothing (and it would also re-run nfa_reevaluate_dependent_vars(), overwriting the shared nfaVarMatched the other contexts read). So I'd keep it: a finalized context must not be matched twice in the same row. Thanks, Henson --000000000000d338e506534ca2c0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Subject: Re: Row pattern recognition

Hi Jian,
> 3.
> 240 variables is enough, as each variable supports multip= le complex
> AND/OR conditions. [...] reserving the remaining ones in= advance is a
> future-proof approach.

Thanks -- that's (3= ), and Tatsuo landed on the same choice, so it's
settled. I'll m= ake the change for v48.

> XII-4. Memory Pool Management
> = =C2=A0 Choice: Custom free list [...]
> It would be better simply to = mention that:
> RPRNFAState and RPRNFAContext are allocated in a part= ition-lifespan
> memory context; they will be destroyed in release_pa= rtition.

Agreed -- that's clearer than the rationale list. I'= ;ll replace XII-4 with
that wording.

> If ctx->matchedState= points to one of the states already in ctx->states,
> will nfa_st= ate_free() be called on the same RPRNFAState twice? Is this
> double-= free permitted, or do we have a mechanism in place to guard
> against= it?

No -- they're disjoint by construction, so the two frees ne= ver touch the
same state. Step by step:

=C2=A0 - nfa_advance() de= taches ctx->states up front (sets it to NULL) and
=C2=A0 =C2=A0 rebui= lds the list from scratch.
=C2=A0 - Each old state is pulled off and adv= anced; the one that reaches FIN is
=C2=A0 =C2=A0 moved into matchedState= and never re-added to ctx->states.
=C2=A0 - So at any moment a state= is either on ctx->states or it is
=C2=A0 =C2=A0 matchedState, never = both.
=C2=A0 - ExecRPRFreeContext frees the list and frees matchedState = -- disjoint
=C2=A0 =C2=A0 sets, no overlap, so no guard is needed.
= =C2=A0 - (When a new FIN replaces matchedState, the previous one is freed r= ight
=C2=A0 =C2=A0 there.)

> if (currentPos =3D=3D ctxFrameEnd= ) {
> =C2=A0 =C2=A0 nfa_match(winstate, ctx, NULL);
> =C2=A0 = =C2=A0 continue;
> }
> If I comment out the CONTINUE, the entir= e regression still succeeds.

It isn't dead -- it's the N-FOL= LOWING boundary handler. nfa_match(ctx,
NULL) forces a mismatch that fin= alizes the context on its matchedState,
and the continue skips the rest = since it's done for this row.

Without the continue, that finaliz= ed context is matched a second time in
the same row -- a context-matched= -twice error. It only looks harmless
because the forced mismatch already= emptied ctx->states, so the second
nfa_match iterates nothing (and i= t would also re-run
nfa_reevaluate_dependent_vars(), overwriting the sha= red nfaVarMatched the
other contexts read). So I'd keep it: a finali= zed context must not be
matched twice in the same row.

Thanks,Henson
--000000000000d338e506534ca2c0--