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 1vLDsj-008nS5-07 for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Nov 2025 05:03:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vLDsg-003yVD-1I for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Nov 2025 05:03:54 +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 1vLDsg-003yV3-08 for pgsql-hackers@lists.postgresql.org; Tue, 18 Nov 2025 05:03:54 +0000 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vLDsd-0007OQ-1N for pgsql-hackers@postgresql.org; Tue, 18 Nov 2025 05:03:53 +0000 Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-4b109c6b9fcso42876381cf.3 for ; Mon, 17 Nov 2025 21:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763442229; x=1764047029; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MRhbaXeLOa2wT6sDkHWvlTWrz5ShQxDmEOVzvlSk6g8=; b=JxN4o5m9uKlQ7N21w5hswU1MP6amOXmHGAKmr/r+VNetYNUs6V6ZwS1WA3JQDY9m9H Snqr6kqdGGgBNm7tFrXN9YnoPwgESzSFAauZkzzUT01yDiuAgsc41k/RWiuBmCYJDyTD l6pz3FuGj4DiWGAeOsz9OOgjykjFO9+zb2RL+SGrtJsyJfVF250rxGO64qEXCzk3lmkr Au2X0kQXHn8qTD7kjsgd0ujKVeWIwpMEXwgqGLNW41j8Tt/q1j1uhJBk8JQ+wPjyWPFY TUfOu7dHfX8x2inZh9v+7zalN0SN67boMHNeoMWCmw9TkvMogUx04xjZPFP12G9EChoS 1fyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763442229; x=1764047029; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MRhbaXeLOa2wT6sDkHWvlTWrz5ShQxDmEOVzvlSk6g8=; b=BggM/if3aqrAmRfii/TEBqWbo4N7HOeUrLavzoNnxQIyIc2jUyHggsCKjd2jtDCHj0 XknUX2d8O4tDOzYANa5BaBDASNcg0evFLiZaqxY0XM9RtV33Ci+QAGurzq5EeL0Gan5Z Lfqf2fRJgdEu3AE1ytn5aahznukTqjlyVUABvuoK9hHY3oAYIZAipliKHVQJIb0eo8Px /bwaxLtxOdgk3O+A/VL0uehqStK16QE5B7ed0NcPAycmdv8DoAsx2PE4XCjfU958MxJu qGNAwV8asoO59PN3meRijBNgH+s9cna8SbJzYvb/QovYaTNMyQ3Gvt2L3i2/Hxt2sC9V 6CDg== X-Forwarded-Encrypted: i=1; AJvYcCWogCr9Nm0DWzUo3JnZIl+XAlqrT1shNY6u3wJkfNSBRNscpWjyJ6SJjn5Qk0ytRaZ5V3jk11VvrCIk2m3I@postgresql.org X-Gm-Message-State: AOJu0YwwteESpzsoygnZJ4W56HcgrW6Ciy1rQSkPOqJVBhX0fbAZHsBq wpIqvojqJgKvPLUQOK5qDlibEDBqXRfmY7szSbELEV0CrsS5jMo4ZpDm X-Gm-Gg: ASbGncu+7EIFaoqNoaEGYgCICt49lwFJNJwb4oSq7R4fNxQNY8AfRQlu7Vby23CPKwv lSaPD9rBQiYp3raQ7ELDfaq3vInGR1c3COObo5+IiZCrWbRWuimrT8tAehaEC3KtoFU0RGKzehZ htzIxj2B32Dd2RyMlkDts3OKQsrDhLHtwsJVb1ZPouHrC6eFHZh1OIGxCogdRGxUzGPodFJeeeH JXxwnqFGmTb5a75qm/fvrymTa+RdlO/J9isOl7Rxz5j9ZHMoTE40UydhyPkviJrhJuArhGeSyEe uParZP7YmcHX8MNXsBAuMygi2uBrurQTekVD55nMYf4JKsDkifyuL08gm/dOzmwMrXZDsEx8q9e /EEYpXe6IqF3zIbTBzBUqPIDZrgCupCxffoG1k28LUB4ua/C0YlLNZSmBEd4tcEte1KVLjY0PTI 2hhWi/8nK5nYd4b2BI2MFY X-Google-Smtp-Source: AGHT+IHhqXiUWON/PzAHdKvnemNRNGNPvr2LdVvnKo1sO4pU8/wjoqVgJTOqtbmkI68jvJvW9ahYuw== X-Received: by 2002:a05:622a:55:b0:4ed:ca59:df7a with SMTP id d75a77b69052e-4edf2140628mr210658231cf.81.1763442228882; Mon, 17 Nov 2025 21:03:48 -0800 (PST) Received: from smtpclient.apple ([209.127.78.222]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4ede86b3820sm99668961cf.4.2025.11.17.21.03.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Nov 2025 21:03:48 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Row pattern recognition From: Chao Li In-Reply-To: <20251118.113320.572888636385647268.ishii@postgresql.org> Date: Tue, 18 Nov 2025 13:03:08 +0800 Cc: david.g.johnston@gmail.com, vik@postgresfriends.org, jacob.champion@enterprisedb.com, er@xs4all.nl, peter@eisentraut.org, pgsql-hackers@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20250816.174552.1094782787078410357.ishii@postgresql.org> <20250924.193523.694296225366690354.ishii@postgresql.org> <20251117.155715.178271279022552982.ishii@postgresql.org> <20251118.113320.572888636385647268.ishii@postgresql.org> To: Tatsuo Ishii X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Tatsuo-san, I just reviewed 0006 docs changes and 0001. I plan to slowly review the = patch, maybe one commit a day.=20 > On Nov 18, 2025, at 10:33, Tatsuo Ishii wrote: >=20 > Attached are the v35 patches for Row pattern recognition. In v34-0001 > gram.y patch, %type for RPR were misplaced. v35-0001 fixes this. Other > patches are not changed. >=20 > Best regards, > -- > Tatsuo Ishii > SRA OSS K.K. > English: http://www.sraoss.co.jp/index_en/ > Japanese:http://www.sraoss.co.jp > = I got a few comments, maybe just questions: 1 - 0001 - kwlist.h ``` +PG_KEYWORD("define", DEFINE, RESERVED_KEYWORD, BARE_LABEL) ``` Why do we add =E2=80=9Cdefine=E2=80=9D as a reserved keyword? =46rom the = SQL example you put in 0006: ``` SELECT company, tdate, price, first_value(price) OVER w, max(price) OVER w, count(price) OVER w FROM stock WINDOW w AS ( PARTITION BY company ORDER BY tdate ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING AFTER MATCH SKIP PAST LAST ROW INITIAL PATTERN (LOWPRICE UP+ DOWN+) DEFINE LOWPRICE AS price <=3D 100, UP AS price > PREV(price), DOWN AS price < PREV(price) ); ``` PARTITION is at the same level as DEFINE, but it=E2=80=99s not defined = as a reserved keyword: ``` PG_KEYWORD("partition", PARTITION, UNRESERVED_KEYWORD, BARE_LABEL) ``` Even in this patch,=E2=80=9Dinitial=E2=80=9D,=E2=80=9Dpast=E2=80=9D, = =E2=80=9Cpattern=E2=80=9D and =E2=80=9Cseek=E2=80=9D are defined as = unreserved, why? =20 So I just want to clarify. 2 - 0001 - gram.y ``` opt_row_pattern_initial_or_seek: INITIAL { $$ =3D true; } | SEEK { ereport(ERROR, = (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("SEEK is = not supported"), errhint("Use = INITIAL instead."), = parser_errposition(@1))); } | /*EMPTY*/ { $$ =3D true; } ; ``` As SEEK is specially listed here, I guess it might be supported in = future. If that is true, would it be better to defer the semantic check = to later parse phase, which would future work easier. 3 - 0001 - parsenodes.h ``` +/* + * RowPatternCommonSyntax - raw representation of row pattern common = syntax + * + */ +typedef struct RPCommonSyntax +{ + NodeTag type; + RPSkipTo rpSkipTo; /* Row Pattern AFTER = MATCH SKIP type */ + bool initial; /* true if is + * = initial */ + List *rpPatterns; /* PATTERN variables (list of = A_Expr) */ + List *rpDefs; /* row pattern = definitions clause (list of + * = ResTarget) */ +} RPCommonSyntax; + /* * WindowDef - raw representation of WINDOW and OVER clauses * @@ -593,6 +618,7 @@ typedef struct WindowDef char *refname; /* referenced window name, if = any */ List *partitionClause; /* PARTITION BY expression list = */ List *orderClause; /* ORDER BY (list of SortBy) */ + RPCommonSyntax *rpCommonSyntax; /* row pattern common syntax */ ``` RP fields are directly defined in WindowClause, then why do we need a = wrapper of RPCommonSyntax? Can we directly define RP fields in WindowRef = as well? Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/