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 1rTLpq-002EWL-Kh for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 13:01:31 +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 1rTLpp-00FHfj-O5 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 13:01:29 +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.94.2) (envelope-from ) id 1rTLpp-00FHfb-EK for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 13:01:29 +0000 Received: from mail-yw1-x112b.google.com ([2607:f8b0:4864:20::112b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rTLpl-003pBb-Sy for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 13:01:28 +0000 Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-5ff7a8b5e61so3212387b3.2 for ; Fri, 26 Jan 2024 05:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706274084; x=1706878884; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=M9ZOkTbSVJ3+IHOGY6oB1clE+q4IBQd4CtSf660GrD8=; b=KpKGwQJPfSOGDNHb8e+j5xnc12jotAjIuDw+aeKzEaLV6RGTyvUxK5Mn0tSlV0S30j K5T5w5KL1RncCDxAU0hDEeQrxwXyrwkiEmD7TFS6efl5hExeM4oXfcVKekI3vYBgOF1n IAS312WOSm5ZFLeRQIXp3fu7Xr2wrxH2mWm0hfKCp37w96756rcTZBQyNCEX1w6fTYSL GS3pras4kuimokHYoidtLodoA27ncIhGmZEuTL/SKQz3id93xPSW+AselaHdUVA4VC8n +sAyUJwdX8MzJMFVoTIX2sxb1BpjXaghPN6krWBv7WuMBrYBFS7VYmfxRUJT/i03K/mn bfUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706274084; x=1706878884; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M9ZOkTbSVJ3+IHOGY6oB1clE+q4IBQd4CtSf660GrD8=; b=j0GKLSPeRbgcMJiQUryFLEFX2v5yJw7BYFbNMm5guviN/Q0hMeqxz+0NbiuXDGkHPC 8oF8ecFdjX525cKdB/xDZ3XM8RJUGISf+/Mlr3N5mxjg1xIdnNRrtteYdOvaSO8wKuD7 43LEw+xjakN49izvZ2WT/mmrcL6T5Gj3HL1KjGDJg9xQ2MAMFX/shh5jlYuiPxk4DFR0 2uSDecpTM6nVoGbMzyVvUOjlCOeG9exLWdatgLwWHq/MWrqm9Mv59dPknkeyWOfv2z1l nFDrBxrC9b+hAa9BgJel3DMQxV+DmuM3DXWGM8qGC/+AP53FuOmbXDPQX3Eq6jPMjRBI McfQ== X-Gm-Message-State: AOJu0YzATzkkRI7A4h3CKytJ7sHvHEJ+E1DnU7ULOnXUxHwq9ewQQjHE fWL2iF3iwxuOa8SBIZ4AblA0gk1Ze8hF6Yz7/2RKlxnasAqDtIFEC/N7WXxEdgRKU9gCkNCW1a+ AIMF3hPLKJG8Vw+WMQWdO2lQzES4vXriKl4IRu1B2 X-Google-Smtp-Source: AGHT+IFaxtxuqMp7srnYnoIb2AlK96QtS6vxu1xTUpAHDe5CtJLGyOON1hrvmArjS9C9VjxXQ7O6YGRY80If4YQR7NY= X-Received: by 2002:a81:b710:0:b0:5ff:a549:2b0 with SMTP id v16-20020a81b710000000b005ffa54902b0mr1217754ywh.58.1706274083744; Fri, 26 Jan 2024 05:01:23 -0800 (PST) MIME-Version: 1.0 References: <437ccbcf-8f80-2919-411d-a3af88becf6c@cybertec.at> <77f4bacbeb9d223f90b3a0bd55ef7d65407bfddd.camel@oopsware.de> In-Reply-To: From: vignesh C Date: Fri, 26 Jan 2024 18:31:12 +0530 Message-ID: Subject: Re: [PATCH] Add sortsupport for range types and btree_gist To: jian he Cc: Bernd Helmle , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 10 Jan 2024 at 19:49, jian he wrote: > > On Wed, Jan 10, 2024 at 8:00=E2=80=AFAM jian he wrote: > > > > ` > > from the doc, add sortsupport function will only influence index build = time? > > > > +/* > > + * GiST sortsupport comparator for ranges. > > + * > > + * Operates solely on the lower bounds of the ranges, comparing them u= sing > > + * range_cmp_bounds(). > > + * Empty ranges are sorted before non-empty ones. > > + */ > > +static int > > +range_gist_cmp(Datum a, Datum b, SortSupport ssup) > > +{ > > + RangeType *range_a =3D DatumGetRangeTypeP(a); > > + RangeType *range_b =3D DatumGetRangeTypeP(b); > > + TypeCacheEntry *typcache =3D ssup->ssup_extra; > > + RangeBound lower1, > > + lower2; > > + RangeBound upper1, > > + upper2; > > + bool empty1, > > + empty2; > > + int result; > > + > > + if (typcache =3D=3D NULL) { > > + Assert(RangeTypeGetOid(range_a) =3D=3D RangeTypeGetOid(range_b)); > > + typcache =3D lookup_type_cache(RangeTypeGetOid(range_a), TYPECACHE_RA= NGE_INFO); > > + > > + /* > > + * Cache the range info between calls to avoid having to call > > + * lookup_type_cache() for each comparison. > > + */ > > + ssup->ssup_extra =3D typcache; > > + } > > + > > + range_deserialize(typcache, range_a, &lower1, &upper1, &empty1); > > + range_deserialize(typcache, range_b, &lower2, &upper2, &empty2); > > + > > + /* For b-tree use, empty ranges sort before all else */ > > + if (empty1 && empty2) > > + result =3D 0; > > + else if (empty1) > > + result =3D -1; > > + else if (empty2) > > + result =3D 1; > > + else > > + result =3D range_cmp_bounds(typcache, &lower1, &lower2); > > + > > + if ((Datum) range_a !=3D a) > > + pfree(range_a); > > + > > + if ((Datum) range_b !=3D b) > > + pfree(range_b); > > + > > + return result; > > +} > > > > 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 > > > > 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); > > > > 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: > > > > + 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); > > } > > ` > > > > 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. > > the original author email address (christoph.heiss@cybertec.at) > Address not found. > so I don't include it. > > I split the original author's patch into 2. > 1. Add GiST sortsupport function for all the btree-gist module data > types except anyrange data type (which actually does not in this > module) > 2. Add GiST sortsupport function for anyrange data type. CFBot shows that the patch does not apply anymore as in [1]: =3D=3D=3D Applying patches on top of PostgreSQL commit ID 7014c9a4bba2d1b67d60687afb5b2091c1d07f73 =3D=3D=3D =3D=3D=3D applying patch ./v5-0001-Add-GIST-sortsupport-function-for-all-the-btree-g.patch patching file contrib/btree_gist/Makefile Hunk #1 FAILED at 33. 1 out of 1 hunk FAILED -- saving rejects to file contrib/btree_gist/Makefil= e.rej ... The next patch would create the file contrib/btree_gist/btree_gist--1.7--1.8.sql, which already exists! Applying it anyway. patching file contrib/btree_gist/btree_gist--1.7--1.8.sql Hunk #1 FAILED at 1. 1 out of 1 hunk FAILED -- saving rejects to file contrib/btree_gist/btree_gist--1.7--1.8.sql.rej patching file contrib/btree_gist/btree_gist.control Hunk #1 FAILED at 1. 1 out of 1 hunk FAILED -- saving rejects to file contrib/btree_gist/btree_gist.control.rej ... patching file contrib/btree_gist/meson.build Hunk #1 FAILED at 50. 1 out of 1 hunk FAILED -- saving rejects to file contrib/btree_gist/meson.build.rej Please post an updated version for the same. [1] - http://cfbot.cputube.org/patch_46_3686.log Regards, Vignesh