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 1rwILR-000p6f-Ir for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2024 09:09:46 +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 1rwILQ-00BxwY-67 for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2024 09:09:44 +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 1rwILP-00BxuM-2O for pgsql-hackers@lists.postgresql.org; Mon, 15 Apr 2024 09:09:43 +0000 Received: from mail.clear-code.com ([153.126.206.245]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rwILL-002wNW-4u for pgsql-hackers@postgresql.org; Mon, 15 Apr 2024 09:09:41 +0000 Received: from localhost (unknown [IPv6:2404:7a80:89c1:1200:6af9:2266:1443:f149]) by mail.clear-code.com (Postfix) with ESMTPSA id 961EBD8157; Mon, 15 Apr 2024 18:09:31 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com 961EBD8157 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1713172172; bh=4HHq8+7JE72pZ7WdJYS3IlZzi59/FZApRNUXiImUw58=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=QOVLz/RQZMMnSWFvXS0cnO6giek/8VzE9tDbeO1fEdYLQCSYt7+tpoU/E+I2Z3jbY U3CYSXitRxogfhBC8d7vF6xm7Cl27IQj4LYvO911NPfnHgbW0JJAVUxBpcifBhs3zR onYfmTviwMfpa9m+CUjAgCq6Eokz8KrJuZIkJjtE= Date: Mon, 15 Apr 2024 18:09:29 +0900 (JST) Message-Id: <20240415.180929.517481101782400391.kou@clear-code.com> To: 9erthalion6@gmail.com Cc: yasuo.honda@gmail.com, tgl@sss.pgh.pa.us, smithpb2250@gmail.com, vignesh21@gmail.com, michael@paquier.xyz, nathandbossart@gmail.com, stark.cfm@gmail.com, geidav.pg@gmail.com, sk@zsrv.org, alvherre@alvh.no-ip.org, marcos@f10.com.br, robertmhaas@gmail.com, david@pgmasters.net, pgsql-hackers@postgresql.org, pavel.trukhanov@gmail.com Subject: Re: pg_stat_statements and "IN" conditions From: Sutou Kouhei In-Reply-To: <20240404143514.a26f7ttxrbdfc73a@erthalion.local> References: <20240326205916.aqxffqt7vgqjmnhm@erthalion.local> <20240404143514.a26f7ttxrbdfc73a@erthalion.local> X-Mailer: Mew version 6.8 on Emacs 29.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [2.90 / 999.00]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; RCVD_COUNT_ZERO(0.00)[0]; FREEMAIL_TO(0.00)[gmail.com]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_CC(0.00)[gmail.com,sss.pgh.pa.us,paquier.xyz,zsrv.org,alvh.no-ip.org,f10.com.br,pgmasters.net,postgresql.org]; RCPT_COUNT_TWELVE(0.00)[16]; FROM_HAS_DN(0.00)[]; TO_DN_NONE(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; SURBL_MULTI_FAIL(0.00)[localhost:server fail] X-Rspamd-Server: mail.clear-code.com X-Rspamd-Action: no action X-Rspamd-Queue-Id: 961EBD8157 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, In <20240404143514.a26f7ttxrbdfc73a@erthalion.local> "Re: pg_stat_statements and "IN" conditions" on Thu, 4 Apr 2024 16:35:14 +0200, Dmitry Dolgov <9erthalion6@gmail.com> wrote: > Here is the rebased version. Thanks. I'm not familiar with this code base but I've reviewed these patches because I'm interested in this feature too. 0001: > diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c > index be823a7f8fa..e9473def361 100644 > --- a/src/backend/nodes/queryjumblefuncs.c > +++ b/src/backend/nodes/queryjumblefuncs.c > > @@ -212,15 +233,67 @@ RecordConstLocation(JumbleState *jstate, int location) > ... > +static bool > +IsMergeableConstList(List *elements, Const **firstConst, Const **lastConst) > +{ > + ListCell *temp; > + Node *firstExpr = NULL; > + > + if (elements == NULL) "elements == NIL" will be better for List. > +static void > +_jumbleElements(JumbleState *jstate, List *elements) > +{ > + Const *first, *last; > + if(IsMergeableConstList(elements, &first, &last)) A space is missing between "if" and "(". > diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h > index aa727e722cc..cf4f900d4ed 100644 > --- a/src/include/nodes/primnodes.h > +++ b/src/include/nodes/primnodes.h > @@ -1333,7 +1333,7 @@ typedef struct ArrayExpr > /* common type of array elements */ > Oid element_typeid pg_node_attr(query_jumble_ignore); > /* the array elements or sub-arrays */ > - List *elements; > + List *elements pg_node_attr(query_jumble_merge); Should we also update the pg_node_attr() comment for query_jumble_merge in nodes.h? 0003: > diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c > index d7841b51cc9..00eec30feb1 100644 > --- a/contrib/pg_stat_statements/pg_stat_statements.c > +++ b/contrib/pg_stat_statements/pg_stat_statements.c > ... > @@ -2883,12 +2886,22 @@ generate_normalized_query(JumbleState *jstate, const char *query, > /* The firsts merged constant */ > else if (!skip) > { > + static const uint32 powers_of_ten[] = { > + 1, 10, 100, > + 1000, 10000, 100000, > + 1000000, 10000000, 100000000, > + 1000000000 > + }; > + int lower_merged = powers_of_ten[magnitude - 1]; > + int upper_merged = powers_of_ten[magnitude]; How about adding a reverse function of decimalLength32() to numutils.h and use it here? > - n_quer_loc += sprintf(norm_query + n_quer_loc, "..."); > + n_quer_loc += sprintf(norm_query + n_quer_loc, "... [%d-%d entries]", > + lower_merged, upper_merged - 1); Do we still have enough space in norm_query for this change? It seems that norm_query expects up to 10 additional bytes per jstate->clocations[i]. It seems that we can merge 0001, 0003 and 0004 to one patch. (Sorry. I haven't read all discussions yet. If we already discuss this, sorry for this noise.) Thanks, -- kou