From a4df52f95ff315dd10beca27cf93ff652be62153 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon, 3 Sep 2007 01:18:33 +0000
Subject: [PATCH] Fix breakage of GIN support for varchar[] and cidr[] that I
 introduced in the operator-family rewrite.  I had mistakenly supposed that
 these could use the pg_amproc entries for text[] and inet[] respectively. 
 However, binary compatibility of the underlying types does not make two array
 types binary compatible (since they must differ in the header field that
 gives the element type OID), and so the index support code doesn't consider
 those entries applicable.  Add back the missing pg_amproc entries, and add an
 opr_sanity query to try to catch such mistakes in future.  Per report from
 Gregory Maxwell.

---
 src/include/catalog/catversion.h         |  4 ++--
 src/include/catalog/pg_amproc.h          | 10 +++++++++-
 src/test/regress/expected/opr_sanity.out | 12 ++++++++++++
 src/test/regress/sql/opr_sanity.sql      | 10 ++++++++++
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index bd1970603e3..69de1ab8d76 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.420 2007/09/03 00:39:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.421 2007/09/03 01:18:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*							yyyymmddN */
-#define CATALOG_VERSION_NO	200709011
+#define CATALOG_VERSION_NO	200709021
 
 #endif
diff --git a/src/include/catalog/pg_amproc.h b/src/include/catalog/pg_amproc.h
index a89ed470606..d2a6aadb10a 100644
--- a/src/include/catalog/pg_amproc.h
+++ b/src/include/catalog/pg_amproc.h
@@ -22,7 +22,7 @@
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.67 2007/08/21 01:11:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.68 2007/09/03 01:18:33 tgl Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -214,6 +214,10 @@ DATA(insert (	2745   1009 1009 1  360 ));
 DATA(insert (	2745   1009 1009 2 2743 ));
 DATA(insert (	2745   1009 1009 3 2774 ));
 DATA(insert (	2745   1009 1009 4 2744 ));
+DATA(insert (	2745   1015 1015 1  360 ));
+DATA(insert (	2745   1015 1015 2 2743 ));
+DATA(insert (	2745   1015 1015 3 2774 ));
+DATA(insert (	2745   1015 1015 4 2744 ));
 DATA(insert (	2745   1023 1023 1 357 ));
 DATA(insert (	2745   1023 1023 2 2743 ));
 DATA(insert (	2745   1023 1023 3 2774 ));
@@ -254,6 +258,10 @@ DATA(insert (	2745   1041 1041 1 926 ));
 DATA(insert (	2745   1041 1041 2 2743 ));
 DATA(insert (	2745   1041 1041 3 2774 ));
 DATA(insert (	2745   1041 1041 4 2744 ));
+DATA(insert (	2745   651 651 1 926 ));
+DATA(insert (	2745   651 651 2 2743 ));
+DATA(insert (	2745   651 651 3 2774 ));
+DATA(insert (	2745   651 651 4 2744 ));
 DATA(insert (	2745   1005 1005 1 350 ));
 DATA(insert (	2745   1005 1005 2 2743 ));
 DATA(insert (	2745   1005 1005 3 2774 ));
diff --git a/src/test/regress/expected/opr_sanity.out b/src/test/regress/expected/opr_sanity.out
index a8aecd1dee6..b4d7d70d59c 100644
--- a/src/test/regress/expected/opr_sanity.out
+++ b/src/test/regress/expected/opr_sanity.out
@@ -940,6 +940,18 @@ WHERE p2.opfmethod = p1.oid AND p3.amprocfamily = p2.oid AND
 --------+---------+----------------+-----------------
 (0 rows)
 
+-- Also, check if there are any pg_opclass entries that don't seem to have
+-- pg_amproc support.
+SELECT amname, opcname, count(*)
+FROM pg_am am JOIN pg_opclass op ON opcmethod = am.oid
+     LEFT JOIN pg_amproc p ON amprocfamily = opcfamily AND
+         amproclefttype = amprocrighttype AND amproclefttype = opcintype
+GROUP BY amname, amsupport, opcname, amprocfamily
+HAVING count(*) != amsupport OR amprocfamily IS NULL;
+ amname | opcname | count 
+--------+---------+-------
+(0 rows)
+
 -- Unfortunately, we can't check the amproc link very well because the
 -- signature of the function may be different for different support routines
 -- or different base data types.
diff --git a/src/test/regress/sql/opr_sanity.sql b/src/test/regress/sql/opr_sanity.sql
index 54c60c1a6d9..037eb9e74db 100644
--- a/src/test/regress/sql/opr_sanity.sql
+++ b/src/test/regress/sql/opr_sanity.sql
@@ -751,6 +751,16 @@ WHERE p2.opfmethod = p1.oid AND p3.amprocfamily = p2.oid AND
                            p4.amproclefttype = p3.amproclefttype AND
                            p4.amprocrighttype = p3.amprocrighttype);
 
+-- Also, check if there are any pg_opclass entries that don't seem to have
+-- pg_amproc support.
+
+SELECT amname, opcname, count(*)
+FROM pg_am am JOIN pg_opclass op ON opcmethod = am.oid
+     LEFT JOIN pg_amproc p ON amprocfamily = opcfamily AND
+         amproclefttype = amprocrighttype AND amproclefttype = opcintype
+GROUP BY amname, amsupport, opcname, amprocfamily
+HAVING count(*) != amsupport OR amprocfamily IS NULL;
+
 -- Unfortunately, we can't check the amproc link very well because the
 -- signature of the function may be different for different support routines
 -- or different base data types.
-- 
GitLab