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.94.2) (envelope-from ) id 1uyoJp-00D3YH-He for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Sep 2025 09:19:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uyoJl-005n6y-RH for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Sep 2025 09:19:14 +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.94.2) (envelope-from ) id 1uyoJl-005n6p-Bp for pgsql-hackers@lists.postgresql.org; Wed, 17 Sep 2025 09:19:14 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uyoJj-000sIS-1v for pgsql-hackers@lists.postgresql.org; Wed, 17 Sep 2025 09:19:13 +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=29aCjSH3HLH23n+MliJNMpVDhdxHy8vT18s2V4kYeTc=; b=mnhH5kGHaJ+35ruM8XNWFrzFNz ah5u7CQlSKi98gNVsTMchthoVtvLqrXtnQJmkx3aO7IP77o5U9tvOoSB+w1UiQtP9Uka6dLD09WEN 2Jcmij3GtrNBmMw1s2EuIBK0FX8L7KoQmJ0wm6lpTsaV3NW6a2ujsToUABVmLIdfwGLkoYOnEsAgu 3kdu3LzJ07UTKOZ475/XljqUyQVV+UnlHEw1syPFBxWPlNB/UzPYlBuw2DsgCK+1NM2aWzU0KzApF 1mOWFCnJE2rtsVEJGuhGS+xMU+8qx+As5p0VqTFmrz7RExbMgTvhDTiPVGzjJ80Qvs2gJgEH7gH0u dUweW3/A==; Received: from [2409:11:4120:300:9c46:85e3:548c:edd1] (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 1uyoJc-002aAH-29; Wed, 17 Sep 2025 09:19:07 +0000 Date: Wed, 17 Sep 2025 18:18:51 +0900 (JST) Message-Id: <20250917.181851.461494433278003071.ishii@postgresql.org> To: li.evan.chao@gmail.com Cc: ojford@gmail.com, krasiyan@gmail.com, tgl@sss.pgh.pa.us, vik@postgresfriends.org, andrew@tao11.riddles.org.uk, david@fetter.org, pgsql-hackers@lists.postgresql.org Subject: Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options From: Tatsuo Ishii In-Reply-To: <76F5962C-01AA-4D81-B9C2-70590746EC5C@gmail.com> References: <20250912.185316.492168971773927670.ishii@postgresql.org> <76F5962C-01AA-4D81-B9C2-70590746EC5C@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 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:9c46:85e3:548c:edd1 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Overall LGTM. Just a few small comments: > 1 - 0001 > ``` > --- a/src/backend/parser/parse_func.c > +++ b/src/backend/parser/parse_func.c > @@ -98,6 +98,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, > bool agg_star = (fn ? fn->agg_star : false); > bool agg_distinct = (fn ? fn->agg_distinct : false); > bool func_variadic = (fn ? fn->func_variadic : false); > + int ignore_nulls = (fn ? fn->ignore_nulls : 0); > ``` > > Should we use the constant NO_NULLTREATMENT here for 0? Good suggestion. Will fix. > 2 - 0001 > ``` > --- a/src/include/nodes/primnodes.h > +++ b/src/include/nodes/primnodes.h > @@ -579,6 +579,17 @@ typedef struct GroupingFunc > * Collation information is irrelevant for the query jumbling, as is the > * internal state information of the node like "winstar" and "winagg". > */ > + > +/* > + * Null Treatment options. If specified, initially set to PARSER_IGNORE_NULLS > + * which is then converted to IGNORE_NULLS if the window function allows the > + * null treatment clause. > + */ > +#define NO_NULLTREATMENT 0 > +#define PARSER_IGNORE_NULLS 1 > +#define PARSER_RESPECT_NULLS 2 > +#define IGNORE_NULLS 3 > + > typedef struct WindowFunc > { > Expr xpr; > @@ -602,6 +613,8 @@ typedef struct WindowFunc > bool winstar pg_node_attr(query_jumble_ignore); > /* is function a simple aggregate? */ > bool winagg pg_node_attr(query_jumble_ignore); > + /* ignore nulls. One of the Null Treatment options */ > + int ignore_nulls; > ``` > > Maybe we can use “uint8” type for “ignore_nulls”. Because the previous two are both of type “bool”, an uint8 will just fit to the padding bytes, so that new field won’t add extra memory to the structure. If we change the data type for ignore_nulls in WindowFunc, we may also want to change it elsewhere (FuncCall, WindowObjectData, WindowStatePerFuncData) for consistency? > 3 - 0004 > ``` > winobj->markpos = -1; > winobj->seekpos = -1; > + > + /* reset null map */ > + if (perfuncstate->winobj->ignore_nulls == IGNORE_NULLS) > + memset(perfuncstate->winobj->notnull_info, 0, > + NN_POS_TO_BYTES(perfuncstate->winobj->num_notnull_info)); > } > ``` > Where in “if” and “memset()”, we can just use “winobj”. Good catch. Will fix. > 4 - 0004 > ``` > + if (!HeapTupleIsValid(proctup)) > + elog(ERROR, "cache lookup failed for function %u", funcid); > + procform = (Form_pg_proc) GETSTRUCT(proctup); > + elog(ERROR, "function %s does not allow RESPECT/IGNORE NULLS", > + NameStr(procform->proname)); > ``` > > “Procform” is assigned but not used. I think procform is used in the following elog(ERROR, ...). Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp