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 1vMK9I-006jnz-08 for pgsql-hackers@arkaria.postgresql.org; Fri, 21 Nov 2025 05:57:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vMK9G-005qBP-20 for pgsql-hackers@arkaria.postgresql.org; Fri, 21 Nov 2025 05:57:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vMK9G-005qBG-0o for pgsql-hackers@lists.postgresql.org; Fri, 21 Nov 2025 05:57:34 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vMK9D-000fk6-2g; Fri, 21 Nov 2025 05:57:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=AXxMLpuzN1TASxkTujJXnN1Y6LGvpvOhjJHRrFo9x8o=; b=1juohnfO5LpFZUtL/F6XImQUvP Oz9GAqr6LewOmQQs6Xuxp4Cr4+eC4mpOus+ScpXOC+wJ4W2+jF7D18eTx0LdqidiaeusAs5I7TALT Z9mn7nJtjWLvHBFlRNnd7EjbQHcvalxXoXR21F7wdo8xqSUprZV610aWWBJ5bKv+QDmZg/bxTi0MB +qHaoW//jWM9PtsN09Rz+S3QXG+3NYqiFcR7UcwPpGG3TmIbTBtrXlS8j5gKSZf+JQXyGTKnFqK3H oAnrnarvIQnwItzckGA3x/S/ZGT3cxKTnVBsf3c9Xlfd9JFfuwa0gwCCm5VMvPdNe4/mUlQn4E998 M9XcgqMQ==; Received: from 221x241x223x178.ap221.ftth.ucom.ne.jp ([221.241.223.178] helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vMK94-001biv-3A; Fri, 21 Nov 2025 05:57:25 +0000 Date: Fri, 21 Nov 2025 14:57:08 +0900 (JST) Message-Id: <20251121.145708.931561343800399405.ishii@postgresql.org> To: li.evan.chao@gmail.com Cc: vik@postgresfriends.org, ishii@postgresql.org, david.g.johnston@gmail.com, jacob.champion@enterprisedb.com, er@xs4all.nl, peter@eisentraut.org, pgsql-hackers@postgresql.org Subject: Re: Row pattern recognition From: Tatsuo Ishii In-Reply-To: <66415FA2-B539-40C1-A58D-B28E373BDB26@gmail.com> References: <59fe567f-ba41-4cc2-b04a-a830288ea929@postgresfriends.org> <66415FA2-B539-40C1-A58D-B28E373BDB26@gmail.com> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Chao, >> On Nov 18, 2025, at 19:19, Vik Fearing wrote: >> >> >> Because of position. Without making DEFINE a reserved keyword, how do you know that it isn't another variable in the PATTERN clause? >> > > Ah, thanks for the clarification. Now I got it. > > I’m continue to review 0002. Thanks for the review! > 5 - 0002 - parse_clause.c > ``` > + ereport(ERROR, > + (errcode(ERRCODE_SYNTAX_ERROR), > + errmsg("FRAME must start at current row when row patttern recognition is used"))); > ``` > > Nit typo: patttern -> pattern Will fix (this involves regression test change because this changes the ERROR messages in the expected file). > 6 - 0002 - parse_clause.c > ``` > + /* DEFINE variable name initials */ > + static char *defineVariableInitials = "abcdefghijklmnopqrstuvwxyz”; > ``` > > This string can also be const, so “static const char *” Agreed. Will fix. > 7 - 0002 - parse_clause.c > ``` > + /* > + * Create list of row pattern DEFINE variable name's initial. We assign > + * [a-z] to them (up to 26 variable names are allowed). > + */ > + restargets = NIL; > + i = 0; > + initialLen = strlen(defineVariableInitials); > + > + foreach(lc, windef->rpCommonSyntax->rpDefs) > + { > + char initial[2]; > + > + restarget = (ResTarget *) lfirst(lc); > + name = restarget->name; > ``` > > Looks like “name” is not used inside “foreach”. Oops. Will fix. > 8 - 0002 - parse_clause.c > ``` > + /* > + * Create list of row pattern DEFINE variable name's initial. We assign > + * [a-z] to them (up to 26 variable names are allowed). > + */ > + restargets = NIL; > + i = 0; > + initialLen = strlen(defineVariableInitials); > + > + foreach(lc, windef->rpCommonSyntax->rpDefs) > + { > + char initial[2]; > ``` > > I guess this “foreach” for build initial list can be combined into the previous foreach loop of checking duplication. If an def has no dup, then assign an initial to it. You are right. Will change. > 9 - 0002 - parse_clause.c > ``` > +static void > +transformPatternClause(ParseState *pstate, WindowClause *wc, > + WindowDef *windef) > +{ > + ListCell *lc; > + > + /* > + * Row Pattern Common Syntax clause exists? > + */ > + if (windef->rpCommonSyntax == NULL) > + return; > ``` > > Checking (windef->rpCommonSyntax == NULL) seems a duplicate, because transformPatternClause() is only called by transformRPR(), and transformRPR() has done the check. Yeah. transformDefineClause() already does the similar check using Assert. What about using Assert in transPatternClause() as well? Assert(windef->rpCommonSyntax != NULL); Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp