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 1rNbYQ-00Dky1-Ub for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2024 16:35:48 +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 1rNbYQ-005l3z-0v for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2024 16:35:46 +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 1rNbYP-005l3r-Lo for pgsql-hackers@lists.postgresql.org; Wed, 10 Jan 2024 16:35:45 +0000 Received: from dd26416.kasserver.com ([85.13.145.105]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNbYM-000rs0-9N for pgsql-hackers@lists.postgresql.org; Wed, 10 Jan 2024 16:35:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oopsware.de; s=kas202309091111; t=1704904539; bh=Z+/kehpqNwxSavHhJ0vaqQLD47xXlUcQLjH6hDJj/Hw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ea5gEs46/aTPTzMlTJhhdQeaMVF1NQMTntgk3aKZvgMmWCH8XHR7Tv3FQiP0VDpu7 PiJq0ySXFL+WfzajfSQjNhXeYkC3BXmS/CZaNLikTD8n+NJ4tfq/iieGeaM07UmuNJ fo9r/tjiaMhANlvySoWx7Z4YiaS7gEL/P+atuZ98w8JGdHGaYfVjC8ztPJC/zZ6vYo jaG2YSooAg/+ksTCSbXj1upFU8ensw5t11MwMtaXfmpzC6KMjBdmTIXrNdzGM3B3e2 4WBdyxTQnzpbPsLj4opFPNP14jFEgSEgX/4c2EXdVJY4qDBKU+aeLOMWx/YW87KXCu /k1i9nC4uRPBw== Received: from sethos.at.struktu.ro (sethos.at.struktu.ro [46.4.183.126]) by dd26416.kasserver.com (Postfix) with ESMTPSA id 32FBD800499; Wed, 10 Jan 2024 17:35:39 +0100 (CET) Received: from chufu.bluecherstrasse.oopsware.lan (i5C750254.versanet.de [92.117.2.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sethos.at.struktu.ro (Postfix) with ESMTPSA id 1B7134F9A9D2; Wed, 10 Jan 2024 17:35:38 +0100 (CET) Message-ID: <4d983458445f220043b4a49a1baae9e299e69a79.camel@oopsware.de> Subject: Re: [PATCH] Add sortsupport for range types and btree_gist From: Bernd Helmle To: jian he , christoph.heiss@cybertec.at Cc: pgsql-hackers@lists.postgresql.org, Christoph Berg Date: Wed, 10 Jan 2024 17:35:37 +0100 In-Reply-To: References: <437ccbcf-8f80-2919-411d-a3af88becf6c@cybertec.at> <77f4bacbeb9d223f90b3a0bd55ef7d65407bfddd.camel@oopsware.de> Autocrypt: addr=mailings@oopsware.de; prefer-encrypt=mutual; keydata=mQGiBEIM4dYRBACEnxQZ/CfR1xbCJzGOIjvh3fZpLALMm+tt237QlZm9nlLaEwCn317sT1khPAJwhyBHSHbNFbH+LOL6ezYrg4V2Q9KHyYJDStJtC8c+D7vHVB5Jfslynx89DnCH6jb3H0j+U0iNYmRmT18PWTZhD5RuXT+Toyz/0hH4YnJzha4VUwCggikXRuhIQ0KIzrps7/PsvasTPjUD/1aoEHRwVyk2C2hXh6GWJYq+1l+sB2d0TOnFJf2xy3Xo03Hi+BEJJdYGqJKqzd0KfsFyJYhO2GIGScSEj1hsTqAiY8OZeRqRGHe69OQEguUSVXp/jPaqU8fel8dbDDMnXkgULq8oO4T9e4GJSFqIvrlx0sJqSMFdiihV+xCzDS40BACBrTq9tyXmyxJWzQ1/0Hx9S4sU+y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PS6649DRkiYOMWTXzAlSEuQINBEIM4d0QCADaxWn10/2l8HHygHCUlBs+vNRYkMrGDWuj1tyehVRRcFYnNfBaEB44GMsaWdKW0GGP4S1BcEwLM3T+ObIrMt6jsLYXWrMctMcGkW60CTbusllwqFN80prqk0Nh/yZsja8UOt+OrWL4ucIBEx9RsUcdUd7+PeuYThOFO1dMgu4gmbac5eN2LZceHJgN9fha19m/vdLXmLc5IEPX/s6+O5oyEkbBt4GYIdvodnBHG9fyip7ff5GPLKzU2gBJz3RWUuHGEaj3RxCffK1x1S87MonbbEkPl2BtmJg2HeWNHn0eaauTp61V0xUWo1XaBB7Ezovogj+70wQjJ4GEgXoH7MRvAAMFCAC/MFpNfWALuQiKE3GA/VdoBTljq2rOnkDcRzBrn8BBVwpYqa2g7SA/VUW334ztI2PmZZYJ0Bjms/Q+oEv87agSL7sQTr8xUOPEyABVnAoDIuIzrAilflYYbvq7o3kwNcsmkr vPZ1FURstKbO+85M/e8tIyCHa6IbTKru6W8Rqxldx2TjoTvcOov3H7bknAdaA8dv6ea/dpI0WTVkuBTMw+jCy2gezwO1wvY+2ehiObOOnlKB2OsMshbe7FHtMU4qB6H1IthiSCzYz5IAsovS8u88HwtUVh/fjLHjTBB85IIMswvJ6SiCXfpe4z8Aj2b5hdo6ggZmI6opiBpaeK164SiEkEGBECAAkFAkIM4d0CGwwACgkQUXXNjoXZSszvIgCfeqX8AYMGEnF+rOp2ukoCWQXfq48AmQEAzB0c5vVMlRnuBh0z9qMKRqbi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.2 (3.50.2-1.fc39) MIME-Version: 1.0 X-Spamd-Bar: --- List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Am Mittwoch, dem 10.01.2024 um 08:00 +0800 schrieb jian he: > you do=C2=A0 `CREATE INDEX ON pgbench_accounts USING gist(aid);` > but the original patch didn't change contrib/btree_gist/btree_int4.c > So I doubt your benchmark is related to the original patch. > or maybe I missed something. >=20 The patch originally does this: +ALTER OPERATOR FAMILY gist_int4_ops USING gist ADD + FUNCTION 11 (int4, int4) btint4sortsupport (internal) ; This adds sortsupport function to int4 as well. We reuse existing btint4sortsupport() function, so no need to change btree_int4.c. > also per doc: > ` > sortsupport > Returns a comparator function to sort data in a way that preserves > locality. It is used by CREATE INDEX and REINDEX commands. The > quality > of the created index depends on how well the sort order determined by > the comparator function preserves locality of the inputs. > ` > from the doc, add sortsupport function will only influence index > build time? >=20 Thats the point of this patch. Though it influences the index quality in a way which seems to cause the measured performance regression upthread. >=20 > per https://www.postgresql.org/docs/current/gist-extensibility.html > QUOTE: > All the GiST support methods are normally called in short-lived > memory > contexts; that is, CurrentMemoryContext will get reset after each > tuple is processed. It is therefore not very important to worry about > pfree'ing everything you palloc. However, in some cases it's useful > for a support method to > ENDOF_QUOTE >=20 > so removing the following part should be OK. > + if ((Datum) range_a !=3D a) > + pfree(range_a); > + > + if ((Datum) range_b !=3D b) > + pfree(range_b); >=20 Probably, i think we get a different range objects in case of detoasting in this case.=20 > comparison solely on the lower bounds looks strange to me. > if lower bound is the same, then compare upper bound, so the > range_gist_cmp function is consistent with function range_compare. > so following change: >=20 > + else > + result =3D range_cmp_bounds(typcache, &lower1, &lower2); > to > ` > else > { > result =3D range_cmp_bounds(typcache, &lower1, &lower2); > if (result =3D=3D 0) > result =3D range_cmp_bounds(typcache, &upper1, &upper2); > } > ` >=20 > does contrib/btree_gist/btree_gist--1.7--1.8.sql function be declared > as strict ? (I am not sure) > other than that, the whole patch looks good. >=20 >=20 That's something surely to consider.