Обсуждение: Fixing the btree_gist inet mess

Поиск
Список
Период
Сортировка

Fixing the btree_gist inet mess

От
Tom Lane
Дата:
As we've known for years[1][2][3], contrib/btree_gist's opclasses
for inet/cidr columns are fundamentally broken: they rely on the
planner's convert_network_to_scalar() function, which was only
ever intended to give approximate results, so you get the wrong
answers in edge cases.  There isn't anything that can be done
about that without breaking on-disk compatibility for such indexes,
so we haven't tried.  What we did do some time ago was to implement
a hopefully-correct, in-core gist network_ops opclass to replace the
btree_gist opclasses.  But people are still using the btree_gist
opclasses, because those are marked default and the in-core opclass
isn't.

It's past time to move this problem along and try to get out of the
business of encouraging use of known-broken code.  I propose that
for v19, we should flip the opcdefault status so that network_ops is
marked default and the btree_gist opclasses are not.  This will be
enough to ensure that network_ops is used unless the user explicitly
specifies to do differently.  I don't think we should go further than
that yet (ie, not actively disable the btree_gist code) for a couple
of reasons: (1) this step is messy enough already, and (2) given the
current situation, the in-core network_ops opclass may be less well
tested than one would like.  So I don't think we have enough evidence
to decide that we can summarily force everyone onto it; broken or not,
there haven't been that many complaints about btree_gist's opclasses.

Having done this, the effects of a plain pg_dump from v18- and restore
into v19+ will be to recreate GiST indexes on inet/cidr columns using
network_ops even if they were previously using btree_gist.  That will
happen because in v18-, those opclasses were marked opcdefault and
pg_dump intentionally omits the explicit opclass specification in that
case.  So that works the way we want.

pg_upgrade is more of a problem, because its invocation of pg_dump
will also omit the explicit opclass specification, resulting in the
new server thinking that the index uses network_ops while the on-disk
data isn't compatible with that.  We can't really change that pg_dump
behavior, because that aspect is managed inside the old server's
pg_get_indexdef() function.  The only solution I can see is for
pg_upgrade to refuse to upgrade indexes that use those opclasses.
We can tell users to replace them with network_ops indexes before
upgrading --- that's possible in 9.4 and later, so it should be
a good enough answer for almost everybody.

The attached draft patch implements these ideas and seems to do
the right things in testing.  It's worth remarking on the way
that I did the "mark the btree_gist opclasses not-default" part:
I hacked up DefineOpClass() to ignore the DEFAULT specification if
the opclass being created has the right name and input data type.
That certainly has a foul odor about it, but the alternatives seem
worse.  We can't simply add a btree_gist update step to remove
the DEFAULT setting, because btree_gist--1.2.sql will already have
failed as a consequence of trying to create a default opclass when
there already is one.  Modifying btree_gist--1.2.sql to remove the
DEFAULT markings might be safe, but it goes against our longstanding
rule that extension scripts don't change once shipped, and I'm not
entirely sure that there aren't bad consequences if we break that
rule.  (I did go as far as to add a comment to it about what will
really happen.)  Moreover, even if we were willing to risk changing
btree_gist--1.2.sql, that's not enough: pg_upgrade would still fail,
because it dumps extensions by content, and what it will see in the
old installation is btree_gist opclasses that are marked default.
So hacking up DefineOpClass() can solve both the
normal-extension-install case and the pg_upgrade case for not a lot
of code, and I'm not seeing another way that's better.

There are a couple of loose ends still to be dealt with.  We need
to say something about this in btree-gist.sgml, but I've not
attempted to write that text yet.  Also, I expect that
cross-version-upgrade testing will spit up on the inet/cidr indexes
created by btree_gist's regression tests.  There's probably
nothing that can be done about the latter except to teach
AdjustUpgrade.pm to drop those indexes from the old installation.

Thoughts?

            regards, tom lane

[1] https://www.postgresql.org/message-id/flat/201010112055.o9BKtZf7011251%40wwwmaster.postgresql.org
[2] https://www.postgresql.org/message-id/flat/7891efc1-8378-2cf2-617b-4143848ec895%40proxel.se
[3] https://www.postgresql.org/message-id/flat/19000-2525470d200672ab%40postgresql.org

From 9b594f81fb3b1ebe6ea79d14d4039778e9e523a2 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 1 Aug 2025 14:08:13 -0400
Subject: [PATCH v1] Mark GiST network_ops opcdefault, and btree_gist's
 opclasses not.

We want to deprecate btree_gist's gist_inet_ops and gist_cidr_ops
opclasses, because they sometimes give the wrong answers.  (We won't
remove those opclasses completely just yet, and even if we did,
it wouldn't make this undertaking any less messy.)  As a first
step on that road, make the replacement opclass the default one.

GetDefaultOpClass() enforces that there can be only one default
opclass per index AM and input datatype, so we have to remove
the DEFAULT markings on gist_inet_ops and gist_cidr_ops.  The
only way to do this that doesn't cause failures in pg_upgrade
is to hack up DefineOpClass() to ignore those markings.  Even
then, pg_upgrade would do the wrong things with such indexes,
so refuse to upgrade them.

TODO: user-facing docs, cross-version-upgrade test support.

XXX: don't forget catversion bump.
---
 contrib/btree_gist/btree_gist--1.2.sql |  4 ++
 contrib/btree_gist/expected/cidr.out   |  2 +-
 contrib/btree_gist/expected/inet.out   |  2 +-
 contrib/btree_gist/sql/cidr.sql        |  2 +-
 contrib/btree_gist/sql/inet.sql        |  2 +-
 src/backend/commands/opclasscmds.c     | 20 +++++-
 src/bin/pg_upgrade/check.c             | 90 ++++++++++++++++++++++++++
 src/include/catalog/pg_opclass.dat     |  2 +-
 8 files changed, 117 insertions(+), 7 deletions(-)

diff --git a/contrib/btree_gist/btree_gist--1.2.sql b/contrib/btree_gist/btree_gist--1.2.sql
index 1efe7530438..7b3012032c3 100644
--- a/contrib/btree_gist/btree_gist--1.2.sql
+++ b/contrib/btree_gist/btree_gist--1.2.sql
@@ -1492,6 +1492,10 @@ ALTER OPERATOR FAMILY gist_vbit_ops USING gist ADD
 --
 -- inet/cidr ops
 --
+-- NOTE: while the CREATE OPERATOR CLASS commands below say DEFAULT,
+-- in a v19 or later server DefineOpClass will ignore that and make
+-- gist_inet_ops and gist_cidr_ops non-default.
+--
 --
 --
 -- define the GiST support methods
diff --git a/contrib/btree_gist/expected/cidr.out b/contrib/btree_gist/expected/cidr.out
index 6d0995add60..e61df27affc 100644
--- a/contrib/btree_gist/expected/cidr.out
+++ b/contrib/btree_gist/expected/cidr.out
@@ -32,7 +32,7 @@ SELECT count(*) FROM cidrtmp WHERE a >  '121.111.63.82';
    309
 (1 row)

-CREATE INDEX cidridx ON cidrtmp USING gist ( a );
+CREATE INDEX cidridx ON cidrtmp USING gist ( a gist_cidr_ops );
 SET enable_seqscan=off;
 SELECT count(*) FROM cidrtmp WHERE a <  '121.111.63.82'::cidr;
  count
diff --git a/contrib/btree_gist/expected/inet.out b/contrib/btree_gist/expected/inet.out
index f15f1435f0a..8cf12e3df8e 100644
--- a/contrib/btree_gist/expected/inet.out
+++ b/contrib/btree_gist/expected/inet.out
@@ -32,7 +32,7 @@ SELECT count(*) FROM inettmp WHERE a >  '89.225.196.191';
    386
 (1 row)

-CREATE INDEX inetidx ON inettmp USING gist ( a );
+CREATE INDEX inetidx ON inettmp USING gist ( a gist_inet_ops );
 SET enable_seqscan=off;
 SELECT count(*) FROM inettmp WHERE a <  '89.225.196.191'::inet;
  count
diff --git a/contrib/btree_gist/sql/cidr.sql b/contrib/btree_gist/sql/cidr.sql
index 9bd77185b96..ec1529e3e04 100644
--- a/contrib/btree_gist/sql/cidr.sql
+++ b/contrib/btree_gist/sql/cidr.sql
@@ -15,7 +15,7 @@ SELECT count(*) FROM cidrtmp WHERE a >= '121.111.63.82';

 SELECT count(*) FROM cidrtmp WHERE a >  '121.111.63.82';

-CREATE INDEX cidridx ON cidrtmp USING gist ( a );
+CREATE INDEX cidridx ON cidrtmp USING gist ( a gist_cidr_ops );

 SET enable_seqscan=off;

diff --git a/contrib/btree_gist/sql/inet.sql b/contrib/btree_gist/sql/inet.sql
index 249e8085c3b..0bb73c9d715 100644
--- a/contrib/btree_gist/sql/inet.sql
+++ b/contrib/btree_gist/sql/inet.sql
@@ -16,7 +16,7 @@ SELECT count(*) FROM inettmp WHERE a >= '89.225.196.191';

 SELECT count(*) FROM inettmp WHERE a >  '89.225.196.191';

-CREATE INDEX inetidx ON inettmp USING gist ( a );
+CREATE INDEX inetidx ON inettmp USING gist ( a gist_inet_ops );

 SET enable_seqscan=off;

diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index a6dd8eab518..1cf9bc12f0c 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -343,6 +343,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
                 optsProcNumber, /* amoptsprocnum value */
                 maxProcNumber;    /* amsupport value */
     bool        amstorage;        /* amstorage flag */
+    bool        isDefault = stmt->isDefault;
     List       *operators;        /* OpFamilyMember list for operators */
     List       *procedures;        /* OpFamilyMember list for support procs */
     ListCell   *l;
@@ -610,12 +611,27 @@ DefineOpClass(CreateOpClassStmt *stmt)
                  errmsg("operator class \"%s\" for access method \"%s\" already exists",
                         opcname, stmt->amname)));

+    /*
+     * HACK: if we're trying to create btree_gist's gist_inet_ops or
+     * gist_cidr_ops, avoid failure in the next stanza by silently making the
+     * new opclass non-default.  Without this kluge, we would fail to load
+     * pre-v19 definitions of contrib/btree_gist.  We can remove it sometime
+     * in the far future when we don't expect any such definitions to exist.
+     */
+    if (isDefault)
+    {
+        if (amoid == GIST_AM_OID &&
+            ((typeoid == INETOID && strcmp(opcname, "gist_inet_ops") == 0) ||
+             (typeoid == CIDROID && strcmp(opcname, "gist_cidr_ops") == 0)))
+            isDefault = false;
+    }
+
     /*
      * If we are creating a default opclass, check there isn't one already.
      * (Note we do not restrict this test to visible opclasses; this ensures
      * that typcache.c can find unique solutions to its questions.)
      */
-    if (stmt->isDefault)
+    if (isDefault)
     {
         ScanKeyData skey[1];
         SysScanDesc scan;
@@ -661,7 +677,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
     values[Anum_pg_opclass_opcowner - 1] = ObjectIdGetDatum(GetUserId());
     values[Anum_pg_opclass_opcfamily - 1] = ObjectIdGetDatum(opfamilyoid);
     values[Anum_pg_opclass_opcintype - 1] = ObjectIdGetDatum(typeoid);
-    values[Anum_pg_opclass_opcdefault - 1] = BoolGetDatum(stmt->isDefault);
+    values[Anum_pg_opclass_opcdefault - 1] = BoolGetDatum(isDefault);
     values[Anum_pg_opclass_opckeytype - 1] = ObjectIdGetDatum(storageoid);

     tup = heap_form_tuple(rel->rd_att, values, nulls);
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 310f53c5577..4f6946f68a4 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -9,6 +9,7 @@

 #include "postgres_fe.h"

+#include "catalog/pg_am_d.h"
 #include "catalog/pg_authid_d.h"
 #include "catalog/pg_class_d.h"
 #include "fe_utils/string_utils.h"
@@ -24,6 +25,7 @@ static void check_for_user_defined_postfix_ops(ClusterInfo *cluster);
 static void check_for_incompatible_polymorphics(ClusterInfo *cluster);
 static void check_for_tables_with_oids(ClusterInfo *cluster);
 static void check_for_not_null_inheritance(ClusterInfo *cluster);
+static void check_for_gist_inet_ops(ClusterInfo *cluster);
 static void check_for_pg_role_prefix(ClusterInfo *cluster);
 static void check_for_new_tablespace_dir(void);
 static void check_for_user_defined_encoding_conversions(ClusterInfo *cluster);
@@ -681,6 +683,18 @@ check_and_dump_old_cluster(void)
     if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1800)
         check_for_not_null_inheritance(&old_cluster);

+    /*
+     * Pre-PG 19, the btree_gist extension contained gist_inet_ops and
+     * gist_cidr_ops opclasses that did not reliably give correct answers.
+     * Even if we wanted to support migrating indexes using those forward, we
+     * can't because they were marked opcdefault = true, which will cause
+     * pg_dump to dump such indexes with no explicit opclass specification,
+     * which would do the wrong thing now that the in-core inet_ops opclass is
+     * marked default.  So refuse to upgrade if there are any.
+     */
+    if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1800)
+        check_for_gist_inet_ops(&old_cluster);
+
     /*
      * Pre-PG 10 allowed tables with 'unknown' type columns and non WAL logged
      * hash indexes
@@ -1721,6 +1735,82 @@ check_for_not_null_inheritance(ClusterInfo *cluster)
         check_ok();
 }

+/*
+ * Callback function for processing results of query for
+ * check_for_gist_inet_ops()'s UpgradeTask.  If the query returned any rows
+ * (i.e., the check failed), write the details to the report file.
+ */
+static void
+process_gist_inet_ops_check(DbInfo *dbinfo, PGresult *res, void *arg)
+{
+    UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
+    int            ntups = PQntuples(res);
+    int            i_nspname = PQfnumber(res, "nspname");
+    int            i_relname = PQfnumber(res, "relname");
+
+    AssertVariableIsOfType(&process_gist_inet_ops_check, UpgradeTaskProcessCB);
+
+    if (ntups == 0)
+        return;
+
+    if (report->file == NULL &&
+        (report->file = fopen_priv(report->path, "w")) == NULL)
+        pg_fatal("could not open file \"%s\": %m", report->path);
+
+    fprintf(report->file, "In database: %s\n", dbinfo->db_name);
+
+    for (int rowno = 0; rowno < ntups; rowno++)
+        fprintf(report->file, "  %s.%s\n",
+                PQgetvalue(res, rowno, i_nspname),
+                PQgetvalue(res, rowno, i_relname));
+}
+
+/*
+ * Verify that no indexes use gist_inet_ops/gist_cidr_ops, unless the
+ * opclasses have been changed to not-opcdefault (which would allow
+ * the old server to dump the index definitions with explicit opclasses).
+ */
+static void
+check_for_gist_inet_ops(ClusterInfo *cluster)
+{
+    UpgradeTaskReport report;
+    UpgradeTask *task = upgrade_task_create();
+    const char *query = "SELECT nc.nspname, cc.relname "
+        "FROM   pg_catalog.pg_opclass oc, pg_catalog.pg_index i, "
+        "       pg_catalog.pg_class cc, pg_catalog.pg_namespace nc "
+        "WHERE  oc.opcmethod = " CppAsString2(GIST_AM_OID)
+        "       AND oc.opcname IN ('gist_inet_ops', 'gist_cidr_ops')"
+        "       AND oc.opcdefault"
+        "       AND oc.oid = any(i.indclass)"
+        "       AND i.indexrelid = cc.oid AND cc.relnamespace = nc.oid";
+
+    prep_status("Checking for uses of gist_inet_ops/gist_cidr_ops");
+
+    report.file = NULL;
+    snprintf(report.path, sizeof(report.path), "%s/%s",
+             log_opts.basedir,
+             "gist_inet_ops.txt");
+
+    upgrade_task_add_step(task, query, process_gist_inet_ops_check,
+                          true, &report);
+    upgrade_task_run(task, cluster);
+    upgrade_task_free(task);
+
+    if (report.file)
+    {
+        fclose(report.file);
+        pg_log(PG_REPORT, "fatal");
+        pg_fatal("Your installation contains indexes that use btree_gist's\n"
+                 "gist_inet_ops or gist_cidr_ops opclasses,\n"
+                 "which are not supported anymore.  Replace them with indexes\n"
+                 "that use the built-in GiST network_ops opclass.\n"
+                 "A list of indexes with the problem is in the file:\n"
+                 "    %s", report.path);
+    }
+    else
+        check_ok();
+}
+
 /*
  * check_for_pg_role_prefix()
  *
diff --git a/src/include/catalog/pg_opclass.dat b/src/include/catalog/pg_opclass.dat
index 4a9624802aa..4b2c3a52403 100644
--- a/src/include/catalog/pg_opclass.dat
+++ b/src/include/catalog/pg_opclass.dat
@@ -57,7 +57,7 @@
 { opcmethod => 'hash', opcname => 'inet_ops', opcfamily => 'hash/network_ops',
   opcintype => 'inet' },
 { opcmethod => 'gist', opcname => 'inet_ops', opcfamily => 'gist/network_ops',
-  opcintype => 'inet', opcdefault => 'f' },
+  opcintype => 'inet' },
 { opcmethod => 'spgist', opcname => 'inet_ops',
   opcfamily => 'spgist/network_ops', opcintype => 'inet' },
 { oid => '1979', oid_symbol => 'INT2_BTREE_OPS_OID',
--
2.43.7


Re: Fixing the btree_gist inet mess

От
Matthias van de Meent
Дата:
On Fri, 1 Aug 2025 at 20:17, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> There are a couple of loose ends still to be dealt with.  We need
> to say something about this in btree-gist.sgml, but I've not
> attempted to write that text yet.  Also, I expect that
> cross-version-upgrade testing will spit up on the inet/cidr indexes
> created by btree_gist's regression tests.  There's probably
> nothing that can be done about the latter except to teach
> AdjustUpgrade.pm to drop those indexes from the old installation.
>
> Thoughts?

This was long overdue from a project perspective, so thanks for picking this up.

I think we should still adjust btree-gist--1.2.sql, if only because it
adds stronger protections against any future installs that might try
to get this flag configured. Especially if we at some point in the far
future want to be able to remove this hack we should stop shipping
code that would break without the hack in new releases.

That doesn't remove the need for the pg_upgrade -related code changes,
but I think that just means we need to do both.

As for the rest of the patch:

> +    /*
> +     * HACK: if we're trying to create btree_gist's gist_inet_ops or
> +     * gist_cidr_ops, avoid failure in the next stanza by silently making the
> +     * new opclass non-default.  Without this kluge, we would fail to load
> +     * pre-v19 definitions of contrib/btree_gist.  We can remove it sometime
> +     * in the far future when we don't expect any such definitions to exist.
> +     */
> +    if (isDefault)
> +    {
> +        if (amoid == GIST_AM_OID &&
> +            ((typeoid == INETOID && strcmp(opcname, "gist_inet_ops") == 0) ||
> +             (typeoid == CIDROID && strcmp(opcname, "gist_cidr_ops") == 0)))
> +            isDefault = false;
> +    }

Could we either limit this hack to pg_upgrade cases, or add a WARNING
whenever this condition is triggered and the DEFAULT flag is
overwritten? I think that a user trying to execute such commands
should be made aware that some part of their SQL command was ignored.


Kind regards,

