Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pMRZn-0004lD-RV for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Jan 2023 10:39:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pMRZm-0000Ed-Dp for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Jan 2023 10:39:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pMRZk-0000DU-O6 for pgsql-hackers@lists.postgresql.org; Mon, 30 Jan 2023 10:39:50 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pMRZd-0000Er-GS for pgsql-hackers@lists.postgresql.org; Mon, 30 Jan 2023 10:39:47 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 19FD63200906; Mon, 30 Jan 2023 05:39:38 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 30 Jan 2023 05:39:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1675075177; x=1675161577; bh=fCPbr/OeFr dbAyQg3+eW2FqefRmZK9O+Lw2EV+zzFFo=; b=obTLYpTAiTfrFcPqPqtG0t8SgP QeUWul3tFOAdRMWOT4HwWonZ64HIK8TSs3qfMfr9AwuQy/3d8w2QwlyKl+X2xLwg gVZ8N6PxnGaM5gZjOnWkrk9niTnsI7AF3jVk2khLpJq20uRvMwqLCcwRIwHBUm6p POv0FYsdSAGl2I+pBkyLqYLLL6N9C/wxBsfxd4+Gtkl177bDiAeFuQUqS/SxcBd3 rMkQ/1YcfXINml1coEC190+VZfMYgH9SsayaPQ/NROKuzmqA7XhoBsprXOnLxtEw /4VonhREooAdpx6i40egEiY/8FoLBRlsGjLyR1lZZvnts+PyKOkDXjJhZLFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1675075177; x=1675161577; bh=fCPbr/OeFrdbAyQg3+eW2FqefRmZ K9O+Lw2EV+zzFFo=; b=hNcwVvZ2jJXVdppNbLnpIXet3o6m5Hw84CSgVLrsSCGq mCmjNkzJgY6Rhv4yAOZ7c+/SOnigo/inbPlsmsDHTHxlmp36Y+HgDzO7w/TZ+Ege voiBHkTRNNVfMcnYkWY7hTu6aMx8FkVU6414tYAYMRLY5/pO8snCp8tJ7pKQ1Lqa hFMB3eVnq+BCfUy6PG0s4LAMa4UUtAVpZkVVQszgEXiSnXFSVYyPpzaX1TqLq/QA S9DtZ3454Ytz+usDzDWc+NjcAWdIayvi9w54qR8kWYmZPcfLi9c6XxrEzEymrHWW 55Hy5butmsPQOV99+Z6F+ltlhz580t+Ug5ejnLXxeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudefvddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Jan 2023 05:39:36 -0500 (EST) Date: Mon, 30 Jan 2023 19:39:30 +0900 From: Michael Paquier To: Peter Eisentraut Cc: Postgres hackers , "Drouvot, Bertrand" Subject: Re: Generating code for query jumbling through gen_node_support.pl Message-ID: References: <50b571dc-e0c0-22be-9803-4a3480d2e792@enterprisedb.com> <9695f035-0f2b-92b9-deed-0b7e5bb7e4e0@enterprisedb.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="BKbBZesdNrR/+239" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --BKbBZesdNrR/+239 Content-Type: multipart/mixed; boundary="lKZ79HeW445Ixrn/" Content-Disposition: inline --lKZ79HeW445Ixrn/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 27, 2023 at 11:59:47AM +0900, Michael Paquier wrote: > Using that, I can compile the following results for various cases (-O2 > and compute_query_id=3Don): > query | mode | iterations | avg_runtime_ns | avg_jum= ble_ns=20 > -------------------------+--------+------------+----------------+--------= ------- > begin | string | 50000000 | 4.53116 | = 4.54 > begin | jumble | 50000000 | 30.94578 | = 30.94 > commit | string | 50000000 | 4.76004 | = 4.74 > commit | jumble | 50000000 | 31.4791 | = 31.48 > create table 1 column | string | 50000000 | 7.22836 | = 7.08 > create table 1 column | jumble | 50000000 | 152.10852 | = 151.96 > create table 5 columns | string | 50000000 | 12.43412 | = 12.28 > create table 5 columns | jumble | 50000000 | 352.88976 | = 349.1 > create table 20 columns | string | 5000000 | 49.591 | = 48.2 > create table 20 columns | jumble | 5000000 | 2272.4066 | = 2271 > drop table 1 column | string | 50000000 | 6.70538 | = 6.56 > drop table 1 column | jumble | 50000000 | 50.38 | = 50.24 > drop table 5 columns | string | 50000000 | 6.88256 | = 6.74 > drop table 5 columns | jumble | 50000000 | 50.02898 | = 49.9 > SET work_mem | string | 50000000 | 7.28752 | = 7.28 > SET work_mem | jumble | 50000000 | 91.66588 | = 91.64 > (16 rows) Just to close the loop here, I have done more measurements to compare the jumble done for some DMLs and some SELECTs between HEAD and the patch (forgot to post some last Friday). Both methods show comparable results: query | mode | iterations | avg_runtime_ns | avg_jumble_n= s=20 ----------------------+--------+------------+----------------+-------------= -- insert table 10 cols | master | 50000000 | 377.17878 | 377.04 insert table 10 cols | jumble | 50000000 | 409.47924 | 409.34 insert table 20 cols | master | 50000000 | 692.94924 | 692.8 insert table 20 cols | jumble | 50000000 | 710.0901 | 709.96 insert table 5 cols | master | 50000000 | 232.44308 | 232.3 insert table 5 cols | jumble | 50000000 | 253.49854 | 253.36 select 10 cols | master | 50000000 | 449.13608 | 383.36 select 10 cols | jumble | 50000000 | 491.61912 | 323.86 select 5 cols | master | 50000000 | 277.477 | 277.46 select 5 cols | jumble | 50000000 | 323.88152 | 323.86 (10 rows) The averages are in ns, so the difference does not bother me much. There may be some noise mixed in that ;) (Attached is the tweak I have applied on HEAD to get some numbers.) -- Michael --lKZ79HeW445Ixrn/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="jumble-benchmark.txt" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/query= jumblefuncs.c index 16084842a3..c66090bde3 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -101,10 +101,14 @@ CleanQuerytext(const char *query, int *location, int = *len) JumbleState * JumbleQuery(Query *query, const char *querytext) { +#define MAX_QUERY_COMPUTE 50000000 + JumbleState *jstate =3D NULL; =20 Assert(IsQueryIdEnabled()); =20 + elog(WARNING, "start JumbleQuery"); + if (query->utilityStmt) { query->queryId =3D compute_utility_query_id(querytext, @@ -114,18 +118,26 @@ JumbleQuery(Query *query, const char *querytext) else { jstate =3D (JumbleState *) palloc(sizeof(JumbleState)); - - /* Set up workspace for query jumbling */ jstate->jumble =3D (unsigned char *) palloc(JUMBLE_SIZE); - jstate->jumble_len =3D 0; jstate->clocations_buf_size =3D 32; jstate->clocations =3D (LocationLen *) palloc(jstate->clocations_buf_size * sizeof(LocationLen)); - jstate->clocations_count =3D 0; - jstate->highest_extern_param_id =3D 0; =20 - /* Compute query ID and mark the Query node with it */ - JumbleQueryInternal(jstate, query); + for (int i =3D 0; i < MAX_QUERY_COMPUTE ; i++) + { + /* Set up workspace for query jumbling */ + memset(jstate->jumble, 0, sizeof(JUMBLE_SIZE)); + jstate->jumble_len =3D 0; + jstate->clocations_buf_size =3D 32; + memset(jstate->clocations, 0, + jstate->clocations_buf_size * sizeof(LocationLen)); + + jstate->clocations_count =3D 0; + jstate->highest_extern_param_id =3D 0; + + /* Compute query ID and mark the Query node with it */ + JumbleQueryInternal(jstate, query); + } query->queryId =3D DatumGetUInt64(hash_any_extended(jstate->jumble, jstate->jumble_len, 0)); @@ -138,6 +150,8 @@ JumbleQuery(Query *query, const char *querytext) query->queryId =3D UINT64CONST(1); } =20 + elog(WARNING, "end JumbleQuery"); + return jstate; } =20 --lKZ79HeW445Ixrn/-- --BKbBZesdNrR/+239 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmPXnmIACgkQnvQgOdby QH2GJw//YfJu43ciJanRIyaQkSSC2PWNbAXYc9HGNWeFcjbG/hqDbnODhXyQHZws PyWVwy/uv2xQE+fS8Q2q12AMj1ZcatOEGd8RzLyAGGYPzBdhQdj8AMrpAoBhGJIZ dQYa1ESxFbLPUoLaUVfq6Nq5QQZ1ktrYSAbKdbPRQyQrkcd4K4AZ0OhIUrOzwmAz rt45mdta4aPfJjXeym8A1NtEFrLI54pQRSPW2Zg7aNz5RaLY8tAu+dTbBLxZuYzJ wdw37I8OF1A/cssCrMvrXpxk6TOldCtu1THCRWLRd90Y0ntHoFV2VoETU/OVe+Is vIogyG8lW+Nq5ZQTJmFNRmAYebOMjin+AXsswJR2GN8v3578x/N5PrT4ETHkKUBu mxaU6IhWXADpRVcl30Mo+zPT7RBjn+Q+SjHjinKGBOujgNfa091i0kpTEfGhoACz bnLHDeTX7off72Gn6cBl01BLrgOjHUdZMcDqdues69VsfhzhDZmpXGbuUN2fRC0X rVMKRgOVgmdbwTkHnYiwksWuteFdxlKNo2sI7OWgMqQxV2ZeojG4OvGPruO5J6D8 V/EShntUXjBp0Ixie5LJ55Ga5QvxHycs0M1/0zTXJpHho6cinNhfYcs+ZEkAZe0B LXoJvDvXC8pwet3mL9IH2rRzOVj3cBUa/9ZHAhbe0e4IooSya/U= =NIDv -----END PGP SIGNATURE----- --BKbBZesdNrR/+239--