Matthias van de Meent
Databricks (https://www.databricks.com)



Re: Fixing the btree_gist inet mess

От
Tom Lane
Дата:
Matthias van de Meent <boekewurm+postgres@gmail.com> writes:
> On Fri, 1 Aug 2025 at 20:17, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Thoughts?

> This was long overdue from a project perspective, so thanks for picking this up.

> I think we should still adjust btree-gist--1.2.sql, if only because it
> adds stronger protections against any future installs that might try
> to get this flag configured. Especially if we at some point in the far
> future want to be able to remove this hack we should stop shipping
> code that would break without the hack in new releases.

Well ... mumble.  Project policy has been that extension scripts don't
change once shipped.  We have no experience with violating that policy
and hence little certainty about what might break.  I don't think that
we can be certain that nothing will break, because for example there
might be some packager out there who has relied on that policy and
decided they could store extension scripts from multiple PG releases
in one directory.

It's probably worth crossing that bridge at some point, but I'd
rather not make a bug fix dependent on it.

One potential path forward is to roll up the existing series of
update scripts to create a new installation-from-scratch script
btree-gist--1.9.sql which would not try to mark the opclasses as
default.  And I guess we could provide a btree-gist--1.8--1.9.sql
update script that includes manual catalog updates to turn off the
opcdefault flags if they're somehow on; though I'm not sure that
that case would be reachable, so maybe the 1.8--1.9 update could
as well be empty.  Sometime in the very far future, when we have
deprecated pg_upgrade from pre-v19 versions, we could remove all
the pre-1.9 script versions and remove the hack in DefineOpClass.

BTW, one reason why I'm not *that* excited about this is that we've
tolerated some related hacks for a very long time indeed.  See for
instance this twenty-year-old gem in DefineIndex:

        /*
         * Hack to provide more-or-less-transparent updating of old RTREE
         * indexes to GiST: if RTREE is requested and not found, use GIST.
         */
        if (strcmp(accessMethodName, "rtree") == 0)
        {
            ereport(NOTICE,
                    (errmsg("substituting access method \"gist\" for obsolete method \"rtree\"")));
            accessMethodName = "gist";
            tuple = SearchSysCache1(AMNAME, PointerGetDatum(accessMethodName));
        }

> Could we either limit this hack to pg_upgrade cases, or add a WARNING
> whenever this condition is triggered and the DEFAULT flag is
> overwritten? I think that a user trying to execute such commands
> should be made aware that some part of their SQL command was ignored.

I'm not opposed in principle to having a warning, but I don't want one
to come out when some user merely does CREATE EXTENSION btree_gist.
And I don't see how to avoid that if we don't touch
btree-gist--1.2.sql.  In practice, the odds that somebody would hit
this behavior in some other context seem negligible: nobody would be
re-using btree_gist's opclass names.

            regards, tom lane



Re: Fixing the btree_gist inet mess

От
Tom Lane
Дата:
I wrote:
> One potential path forward is to roll up the existing series of
> update scripts to create a new installation-from-scratch script
> btree-gist--1.9.sql which would not try to mark the opclasses as
> default.

> Matthias van de Meent <boekewurm+postgres@gmail.com> writes:
>> Could we either limit this hack to pg_upgrade cases, or add a WARNING
>> whenever this condition is triggered and the DEFAULT flag is
>> overwritten? I think that a user trying to execute such commands
>> should be made aware that some part of their SQL command was ignored.

> I'm not opposed in principle to having a warning, but I don't want one
> to come out when some user merely does CREATE EXTENSION btree_gist.
> And I don't see how to avoid that if we don't touch
> btree-gist--1.2.sql.

Wait a minute ... if we create a rolled-up btree-gist--1.9.sql as
above, and that's the default version, then plain CREATE EXTENSION
wouldn't show the problem anyway.  You'd have to explicitly try to
create an old version to reach the hack.  So maybe a warning-if-
not-in-binary-upgrade-mode wouldn't be too noisy after all.
Let me give that a try.

            regards, tom lane



Re: Fixing the btree_gist inet mess

От
Heikki Linnakangas
Дата:
On 01/08/2025 21:17, Tom Lane wrote:
> It's past time to move this problem along and try to get out of the
> business of encouraging use of known-broken code.  I propose that
> for v19, we should flip the opcdefault status so that network_ops is
> marked default and the btree_gist opclasses are not.  This will be
> enough to ensure that network_ops is used unless the user explicitly
> specifies to do differently.

+1

Bunch of ideas and opinions below, but I'm fine with your plan as is too:

> I don't think we should go further than
> that yet (ie, not actively disable the btree_gist code) for a couple
> of reasons: (1) this step is messy enough already, and (2) given the> current situation, the in-core network_ops
opclassmay be less well
 
> tested than one would like.  So I don't think we have enough evidence
> to decide that we can summarily force everyone onto it; broken or not,
> there haven't been that many complaints about btree_gist's opclasses.

If we implement upgrade the way you propose, all upgraded databases, 
whether it's with pg_dump or pg_upgrade, will switch to using 
network_ops. The only way to get an index with the old btree_gist 
opclass is to specify it explicitly, on v19. I think we might as well 
remove it completely.

The upgrade as proposed will be a hurdle for anyone using the old 
opclass anyway, so people will get some warning to test their 
application after the upgrade. In the worst case people can stick with 
the old version until any issues have been fixed.

> Having done this, the effects of a plain pg_dump from v18- and restore
> into v19+ will be to recreate GiST indexes on inet/cidr columns using
> network_ops even if they were previously using btree_gist.  That will
> happen because in v18-, those opclasses were marked opcdefault and
> pg_dump intentionally omits the explicit opclass specification in that
> case.  So that works the way we want.
> 
> pg_upgrade is more of a problem, because its invocation of pg_dump
> will also omit the explicit opclass specification, resulting in the
> new server thinking that the index uses network_ops while the on-disk
> data isn't compatible with that.  We can't really change that pg_dump
> behavior, because that aspect is managed inside the old server's
> pg_get_indexdef() function.  The only solution I can see is for
> pg_upgrade to refuse to upgrade indexes that use those opclasses.
> We can tell users to replace them with network_ops indexes before
> upgrading --- that's possible in 9.4 and later, so it should be
> a good enough answer for almost everybody.

I wonder if we could move the old opclass's code to core, and somehow 
detect at runtime e.g. by looking at the root page, whether the index 
was built before the upgrade. Hack initGISTstate() to redirect 
everything to the old AM if it was created before the upgrade. The idea 
is that after upgrade, all indexes would appear to be using the new 
opclass if you look at the catalogs, but if it was pg_upgraded from an 
older version, it would actually use the old functions. If you REINDEX, 
it would get recreated in the new format, and would start using the new 
functions. That would be the best user experience, but not sure it's 
worth the effort and all the special hacks.

> The attached draft patch implements these ideas and seems to do
> the right things in testing.  It's worth remarking on the way
> that I did the "mark the btree_gist opclasses not-default" part:
> I hacked up DefineOpClass() to ignore the DEFAULT specification if
> the opclass being created has the right name and input data type.
> That certainly has a foul odor about it, but the alternatives seem
> worse.  We can't simply add a btree_gist update step to remove
> the DEFAULT setting, because btree_gist--1.2.sql will already have
> failed as a consequence of trying to create a default opclass when
> there already is one.  Modifying btree_gist--1.2.sql to remove the
> DEFAULT markings might be safe, but it goes against our longstanding
> rule that extension scripts don't change once shipped, and I'm not
> entirely sure that there aren't bad consequences if we break that
> rule.  (I did go as far as to add a comment to it about what will
> really happen.)  Moreover, even if we were willing to risk changing
> btree_gist--1.2.sql, that's not enough: pg_upgrade would still fail,
> because it dumps extensions by content, and what it will see in the
> old installation is btree_gist opclasses that are marked default.
> So hacking up DefineOpClass() can solve both the
> normal-extension-install case and the pg_upgrade case for not a lot
> of code, and I'm not seeing another way that's better.

Instead of having the hack in DefineOpClass(), we could have a similar 
hack in pg_dump's dump_opclass(), only in binary upgrade mode.

It seems silly to keep an unmodified btree_gist--1.2.sql in v19, if it 
actually gets installed in a different way. I feel we should truncate 
the history and only include a new btree_gist--1.9.sql in v19.

Putting all that together, you get a more aggressive plan:

- Remove the old opclass entirely
- Remove all old btree_gist--*.sql scripts, start afresh with 
btree_gist--1.9.sql
- Hack pg_dump, in binary upgrade mode, to dump the btree_gist extension 
as simply "CREATE EXTENSION btree_gist;", instead of dumping the 
individual members like it usually does.


Because btree_gist a contrib extension, we have the luxury that we can 
do special hacks like this, in DefineOpClass() or in pg_upgrade. Out of 
core extensions don't have that luxury. Could we generalize this?

I think the common case for extensions is that you'd want them be 
implicitly upgraded to the latest version when you pg_upgrade. So for 
most extensions, you would actually want pg_upgrade's dump and restore 
to just do "CREATE EXTENSION foo;" instead of dumping the individual 
members. But I'm sure there are exceptions. Could we add information to 
the control file about that? For example, list all the older extension 
versions that new default version is binary-compatible with. In 
pg_upgrade, if the new default version is marked as binary-compatible 
with the old installed version, install the new version on the new 
cluster directly. Have support for extension scripts that are run on 
pg_upgrade.

In the btree_gist case, the new version would be marked as 
binary-compatible with all previous extension versions, but there would 
be a pre-upgrade script that throws an error if there are any indexes 
using the old opclass.

> Also, I expect that cross-version-upgrade testing will spit up on
> the inet/cidr indexes created by btree_gist's regression tests.
> There's probably nothing that can be done about the latter except to
> teach AdjustUpgrade.pm to drop those indexes from the old
> installation.
Yeah. It would be nice to not drop them so that we have some test 
coverage for upgrading them, though. At least if we do more with them 
than just refuse the upgrade.

- Heikki




Re: Fixing the btree_gist inet mess

От
Heikki Linnakangas
Дата:
On 18/12/2025 13:15, Heikki Linnakangas wrote:
> On 01/08/2025 21:17, Tom Lane wrote:
>> It's past time to move this problem along and try to get out of the
>> business of encouraging use of known-broken code.  I propose that
>> for v19, we should flip the opcdefault status so that network_ops is
>> marked default and the btree_gist opclasses are not.  This will be
>> enough to ensure that network_ops is used unless the user explicitly
>> specifies to do differently.
> 
> +1
> 
> Bunch of ideas and opinions below, but I'm fine with your plan as is too:

Sorry, I was confused by my emails and replied to this old email 
ignoring the later discussion. But I think all I said is still valid, 
and some of it was already mentioned.

- Heikki




Re: Fixing the btree_gist inet mess

От
Tom Lane
Дата:
Heikki Linnakangas <hlinnaka@iki.fi> writes:
> On 01/08/2025 21:17, Tom Lane wrote:
>> It's past time to move this problem along and try to get out of the
>> business of encouraging use of known-broken code.  I propose that
>> for v19, we should flip the opcdefault status so that network_ops is
>> marked default and the btree_gist opclasses are not.  This will be
>> enough to ensure that network_ops is used unless the user explicitly
>> specifies to do differently.

> I wonder if we could move the old opclass's code to core, and somehow 
> detect at runtime e.g. by looking at the root page, whether the index 
> was built before the upgrade. Hack initGISTstate() to redirect 
> everything to the old AM if it was created before the upgrade. The idea 
> is that after upgrade, all indexes would appear to be using the new 
> opclass if you look at the catalogs, but if it was pg_upgraded from an 
> older version, it would actually use the old functions. If you REINDEX, 
> it would get recreated in the new format, and would start using the new 
> functions. That would be the best user experience, but not sure it's 
> worth the effort and all the special hacks.

It's more work than I want to do, anyway.  Also, that path would
pretty much mean we could never get rid of the broken code.

> Instead of having the hack in DefineOpClass(), we could have a similar 
> hack in pg_dump's dump_opclass(), only in binary upgrade mode.

Hmm ... I'll take a look at that.  However, that would not allow
people to install pre-1.9 versions of btree_gist, at least not without
manually editing the extension script.

> Putting all that together, you get a more aggressive plan:

> - Remove the old opclass entirely
> - Remove all old btree_gist--*.sql scripts, start afresh with 
> btree_gist--1.9.sql
> - Hack pg_dump, in binary upgrade mode, to dump the btree_gist extension 
> as simply "CREATE EXTENSION btree_gist;", instead of dumping the 
> individual members like it usually does.

I think that that is where we want to end up in a release or two.
But as I explained upthread, I'm afraid to do it right off the bat:
I don't have 100% confidence in the new opclass code because I fear
it hasn't gotten enough road mileage.  So I don't want to tell people
they flat out cannot use the old code as of v19.  I think switching
the default choice of opclass is the right amount of risk for v19.
We could plan to remove the old code as of v20 or v21 or so.

            regards, tom lane



Re: Fixing the btree_gist inet mess

От
Tom Lane
Дата:
Here's a v2 patchset that tries to address all the discussion so far.

The principal change from v1 is that I made a rolled-up
btree_gist--1.9.sql script in which the problem opclasses are not
marked DEFAULT.  So that version can be installed without any
hack in DefineOpClass.  This answer is much better than my v1 in
terms of having a clean way to describe the change in the module,
too.

We still need a hack for binary-upgrade mode though, since pg_dump
will dump the CREATE OPERATOR CLASS commands with DEFAULT if it's
looking at an old copy of btree_gist.  (I looked at putting said hack
into pg_dump instead of the server, but it didn't seem like an
improvement.  Heikki's idea of making pg_dump --binary-upgrade
dump "CREATE EXTENSION btree_gist" seemed much messier than this,
too.)

Because I didn't change DefineOpClass's behavior when
!IsBinaryUpgrade, any attempt to install a pre-1.9 version of
btree_gist will now fail.  So we could remove btree_gist--1.2.sql
as well as btree_gist--1.0--1.1.sql and btree_gist--1.1--1.2.sql
without cost.  (I've not done that here, as it would just bloat the
patchset some more.)  However we should keep btree_gist--1.2--1.3.sql
and later delta scripts, so that users can update old definitions of
the module to 1.9 after a pg_upgrade.

I've also fixed up the cross-version-upgrade tests and written
some documentation.

One point perhaps worth mentioning here is that it works to
copy btree_gist--1.8--1.9.sql into a v18 installation and
issue
    ALTER EXTENSION btree_gist UPDATE TO '1.9';
after which pg_upgrade will let you upgrade your old indexes
without complaint, because pg_dump will now do the right things.
I did not document this because (a) it does not work in anything
before v18 due to lack of btree_gist 1.8, and (b) we don't want
to encourage people to stay on the old opclasses in v19.  But
perhaps somebody would find a reason to want to do this.

I'd probably squash all this into one commit at the end, but
I made it into several patches for review purposes.

            regards, tom lane

From ae3f24ddaff84ba9ea4c13d820b8441eee953709 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 18 Dec 2025 15:37:34 -0500
Subject: [PATCH v2 1/3] Create btree_gist v1.9, in which inet/cidr opclasses
 aren't default.

Roll up the preceding deltas since 1.2 into a new base script
btree_gist--1.9.sql.  This will allow installing 1.9 without going
through a transient situation where gist_inet_ops and gist_cidr_ops
are marked as opcdefault; trying to create them that way would fail
if there's already a matching default opclass in the core system.

I noted along the way that commit 57e3c5160 had missed marking the
gist_bool_ops support functions as PARALLEL SAFE.  While that probably
has little harmful effect (since AFAIK we don't check that when
calling index support functions), this seems like a good time to make
things consistent.

Readers will also note that I removed the former habit of installing
some opclass operators/functions with ALTER OPERATOR FAMILY, instead
just rolling them all into the CREATE OPERATOR CLASS steps.  The
comment in btree_gist--1.2.sql that it's necessary to use ALTER for
pg_upgrade reproducibility has been obsolete since we invented the
amadjustmembers infrastructure.  Nowadays, gistadjustmembers will
force all operators and non-required support functions to have "soft"
opfamily dependencies, regardless of whether they are installed by
CREATE or ALTER.

This patch doesn't yet change 1.9 to be the default version, mainly
so that the module's regression tests will still pass.  The main
thing to verify at this point is that the installed objects are the
same between 1.8 and 1.9 except for the few intended differences.
(I tested that by comparing "pg_dump --binary-upgrade" output.)

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2483812.1754072263@sss.pgh.pa.us
---
 contrib/btree_gist/Makefile                 |    3 +-
 contrib/btree_gist/btree_gist--1.8--1.9.sql |   40 +
 contrib/btree_gist/btree_gist--1.9.sql      | 1971 +++++++++++++++++++
 contrib/btree_gist/meson.build              |    2 +
 4 files changed, 2015 insertions(+), 1 deletion(-)
 create mode 100644 contrib/btree_gist/btree_gist--1.8--1.9.sql
 create mode 100644 contrib/btree_gist/btree_gist--1.9.sql

diff --git a/contrib/btree_gist/Makefile b/contrib/btree_gist/Makefile
index 7ac2df26c10..5161b42b69f 100644
--- a/contrib/btree_gist/Makefile
+++ b/contrib/btree_gist/Makefile
@@ -34,7 +34,8 @@ DATA = btree_gist--1.0--1.1.sql \
        btree_gist--1.1--1.2.sql btree_gist--1.2.sql btree_gist--1.2--1.3.sql \
        btree_gist--1.3--1.4.sql btree_gist--1.4--1.5.sql \
        btree_gist--1.5--1.6.sql btree_gist--1.6--1.7.sql \
-       btree_gist--1.7--1.8.sql
+       btree_gist--1.7--1.8.sql btree_gist--1.8--1.9.sql \
+       btree_gist--1.9.sql
 PGFILEDESC = "btree_gist - B-tree equivalent GiST operator classes"

 REGRESS = init int2 int4 int8 float4 float8 cash oid timestamp timestamptz \
diff --git a/contrib/btree_gist/btree_gist--1.8--1.9.sql b/contrib/btree_gist/btree_gist--1.8--1.9.sql
new file mode 100644
index 00000000000..c67812f5f5d
--- /dev/null
+++ b/contrib/btree_gist/btree_gist--1.8--1.9.sql
@@ -0,0 +1,40 @@
+/* contrib/btree_gist/btree_gist--1.8--1.9.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "ALTER EXTENSION btree_gist UPDATE TO '1.9'" to load this file. \quit
+
+--
+-- Mark gist_inet_ops and gist_cidr_ops opclasses as non-default.
+-- This is the first step on the way to eventually removing them.
+--
+-- There's no SQL command for this, so fake it with a manual update on
+-- pg_opclass.
+--
+DO LANGUAGE plpgsql
+$$
+DECLARE
+  my_schema pg_catalog.text := pg_catalog.quote_ident(pg_catalog.current_schema());
+  old_path pg_catalog.text := pg_catalog.current_setting('search_path');
+BEGIN
+-- for safety, transiently set search_path to just pg_catalog+pg_temp
+PERFORM pg_catalog.set_config('search_path', 'pg_catalog, pg_temp', true);
+
+UPDATE pg_catalog.pg_opclass
+SET opcdefault = false
+WHERE opcmethod = (SELECT oid FROM pg_catalog.pg_am WHERE amname = 'gist') AND
+      opcname IN ('gist_inet_ops', 'gist_cidr_ops') AND
+      opcnamespace = my_schema::pg_catalog.regnamespace;
+
+PERFORM pg_catalog.set_config('search_path', old_path, true);
+END
+$$;
+
+
+-- Fix parallel-safety markings overlooked in btree_gist--1.6--1.7.sql.
+ALTER FUNCTION gbt_bool_consistent(internal, bool, smallint, oid, internal) PARALLEL SAFE;
+ALTER FUNCTION gbt_bool_compress(internal) PARALLEL SAFE;
+ALTER FUNCTION gbt_bool_fetch(internal) PARALLEL SAFE;
+ALTER FUNCTION gbt_bool_penalty(internal, internal, internal) PARALLEL SAFE;
+ALTER FUNCTION gbt_bool_picksplit(internal, internal) PARALLEL SAFE;
+ALTER FUNCTION gbt_bool_union(internal, internal) PARALLEL SAFE;
+ALTER FUNCTION gbt_bool_same(gbtreekey2, gbtreekey2, internal) PARALLEL SAFE;
diff --git a/contrib/btree_gist/btree_gist--1.9.sql b/contrib/btree_gist/btree_gist--1.9.sql
new file mode 100644
index 00000000000..504de91289d
--- /dev/null
+++ b/contrib/btree_gist/btree_gist--1.9.sql
@@ -0,0 +1,1971 @@
+/* contrib/btree_gist/btree_gist--1.9.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION btree_gist" to load this file. \quit
+
+CREATE FUNCTION gbtreekey2_in(cstring)
+RETURNS gbtreekey2
+AS 'MODULE_PATHNAME', 'gbtreekey_in'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbtreekey2_out(gbtreekey2)
+RETURNS cstring
+AS 'MODULE_PATHNAME', 'gbtreekey_out'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE TYPE gbtreekey2 (
+    INTERNALLENGTH = 2,
+    INPUT  = gbtreekey2_in,
+    OUTPUT = gbtreekey2_out
+);
+
+CREATE FUNCTION gbtreekey4_in(cstring)
+RETURNS gbtreekey4
+AS 'MODULE_PATHNAME', 'gbtreekey_in'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbtreekey4_out(gbtreekey4)
+RETURNS cstring
+AS 'MODULE_PATHNAME', 'gbtreekey_out'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE TYPE gbtreekey4 (
+    INTERNALLENGTH = 4,
+    INPUT  = gbtreekey4_in,
+    OUTPUT = gbtreekey4_out
+);
+
+CREATE FUNCTION gbtreekey8_in(cstring)
+RETURNS gbtreekey8
+AS 'MODULE_PATHNAME', 'gbtreekey_in'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbtreekey8_out(gbtreekey8)
+RETURNS cstring
+AS 'MODULE_PATHNAME', 'gbtreekey_out'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE TYPE gbtreekey8 (
+    INTERNALLENGTH = 8,
+    INPUT  = gbtreekey8_in,
+    OUTPUT = gbtreekey8_out
+);
+
+CREATE FUNCTION gbtreekey16_in(cstring)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME', 'gbtreekey_in'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbtreekey16_out(gbtreekey16)
+RETURNS cstring
+AS 'MODULE_PATHNAME', 'gbtreekey_out'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE TYPE gbtreekey16 (
+    INTERNALLENGTH = 16,
+    INPUT  = gbtreekey16_in,
+    OUTPUT = gbtreekey16_out
+);
+
+CREATE FUNCTION gbtreekey32_in(cstring)
+RETURNS gbtreekey32
+AS 'MODULE_PATHNAME', 'gbtreekey_in'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbtreekey32_out(gbtreekey32)
+RETURNS cstring
+AS 'MODULE_PATHNAME', 'gbtreekey_out'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE TYPE gbtreekey32 (
+    INTERNALLENGTH = 32,
+    INPUT  = gbtreekey32_in,
+    OUTPUT = gbtreekey32_out
+);
+
+CREATE FUNCTION gbtreekey_var_in(cstring)
+RETURNS gbtreekey_var
+AS 'MODULE_PATHNAME', 'gbtreekey_in'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbtreekey_var_out(gbtreekey_var)
+RETURNS cstring
+AS 'MODULE_PATHNAME', 'gbtreekey_out'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE TYPE gbtreekey_var (
+    INTERNALLENGTH = VARIABLE,
+    INPUT  = gbtreekey_var_in,
+    OUTPUT = gbtreekey_var_out,
+    STORAGE = EXTENDED
+);
+
+--common support functions
+
+CREATE FUNCTION gist_translate_cmptype_btree(int)
+RETURNS smallint
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+--distance operators
+
+CREATE FUNCTION cash_dist(money, money)
+RETURNS money
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = money,
+    RIGHTARG = money,
+    PROCEDURE = cash_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION date_dist(date, date)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = date,
+    RIGHTARG = date,
+    PROCEDURE = date_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION float4_dist(float4, float4)
+RETURNS float4
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = float4,
+    RIGHTARG = float4,
+    PROCEDURE = float4_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION float8_dist(float8, float8)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = float8,
+    RIGHTARG = float8,
+    PROCEDURE = float8_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION int2_dist(int2, int2)
+RETURNS int2
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = int2,
+    RIGHTARG = int2,
+    PROCEDURE = int2_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION int4_dist(int4, int4)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = int4,
+    RIGHTARG = int4,
+    PROCEDURE = int4_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION int8_dist(int8, int8)
+RETURNS int8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = int8,
+    RIGHTARG = int8,
+    PROCEDURE = int8_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION interval_dist(interval, interval)
+RETURNS interval
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = interval,
+    RIGHTARG = interval,
+    PROCEDURE = interval_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION oid_dist(oid, oid)
+RETURNS oid
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = oid,
+    RIGHTARG = oid,
+    PROCEDURE = oid_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION time_dist(time, time)
+RETURNS interval
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = time,
+    RIGHTARG = time,
+    PROCEDURE = time_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION ts_dist(timestamp, timestamp)
+RETURNS interval
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = timestamp,
+    RIGHTARG = timestamp,
+    PROCEDURE = ts_dist,
+    COMMUTATOR = '<->'
+);
+
+CREATE FUNCTION tstz_dist(timestamptz, timestamptz)
+RETURNS interval
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <-> (
+    LEFTARG = timestamptz,
+    RIGHTARG = timestamptz,
+    PROCEDURE = tstz_dist,
+    COMMUTATOR = '<->'
+);
+
+
+--
+--
+--
+-- oid ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_oid_consistent(internal,oid,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_distance(internal,oid,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_decompress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_var_decompress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_var_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_union(internal, internal)
+RETURNS gbtreekey8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_same(gbtreekey8, gbtreekey8, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_oid_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_oid_ops
+DEFAULT FOR TYPE oid USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.oid_ops ,
+    FUNCTION    1    gbt_oid_consistent (internal, oid, int2, oid, internal),
+    FUNCTION    2    gbt_oid_union (internal, internal),
+    FUNCTION    3    gbt_oid_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_oid_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_oid_picksplit (internal, internal),
+    FUNCTION    7    gbt_oid_same (gbtreekey8, gbtreekey8, internal),
+    FUNCTION    8    gbt_oid_distance (internal, oid, int2, oid, internal),
+    FUNCTION    9    gbt_oid_fetch (internal),
+    FUNCTION    11    gbt_oid_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey8;
+
+
+--
+--
+--
+-- int2 ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_int2_consistent(internal,int2,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_distance(internal,int2,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_union(internal, internal)
+RETURNS gbtreekey4
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_same(gbtreekey4, gbtreekey4, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int2_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_int2_ops
+DEFAULT FOR TYPE int2 USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.integer_ops ,
+    FUNCTION    1    gbt_int2_consistent (internal, int2, int2, oid, internal),
+    FUNCTION    2    gbt_int2_union (internal, internal),
+    FUNCTION    3    gbt_int2_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_int2_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_int2_picksplit (internal, internal),
+    FUNCTION    7    gbt_int2_same (gbtreekey4, gbtreekey4, internal),
+    FUNCTION    8    gbt_int2_distance (internal, int2, int2, oid, internal),
+    FUNCTION    9    gbt_int2_fetch (internal),
+    FUNCTION    11    gbt_int2_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey4;
+
+
+--
+--
+--
+-- int4 ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_int4_consistent(internal,int4,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_distance(internal,int4,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_union(internal, internal)
+RETURNS gbtreekey8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_same(gbtreekey8, gbtreekey8, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int4_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_int4_ops
+DEFAULT FOR TYPE int4 USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.integer_ops ,
+    FUNCTION    1    gbt_int4_consistent (internal, int4, int2, oid, internal),
+    FUNCTION    2    gbt_int4_union (internal, internal),
+    FUNCTION    3    gbt_int4_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_int4_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_int4_picksplit (internal, internal),
+    FUNCTION    7    gbt_int4_same (gbtreekey8, gbtreekey8, internal),
+    FUNCTION    8    gbt_int4_distance (internal, int4, int2, oid, internal),
+    FUNCTION    9    gbt_int4_fetch (internal),
+    FUNCTION    11    gbt_int4_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey8;
+
+
+--
+--
+--
+-- int8 ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_int8_consistent(internal,int8,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_distance(internal,int8,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_int8_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_int8_ops
+DEFAULT FOR TYPE int8 USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.integer_ops ,
+    FUNCTION    1    gbt_int8_consistent (internal, int8, int2, oid, internal),
+    FUNCTION    2    gbt_int8_union (internal, internal),
+    FUNCTION    3    gbt_int8_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_int8_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_int8_picksplit (internal, internal),
+    FUNCTION    7    gbt_int8_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    8    gbt_int8_distance (internal, int8, int2, oid, internal),
+    FUNCTION    9    gbt_int8_fetch (internal),
+    FUNCTION    11    gbt_int8_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- float4 ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_float4_consistent(internal,float4,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_distance(internal,float4,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_union(internal, internal)
+RETURNS gbtreekey8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_same(gbtreekey8, gbtreekey8, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float4_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_float4_ops
+DEFAULT FOR TYPE float4 USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.float_ops ,
+    FUNCTION    1    gbt_float4_consistent (internal, float4, int2, oid, internal),
+    FUNCTION    2    gbt_float4_union (internal, internal),
+    FUNCTION    3    gbt_float4_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_float4_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_float4_picksplit (internal, internal),
+    FUNCTION    7    gbt_float4_same (gbtreekey8, gbtreekey8, internal),
+    FUNCTION    8    gbt_float4_distance (internal, float4, int2, oid, internal),
+    FUNCTION    9    gbt_float4_fetch (internal),
+    FUNCTION    11    gbt_float4_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey8;
+
+
+--
+--
+--
+-- float8 ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_float8_consistent(internal,float8,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_distance(internal,float8,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_float8_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_float8_ops
+DEFAULT FOR TYPE float8 USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.float_ops ,
+    FUNCTION    1    gbt_float8_consistent (internal, float8, int2, oid, internal),
+    FUNCTION    2    gbt_float8_union (internal, internal),
+    FUNCTION    3    gbt_float8_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_float8_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_float8_picksplit (internal, internal),
+    FUNCTION    7    gbt_float8_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    8    gbt_float8_distance (internal, float8, int2, oid, internal),
+    FUNCTION    9    gbt_float8_fetch (internal),
+    FUNCTION    11    gbt_float8_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- timestamp ops
+--
+--
+--
+
+CREATE FUNCTION gbt_ts_consistent(internal,timestamp,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_distance(internal,timestamp,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_tstz_consistent(internal,timestamptz,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_tstz_distance(internal,timestamptz,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_tstz_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_ts_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_timestamp_ops
+DEFAULT FOR TYPE timestamp USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.interval_ops ,
+    FUNCTION    1    gbt_ts_consistent (internal, timestamp, int2, oid, internal),
+    FUNCTION    2    gbt_ts_union (internal, internal),
+    FUNCTION    3    gbt_ts_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_ts_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_ts_picksplit (internal, internal),
+    FUNCTION    7    gbt_ts_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    8    gbt_ts_distance (internal, timestamp, int2, oid, internal),
+    FUNCTION    9    gbt_ts_fetch (internal),
+    FUNCTION    11    gbt_ts_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_timestamptz_ops
+DEFAULT FOR TYPE timestamptz USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.interval_ops ,
+    FUNCTION    1    gbt_tstz_consistent (internal, timestamptz, int2, oid, internal),
+    FUNCTION    2    gbt_ts_union (internal, internal),
+    FUNCTION    3    gbt_tstz_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_ts_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_ts_picksplit (internal, internal),
+    FUNCTION    7    gbt_ts_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    8    gbt_tstz_distance (internal, timestamptz, int2, oid, internal),
+    FUNCTION    9    gbt_ts_fetch (internal),
+    FUNCTION    11    gbt_ts_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- time ops
+--
+--
+--
+
+CREATE FUNCTION gbt_time_consistent(internal,time,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_distance(internal,time,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_timetz_consistent(internal,timetz,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_timetz_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_time_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_time_ops
+DEFAULT FOR TYPE time USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.interval_ops ,
+    FUNCTION    1    gbt_time_consistent (internal, time, int2, oid, internal),
+    FUNCTION    2    gbt_time_union (internal, internal),
+    FUNCTION    3    gbt_time_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_time_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_time_picksplit (internal, internal),
+    FUNCTION    7    gbt_time_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    8    gbt_time_distance (internal, time, int2, oid, internal),
+    FUNCTION    9    gbt_time_fetch (internal),
+    FUNCTION    11    gbt_time_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+CREATE OPERATOR CLASS gist_timetz_ops
+DEFAULT FOR TYPE timetz USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_timetz_consistent (internal, timetz, int2, oid, internal),
+    FUNCTION    2    gbt_time_union (internal, internal),
+    FUNCTION    3    gbt_timetz_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_time_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_time_picksplit (internal, internal),
+    FUNCTION    7    gbt_time_same (gbtreekey16, gbtreekey16, internal),
+    -- no 'fetch' function, as the compress function is lossy.
+    FUNCTION    11    gbt_time_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- date ops
+--
+--
+--
+
+CREATE FUNCTION gbt_date_consistent(internal,date,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_distance(internal,date,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_union(internal, internal)
+RETURNS gbtreekey8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_same(gbtreekey8, gbtreekey8, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_date_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_date_ops
+DEFAULT FOR TYPE date USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.integer_ops ,
+    FUNCTION    1    gbt_date_consistent (internal, date, int2, oid, internal),
+    FUNCTION    2    gbt_date_union (internal, internal),
+    FUNCTION    3    gbt_date_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_date_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_date_picksplit (internal, internal),
+    FUNCTION    7    gbt_date_same (gbtreekey8, gbtreekey8, internal),
+    FUNCTION    8    gbt_date_distance (internal, date, int2, oid, internal),
+    FUNCTION    9    gbt_date_fetch (internal),
+    FUNCTION    11    gbt_date_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey8;
+
+
+--
+--
+--
+-- interval ops
+--
+--
+--
+
+CREATE FUNCTION gbt_intv_consistent(internal,interval,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_distance(internal,interval,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_decompress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_union(internal, internal)
+RETURNS gbtreekey32
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_same(gbtreekey32, gbtreekey32, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_intv_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_interval_ops
+DEFAULT FOR TYPE interval USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.interval_ops ,
+    FUNCTION    1    gbt_intv_consistent (internal, interval, int2, oid, internal),
+    FUNCTION    2    gbt_intv_union (internal, internal),
+    FUNCTION    3    gbt_intv_compress (internal),
+    FUNCTION    4    gbt_intv_decompress (internal),
+    FUNCTION    5    gbt_intv_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_intv_picksplit (internal, internal),
+    FUNCTION    7    gbt_intv_same (gbtreekey32, gbtreekey32, internal),
+    FUNCTION    8    gbt_intv_distance (internal, interval, int2, oid, internal),
+    FUNCTION    9    gbt_intv_fetch (internal),
+    FUNCTION    11    gbt_intv_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey32;
+
+
+--
+--
+--
+-- cash ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_cash_consistent(internal,money,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_distance(internal,money,int2,oid,internal)
+RETURNS float8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_cash_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_cash_ops
+DEFAULT FOR TYPE money USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    OPERATOR    15    <-> FOR ORDER BY pg_catalog.money_ops ,
+    FUNCTION    1    gbt_cash_consistent (internal, money, int2, oid, internal),
+    FUNCTION    2    gbt_cash_union (internal, internal),
+    FUNCTION    3    gbt_cash_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_cash_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_cash_picksplit (internal, internal),
+    FUNCTION    7    gbt_cash_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    8    gbt_cash_distance (internal, money, int2, oid, internal),
+    FUNCTION    9    gbt_cash_fetch (internal),
+    FUNCTION    11    gbt_cash_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- macaddr ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_macad_consistent(internal,macaddr,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macaddr_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_macaddr_ops
+DEFAULT FOR TYPE macaddr USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_macad_consistent (internal, macaddr, int2, oid, internal),
+    FUNCTION    2    gbt_macad_union (internal, internal),
+    FUNCTION    3    gbt_macad_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_macad_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_macad_picksplit (internal, internal),
+    FUNCTION    7    gbt_macad_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    9    gbt_macad_fetch (internal),
+    FUNCTION    11    gbt_macaddr_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- text/bpchar ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_text_consistent(internal,text,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bpchar_consistent(internal,bpchar,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_text_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bpchar_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_text_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_text_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_text_union(internal, internal)
+RETURNS gbtreekey_var
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_text_same(gbtreekey_var, gbtreekey_var, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_text_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bpchar_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_text_ops
+DEFAULT FOR TYPE text USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_text_consistent (internal, text, int2, oid, internal),
+    FUNCTION    2    gbt_text_union (internal, internal),
+    FUNCTION    3    gbt_text_compress (internal),
+    FUNCTION    4    gbt_var_decompress (internal),
+    FUNCTION    5    gbt_text_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_text_picksplit (internal, internal),
+    FUNCTION    7    gbt_text_same (gbtreekey_var, gbtreekey_var, internal),
+    FUNCTION    9    gbt_var_fetch (internal),
+    FUNCTION    11    gbt_text_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE            gbtreekey_var;
+
+---- Create the operator class
+CREATE OPERATOR CLASS gist_bpchar_ops
+DEFAULT FOR TYPE bpchar USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_bpchar_consistent (internal, bpchar , int2, oid, internal),
+    FUNCTION    2    gbt_text_union (internal, internal),
+    FUNCTION    3    gbt_bpchar_compress (internal),
+    FUNCTION    4    gbt_var_decompress (internal),
+    FUNCTION    5    gbt_text_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_text_picksplit (internal, internal),
+    FUNCTION    7    gbt_text_same (gbtreekey_var, gbtreekey_var, internal),
+    FUNCTION    9    gbt_var_fetch (internal),
+    FUNCTION    11    gbt_bpchar_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE            gbtreekey_var;
+
+
+--
+--
+-- bytea ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_bytea_consistent(internal,bytea,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bytea_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bytea_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bytea_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bytea_union(internal, internal)
+RETURNS gbtreekey_var
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bytea_same(gbtreekey_var, gbtreekey_var, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bytea_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_bytea_ops
+DEFAULT FOR TYPE bytea USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_bytea_consistent (internal, bytea, int2, oid, internal),
+    FUNCTION    2    gbt_bytea_union (internal, internal),
+    FUNCTION    3    gbt_bytea_compress (internal),
+    FUNCTION    4    gbt_var_decompress (internal),
+    FUNCTION    5    gbt_bytea_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_bytea_picksplit (internal, internal),
+    FUNCTION    7    gbt_bytea_same (gbtreekey_var, gbtreekey_var, internal),
+    FUNCTION    9    gbt_var_fetch (internal),
+    FUNCTION    11    gbt_bytea_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE            gbtreekey_var;
+
+
+--
+--
+--
+-- numeric ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_numeric_consistent(internal,numeric,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_numeric_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_numeric_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_numeric_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_numeric_union(internal, internal)
+RETURNS gbtreekey_var
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_numeric_same(gbtreekey_var, gbtreekey_var, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_numeric_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_numeric_ops
+DEFAULT FOR TYPE numeric USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_numeric_consistent (internal, numeric, int2, oid, internal),
+    FUNCTION    2    gbt_numeric_union (internal, internal),
+    FUNCTION    3    gbt_numeric_compress (internal),
+    FUNCTION    4    gbt_var_decompress (internal),
+    FUNCTION    5    gbt_numeric_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_numeric_picksplit (internal, internal),
+    FUNCTION    7    gbt_numeric_same (gbtreekey_var, gbtreekey_var, internal),
+    FUNCTION    9    gbt_var_fetch (internal),
+    FUNCTION    11    gbt_numeric_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE            gbtreekey_var;
+
+
+--
+--
+-- bit ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_bit_consistent(internal,bit,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bit_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bit_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bit_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bit_union(internal, internal)
+RETURNS gbtreekey_var
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bit_same(gbtreekey_var, gbtreekey_var, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bit_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_varbit_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_bit_ops
+DEFAULT FOR TYPE bit USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_bit_consistent (internal, bit, int2, oid, internal),
+    FUNCTION    2    gbt_bit_union (internal, internal),
+    FUNCTION    3    gbt_bit_compress (internal),
+    FUNCTION    4    gbt_var_decompress (internal),
+    FUNCTION    5    gbt_bit_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_bit_picksplit (internal, internal),
+    FUNCTION    7    gbt_bit_same (gbtreekey_var, gbtreekey_var, internal),
+    FUNCTION    9    gbt_var_fetch (internal),
+    FUNCTION    11    gbt_bit_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE            gbtreekey_var;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_vbit_ops
+DEFAULT FOR TYPE varbit USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_bit_consistent (internal, bit, int2, oid, internal),
+    FUNCTION    2    gbt_bit_union (internal, internal),
+    FUNCTION    3    gbt_bit_compress (internal),
+    FUNCTION    4    gbt_var_decompress (internal),
+    FUNCTION    5    gbt_bit_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_bit_picksplit (internal, internal),
+    FUNCTION    7    gbt_bit_same (gbtreekey_var, gbtreekey_var, internal),
+    FUNCTION    9    gbt_var_fetch (internal),
+    FUNCTION    11    gbt_varbit_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE            gbtreekey_var;
+
+
+--
+--
+--
+-- inet/cidr ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_inet_consistent(internal,inet,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_inet_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_inet_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_inet_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_inet_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_inet_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_inet_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class (intentionally not DEFAULT)
+CREATE OPERATOR CLASS gist_inet_ops
+FOR TYPE inet USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_inet_consistent (internal, inet, int2, oid, internal),
+    FUNCTION    2    gbt_inet_union (internal, internal),
+    FUNCTION    3    gbt_inet_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_inet_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_inet_picksplit (internal, internal),
+    FUNCTION    7    gbt_inet_same (gbtreekey16, gbtreekey16, internal),
+    -- no fetch support, the compress function is lossy
+    FUNCTION    11    gbt_inet_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+-- Create the operator class (intentionally not DEFAULT)
+CREATE OPERATOR CLASS gist_cidr_ops
+FOR TYPE cidr USING gist
+AS
+    OPERATOR    1    <  (inet, inet) ,
+    OPERATOR    2    <= (inet, inet) ,
+    OPERATOR    3    =  (inet, inet) ,
+    OPERATOR    4    >= (inet, inet) ,
+    OPERATOR    5    >  (inet, inet) ,
+    OPERATOR    6    <> (inet, inet) ,
+    FUNCTION    1    gbt_inet_consistent (internal, inet, int2, oid, internal),
+    FUNCTION    2    gbt_inet_union (internal, internal),
+    FUNCTION    3    gbt_inet_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_inet_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_inet_picksplit (internal, internal),
+    FUNCTION    7    gbt_inet_same (gbtreekey16, gbtreekey16, internal),
+    -- no fetch support, the compress function is lossy
+    FUNCTION    11    gbt_inet_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- uuid ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_uuid_consistent(internal,uuid,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_uuid_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_uuid_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_uuid_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_uuid_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_uuid_union(internal, internal)
+RETURNS gbtreekey32
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_uuid_same(gbtreekey32, gbtreekey32, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_uuid_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_uuid_ops
+DEFAULT FOR TYPE uuid USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_uuid_consistent (internal, uuid, int2, oid, internal),
+    FUNCTION    2    gbt_uuid_union (internal, internal),
+    FUNCTION    3    gbt_uuid_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_uuid_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_uuid_picksplit (internal, internal),
+    FUNCTION    7    gbt_uuid_same (gbtreekey32, gbtreekey32, internal),
+    FUNCTION    9    gbt_uuid_fetch (internal),
+    FUNCTION    11    gbt_uuid_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey32;
+
+
+--
+--
+--
+-- macaddr8 ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_macad8_consistent(internal,macaddr8,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad8_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad8_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad8_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad8_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad8_union(internal, internal)
+RETURNS gbtreekey16
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad8_same(gbtreekey16, gbtreekey16, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_macad8_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_macaddr8_ops
+DEFAULT FOR TYPE macaddr8 USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_macad8_consistent (internal, macaddr8, int2, oid, internal),
+    FUNCTION    2    gbt_macad8_union (internal, internal),
+    FUNCTION    3    gbt_macad8_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_macad8_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_macad8_picksplit (internal, internal),
+    FUNCTION    7    gbt_macad8_same (gbtreekey16, gbtreekey16, internal),
+    FUNCTION    9    gbt_macad8_fetch (internal),
+    FUNCTION    11    gbt_macad8_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey16;
+
+
+--
+--
+--
+-- enum ops
+--
+--
+--
+-- define the GiST support methods
+CREATE FUNCTION gbt_enum_consistent(internal,anyenum,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_enum_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_enum_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_enum_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_enum_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_enum_union(internal, internal)
+RETURNS gbtreekey8
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_enum_same(gbtreekey8, gbtreekey8, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_enum_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_enum_ops
+DEFAULT FOR TYPE anyenum USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_enum_consistent (internal, anyenum, int2, oid, internal),
+    FUNCTION    2    gbt_enum_union (internal, internal),
+    FUNCTION    3    gbt_enum_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_enum_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_enum_picksplit (internal, internal),
+    FUNCTION    7    gbt_enum_same (gbtreekey8, gbtreekey8, internal),
+    FUNCTION    9    gbt_enum_fetch (internal),
+    FUNCTION    11    gbt_enum_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey8;
+
+
+--
+--
+--
+-- bool ops
+--
+--
+--
+-- Define the GiST support methods
+CREATE FUNCTION gbt_bool_consistent(internal,bool,int2,oid,internal)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bool_compress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bool_fetch(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bool_penalty(internal,internal,internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bool_picksplit(internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bool_union(internal, internal)
+RETURNS gbtreekey2
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bool_same(gbtreekey2, gbtreekey2, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION gbt_bool_sortsupport(internal)
+RETURNS void
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+-- Create the operator class
+CREATE OPERATOR CLASS gist_bool_ops
+DEFAULT FOR TYPE bool USING gist
+AS
+    OPERATOR    1    <  ,
+    OPERATOR    2    <= ,
+    OPERATOR    3    =  ,
+    OPERATOR    4    >= ,
+    OPERATOR    5    >  ,
+    OPERATOR    6    <> ,
+    FUNCTION    1    gbt_bool_consistent (internal, bool, int2, oid, internal),
+    FUNCTION    2    gbt_bool_union (internal, internal),
+    FUNCTION    3    gbt_bool_compress (internal),
+    FUNCTION    4    gbt_decompress (internal),
+    FUNCTION    5    gbt_bool_penalty (internal, internal, internal),
+    FUNCTION    6    gbt_bool_picksplit (internal, internal),
+    FUNCTION    7    gbt_bool_same (gbtreekey2, gbtreekey2, internal),
+    FUNCTION    9    gbt_bool_fetch (internal),
+    FUNCTION    11    gbt_bool_sortsupport (internal),
+    FUNCTION    12 ("any", "any") gist_translate_cmptype_btree (int),
+    STORAGE        gbtreekey2;
diff --git a/contrib/btree_gist/meson.build b/contrib/btree_gist/meson.build
index f4fa9574f1f..b3e3e754388 100644
--- a/contrib/btree_gist/meson.build
+++ b/contrib/btree_gist/meson.build
@@ -51,6 +51,8 @@ install_data(
   'btree_gist--1.5--1.6.sql',
   'btree_gist--1.6--1.7.sql',
   'btree_gist--1.7--1.8.sql',
+  'btree_gist--1.8--1.9.sql',
+  'btree_gist--1.9.sql',
   kwargs: contrib_data_args,
 )

--
2.43.7

From baa37652ed46d252264cdf8e2db8b56db3c855b5 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 18 Dec 2025 15:45:19 -0500
Subject: [PATCH v2 2/3] Mark btree_gist 1.9 as the default version.

This requires adjusting the module's inet and cidr tests to select
the now not-default opclasses explicitly.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2483812.1754072263@sss.pgh.pa.us
---
 contrib/btree_gist/btree_gist.control | 2 +-
 contrib/btree_gist/expected/cidr.out  | 2 +-
 contrib/btree_gist/expected/inet.out  | 2 +-
 contrib/btree_gist/sql/cidr.sql       | 2 +-
 contrib/btree_gist/sql/inet.sql       | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/contrib/btree_gist/btree_gist.control b/contrib/btree_gist/btree_gist.control
index abf66538f32..69d9341a0ad 100644
--- a/contrib/btree_gist/btree_gist.control
+++ b/contrib/btree_gist/btree_gist.control
@@ -1,6 +1,6 @@
 # btree_gist extension
 comment = 'support for indexing common datatypes in GiST'
-default_version = '1.8'
+default_version = '1.9'
 module_pathname = '$libdir/btree_gist'
 relocatable = true
 trusted = true
diff --git a/contrib/btree_gist/expected/cidr.out b/contrib/btree_gist/expected/cidr.out
index 6d0995add60..e61df27affc 100644
--- a/contrib/btree_gist/expected/cidr.out
+++ b/contrib/btree_gist/expected/cidr.out
@@ -32,7 +32,7 @@ SELECT count(*) FROM cidrtmp WHERE a >  '121.111.63.82';
    309
 (1 row)

-CREATE INDEX cidridx ON cidrtmp USING gist ( a );
+CREATE INDEX cidridx ON cidrtmp USING gist ( a gist_cidr_ops );
 SET enable_seqscan=off;
 SELECT count(*) FROM cidrtmp WHERE a <  '121.111.63.82'::cidr;
  count
diff --git a/contrib/btree_gist/expected/inet.out b/contrib/btree_gist/expected/inet.out
index f15f1435f0a..8cf12e3df8e 100644
--- a/contrib/btree_gist/expected/inet.out
+++ b/contrib/btree_gist/expected/inet.out
@@ -32,7 +32,7 @@ SELECT count(*) FROM inettmp WHERE a >  '89.225.196.191';
    386
 (1 row)

-CREATE INDEX inetidx ON inettmp USING gist ( a );
+CREATE INDEX inetidx ON inettmp USING gist ( a gist_inet_ops );
 SET enable_seqscan=off;
 SELECT count(*) FROM inettmp WHERE a <  '89.225.196.191'::inet;
  count
diff --git a/contrib/btree_gist/sql/cidr.sql b/contrib/btree_gist/sql/cidr.sql
index 9bd77185b96..ec1529e3e04 100644
--- a/contrib/btree_gist/sql/cidr.sql
+++ b/contrib/btree_gist/sql/cidr.sql
@@ -15,7 +15,7 @@ SELECT count(*) FROM cidrtmp WHERE a >= '121.111.63.82';

 SELECT count(*) FROM cidrtmp WHERE a >  '121.111.63.82';

-CREATE INDEX cidridx ON cidrtmp USING gist ( a );
+CREATE INDEX cidridx ON cidrtmp USING gist ( a gist_cidr_ops );

 SET enable_seqscan=off;

diff --git a/contrib/btree_gist/sql/inet.sql b/contrib/btree_gist/sql/inet.sql
index 249e8085c3b..0bb73c9d715 100644
--- a/contrib/btree_gist/sql/inet.sql
+++ b/contrib/btree_gist/sql/inet.sql
@@ -16,7 +16,7 @@ SELECT count(*) FROM inettmp WHERE a >= '89.225.196.191';

 SELECT count(*) FROM inettmp WHERE a >  '89.225.196.191';

-CREATE INDEX inetidx ON inettmp USING gist ( a );
+CREATE INDEX inetidx ON inettmp USING gist ( a gist_inet_ops );

 SET enable_seqscan=off;

--
2.43.7

From 19eb84d9d9aca2bf24ebc8bd8068d77881def730 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 19 Dec 2025 12:40:03 -0500
Subject: [PATCH v2 3/3] Mark GiST inet_ops as opcdefault, and deal with
 ensuing fallout.

This patch completes the transition to making inet_ops be default for
inet/cidr columns, rather than btree_gist's opclasses.  Once we do
that, though, pg_upgrade has a big problem.  A dump from an older
version will see btree_gist's opclasses as being default, so it will
not mention the opclass explicitly in CREATE INDEX commands, which
would cause the restore to create the indexes using inet_ops.  Since
that's not compatible with what's actually in the files, havoc would
ensue.

This isn't readily fixable, because the CREATE INDEX command strings
are built by the older server's pg_get_indexdef() function; pg_dump
hasn't nearly enough knowledge to modify those strings successfully.
Even if we cared to put in the work to make that happen in pg_dump,
it would be counterproductive because the end goal here is to get
people off of these opclasses.  Allowing such indexes to persist
through pg_upgrade wouldn't advance that goal.

Therefore, this patch just adds code to pg_upgrade to detect indexes
that would be problematic and refuse to upgrade.

There's another issue too: even without any indexes to worry about,
pg_dump in binary-upgrade mode will reproduce the "CREATE OPERATOR
CLASS ... DEFAULT" commands for btree_gist's opclasses, and those
will fail because now we have a built-in opclass that provides a
conflicting default.  We could ask users to drop the btree_gist
extension altogether before upgrading, but that would carry very
severe penalties.  It would affect perfectly-valid indexes for other
data types, and it would drop operators that might be relied on in
views or other database objects.  Instead, put a hack in DefineOpClass
to ignore the DEFAULT clauses for these opclasses when in
binary-upgrade mode.  This will result in installing a version of
btree_gist that isn't quite the version it claims to be, but that can
be fixed by issuing ALTER EXTENSION UPDATE afterwards.

Since we don't apply that hack when not in binary-upgrade mode,
it is now impossible to install any version of btree_gist less than
1.9 into a v19-or-later server.  We could drop the btree_gist--1.2.sql
script altogether, although I've not included that in this patch.
But we must keep the subsequent delta scripts, so that users can
bring an old version of btree_gist up to 1.9.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2483812.1754072263@sss.pgh.pa.us
---
 doc/src/sgml/btree-gist.sgml                  | 47 ++++++++++
 src/backend/commands/opclasscmds.c            | 24 ++++-
 src/bin/pg_upgrade/check.c                    | 93 +++++++++++++++++++
 src/include/catalog/pg_opclass.dat            |  2 +-
 .../perl/PostgreSQL/Test/AdjustUpgrade.pm     | 23 +++++
 5 files changed, 186 insertions(+), 3 deletions(-)

diff --git a/doc/src/sgml/btree-gist.sgml b/doc/src/sgml/btree-gist.sgml
index a4c1b99be1f..41df635fd5e 100644
--- a/doc/src/sgml/btree-gist.sgml
+++ b/doc/src/sgml/btree-gist.sgml
@@ -108,6 +108,53 @@ INSERT 0 1

  </sect2>

+ <sect2 id="btree-gist-inet-indexes">
+  <title><literal>btree_gist</literal> Indexes
+   on <type>inet</type>/<type>cidr</type> Columns</title>
+
+  <para>
+   The <literal>gist_inet_ops</literal> and <literal>gist_cidr_ops</literal>
+   operator classes provided by <literal>btree_gist</literal> have been
+   shown to be unreliable: index searches may find the wrong rows due to
+   approximations used in creating the index entries.  This is unfixable
+   without redefining the contents of indexes that use these opclasses.
+   Therefore, these opclasses are being deprecated in favor of the built-in
+   GiST <literal>inet_ops</literal> opclass, which does not share the design
+   flaw.
+  </para>
+
+  <para>
+   As a first step, <productname>PostgreSQL</productname> version 19 removes
+   the default-opclass marking from <literal>gist_inet_ops</literal>
+   and <literal>gist_cidr_ops</literal>, instead
+   marking <literal>inet_ops</literal> as default for <type>inet</type>
+   and <type>cidr</type> columns.  This will result in transparently
+   substituting <literal>inet_ops</literal> for the faulty opclasses in most
+   contexts.  It is still possible to create indexes using the faulty
+   opclasses, if really necessary, by explicitly specifying which opclass to
+   use; for example
+<programlisting>
+CREATE TABLE mytable (addr inet);
+CREATE INDEX dubious_index ON mytable USING GIST (addr gist_inet_ops);
+</programlisting>
+  </para>
+
+  <para>
+   However, <application>pg_upgrade</application> cannot handle this change
+   due to implementation limitations.  If asked to upgrade a pre-v19
+   database that contains <literal>gist_inet_ops</literal>
+   or <literal>gist_cidr_ops</literal>
+   indexes, <application>pg_upgrade</application> will fail and tell you to
+   replace those indexes before upgrading.  This would look approximately
+   like
+<programlisting>
+CREATE INDEX good_index ON mytable USING GIST (addr inet_ops);
+DROP INDEX bad_index;
+</programlisting>
+  </para>
+
+ </sect2>
+
  <sect2 id="btree-gist-authors">
   <title>Authors</title>

diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index 992ae789b00..d0421cf0162 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -343,6 +343,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
                 optsProcNumber, /* amoptsprocnum value */
                 maxProcNumber;    /* amsupport value */
     bool        amstorage;        /* amstorage flag */
+    bool        isDefault = stmt->isDefault;
     List       *operators;        /* OpFamilyMember list for operators */
     List       *procedures;        /* OpFamilyMember list for support procs */
     ListCell   *l;
@@ -610,12 +611,31 @@ DefineOpClass(CreateOpClassStmt *stmt)
                  errmsg("operator class \"%s\" for access method \"%s\" already exists",
                         opcname, stmt->amname)));

+    /*
+     * HACK: if we're trying to create btree_gist's gist_inet_ops or
+     * gist_cidr_ops during a binary upgrade, avoid failure in the next stanza
+     * by silently making the new opclass non-default.  Without this kluge, we
+     * would fail to upgrade databases containing pre-1.9 versions of
+     * contrib/btree_gist.  We can remove it sometime in the far future when
+     * we don't expect any such databases to exist.  (The result of this hack
+     * is that the installed version of btree_gist will approximate btree_gist
+     * 1.9, how closely depending on whether it's 1.8 or something older.
+     * ALTER EXTENSION UPDATE can be used to bring it up to real 1.9.)
+     */
+    if (isDefault && IsBinaryUpgrade)
+    {
+        if (amoid == GIST_AM_OID &&
+            ((typeoid == INETOID && strcmp(opcname, "gist_inet_ops") == 0) ||
+             (typeoid == CIDROID && strcmp(opcname, "gist_cidr_ops") == 0)))
+            isDefault = false;
+    }
+
     /*
      * If we are creating a default opclass, check there isn't one already.
      * (Note we do not restrict this test to visible opclasses; this ensures
      * that typcache.c can find unique solutions to its questions.)
      */
-    if (stmt->isDefault)
+    if (isDefault)
     {
         ScanKeyData skey[1];
         SysScanDesc scan;
@@ -661,7 +681,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
     values[Anum_pg_opclass_opcowner - 1] = ObjectIdGetDatum(GetUserId());
     values[Anum_pg_opclass_opcfamily - 1] = ObjectIdGetDatum(opfamilyoid);
     values[Anum_pg_opclass_opcintype - 1] = ObjectIdGetDatum(typeoid);
-    values[Anum_pg_opclass_opcdefault - 1] = BoolGetDatum(stmt->isDefault);
+    values[Anum_pg_opclass_opcdefault - 1] = BoolGetDatum(isDefault);
     values[Anum_pg_opclass_opckeytype - 1] = ObjectIdGetDatum(storageoid);

     tup = heap_form_tuple(rel->rd_att, values, nulls);
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 1e17d64b3ec..48fecefc626 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -9,6 +9,7 @@

 #include "postgres_fe.h"

+#include "catalog/pg_am_d.h"
 #include "catalog/pg_authid_d.h"
 #include "catalog/pg_class_d.h"
 #include "fe_utils/string_utils.h"
@@ -24,6 +25,7 @@ static void check_for_user_defined_postfix_ops(ClusterInfo *cluster);
 static void check_for_incompatible_polymorphics(ClusterInfo *cluster);
 static void check_for_tables_with_oids(ClusterInfo *cluster);
 static void check_for_not_null_inheritance(ClusterInfo *cluster);
+static void check_for_gist_inet_ops(ClusterInfo *cluster);
 static void check_for_pg_role_prefix(ClusterInfo *cluster);
 static void check_for_new_tablespace_dir(void);
 static void check_for_user_defined_encoding_conversions(ClusterInfo *cluster);
@@ -681,6 +683,21 @@ check_and_dump_old_cluster(void)
     if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1800)
         check_for_not_null_inheritance(&old_cluster);

+    /*
+     * The btree_gist extension contains gist_inet_ops and gist_cidr_ops
+     * opclasses that do not reliably give correct answers.  We want to
+     * deprecate and eventually remove those, and as a first step v19 marks
+     * them not-opcdefault and instead marks the replacement in-core opclass
+     * "inet_ops" as opcdefault.  That creates a problem for pg_upgrade: in
+     * versions where those opclasses were marked opcdefault, pg_dump will
+     * dump indexes using them with no explicit opclass specification, so that
+     * restore would create them using the inet_ops opclass.  That would be
+     * incompatible with what's actually in the on-disk files.  So refuse to
+     * upgrade if there are any such indexes.
+     */
+    if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1800)
+        check_for_gist_inet_ops(&old_cluster);
+
     /*
      * Pre-PG 10 allowed tables with 'unknown' type columns and non WAL logged
      * hash indexes
@@ -1721,6 +1738,82 @@ check_for_not_null_inheritance(ClusterInfo *cluster)
         check_ok();
 }

+/*
+ * Callback function for processing results of query for
+ * check_for_gist_inet_ops()'s UpgradeTask.  If the query returned any rows
+ * (i.e., the check failed), write the details to the report file.
+ */
+static void
+process_gist_inet_ops_check(DbInfo *dbinfo, PGresult *res, void *arg)
+{
+    UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
+    int            ntups = PQntuples(res);
+    int            i_nspname = PQfnumber(res, "nspname");
+    int            i_relname = PQfnumber(res, "relname");
+
+    AssertVariableIsOfType(&process_gist_inet_ops_check, UpgradeTaskProcessCB);
+
+    if (ntups == 0)
+        return;
+
+    if (report->file == NULL &&
+        (report->file = fopen_priv(report->path, "w")) == NULL)
+        pg_fatal("could not open file \"%s\": %m", report->path);
+
+    fprintf(report->file, "In database: %s\n", dbinfo->db_name);
+
+    for (int rowno = 0; rowno < ntups; rowno++)
+        fprintf(report->file, "  %s.%s\n",
+                PQgetvalue(res, rowno, i_nspname),
+                PQgetvalue(res, rowno, i_relname));
+}
+
+/*
+ * Verify that no indexes use gist_inet_ops/gist_cidr_ops, unless the
+ * opclasses have been changed to not-opcdefault (which would allow
+ * the old server to dump the index definitions with explicit opclasses).
+ */
+static void
+check_for_gist_inet_ops(ClusterInfo *cluster)
+{
+    UpgradeTaskReport report;
+    UpgradeTask *task = upgrade_task_create();
+    const char *query = "SELECT nc.nspname, cc.relname "
+        "FROM   pg_catalog.pg_opclass oc, pg_catalog.pg_index i, "
+        "       pg_catalog.pg_class cc, pg_catalog.pg_namespace nc "
+        "WHERE  oc.opcmethod = " CppAsString2(GIST_AM_OID)
+        "       AND oc.opcname IN ('gist_inet_ops', 'gist_cidr_ops')"
+        "       AND oc.opcdefault"
+        "       AND oc.oid = any(i.indclass)"
+        "       AND i.indexrelid = cc.oid AND cc.relnamespace = nc.oid";
+
+    prep_status("Checking for uses of gist_inet_ops/gist_cidr_ops");
+
+    report.file = NULL;
+    snprintf(report.path, sizeof(report.path), "%s/%s",
+             log_opts.basedir,
+             "gist_inet_ops.txt");
+
+    upgrade_task_add_step(task, query, process_gist_inet_ops_check,
+                          true, &report);
+    upgrade_task_run(task, cluster);
+    upgrade_task_free(task);
+
+    if (report.file)
+    {
+        fclose(report.file);
+        pg_log(PG_REPORT, "fatal");
+        pg_fatal("Your installation contains indexes that use btree_gist's\n"
+                 "gist_inet_ops or gist_cidr_ops opclasses,\n"
+                 "which cannot be binary-upgraded.  Replace them with indexes\n"
+                 "that use the built-in GiST inet_ops opclass.\n"
+                 "A list of indexes with the problem is in the file:\n"
+                 "    %s", report.path);
+    }
+    else
+        check_ok();
+}
+
 /*
  * check_for_pg_role_prefix()
  *
diff --git a/src/include/catalog/pg_opclass.dat b/src/include/catalog/pg_opclass.dat
index 4a9624802aa..4b2c3a52403 100644
--- a/src/include/catalog/pg_opclass.dat
+++ b/src/include/catalog/pg_opclass.dat
@@ -57,7 +57,7 @@
 { opcmethod => 'hash', opcname => 'inet_ops', opcfamily => 'hash/network_ops',
   opcintype => 'inet' },
 { opcmethod => 'gist', opcname => 'inet_ops', opcfamily => 'gist/network_ops',
-  opcintype => 'inet', opcdefault => 'f' },
+  opcintype => 'inet' },
 { opcmethod => 'spgist', opcname => 'inet_ops',
   opcfamily => 'spgist/network_ops', opcintype => 'inet' },
 { oid => '1979', oid_symbol => 'INT2_BTREE_OPS_OID',
diff --git a/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm b/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
index 7224c286e1d..1316984ce3d 100644
--- a/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
+++ b/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
@@ -112,6 +112,29 @@ sub adjust_database_contents
             'drop extension if exists test_ext7');
     }

+    # btree_gist inet/cidr indexes cannot be upgraded to v19
+    if ($old_version < 19)
+    {
+        if ($dbnames{"contrib_regression_btree_gist"})
+        {
+            _add_st($result, 'contrib_regression_btree_gist',
+                "drop index if exists public.inettmp_a_a1_idx");
+            _add_st($result, 'contrib_regression_btree_gist',
+                "drop index if exists public.inetidx");
+            _add_st($result, 'contrib_regression_btree_gist',
+                "drop index public.cidridx");
+        }
+        if ($dbnames{"regression_btree_gist"})
+        {
+            _add_st($result, 'regression_btree_gist',
+                "drop index if exists public.inettmp_a_a1_idx");
+            _add_st($result, 'regression_btree_gist',
+                "drop index if exists public.inetidx");
+            _add_st($result, 'regression_btree_gist',
+                "drop index public.cidridx");
+        }
+    }
+
     # we removed these test-support functions in v18
     if ($old_version < 18)
     {
--
2.43.7


Re: Fixing the btree_gist inet mess

От
Matthias van de Meent
Дата:
On Fri, 19 Dec 2025 at 19:27, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Here's a v2 patchset that tries to address all the discussion so far.

Thanks!

> [...]
> Because I didn't change DefineOpClass's behavior when
> !IsBinaryUpgrade, any attempt to install a pre-1.9 version of
> btree_gist will now fail.  So we could remove btree_gist--1.2.sql
> as well as btree_gist--1.0--1.1.sql and btree_gist--1.1--1.2.sql
> without cost.  (I've not done that here, as it would just bloat the
> patchset some more.)  However we should keep btree_gist--1.2--1.3.sql
> and later delta scripts, so that users can update old definitions of
> the module to 1.9 after a pg_upgrade.

That all seems reasonable, yes.

> One point perhaps worth mentioning here is that it works to
> copy btree_gist--1.8--1.9.sql into a v18 installation and
> issue
>         ALTER EXTENSION btree_gist UPDATE TO '1.9';
> after which pg_upgrade will let you upgrade your old indexes
> without complaint, because pg_dump will now do the right things.
> I did not document this because (a) it does not work in anything
> before v18 due to lack of btree_gist 1.8, and (b) we don't want
> to encourage people to stay on the old opclasses in v19.

Agreed.

>  But
> perhaps somebody would find a reason to want to do this.

Yes, perhaps. I also hope nobody needs to reach for this.

> I'd probably squash all this into one commit at the end, but
> I made it into several patches for review purposes.

LGTM.


Kind regards,

Matthias van de Meent
Databricks (https://www.databricks.com)



Re: Fixing the btree_gist inet mess

От
Tom Lane
Дата:
Matthias van de Meent <boekewurm+postgres@gmail.com> writes:
> LGTM.

Pushed, thanks for reviewing.

            regards, tom lane