ERROR: "ft1" is of the wrong type. - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject ERROR: "ft1" is of the wrong type.
Date
Msg-id 20210216.181415.368926598204753659.horikyota.ntt@gmail.com
Whole thread Raw
Responses Re: ERROR: "ft1" is of the wrong type.
List pgsql-hackers
Hello,

If I invoked a wrong ALTER TABLE command like this, I would see an
unexpected error.

=# ALTER TABLE <foreign table> ATTACH PARTITION ....
ERROR:  "ft1" is of the wrong type

The cause is that ATWrongRelkidError doesn't handle ATT_TABLE |
ATT_ATT_PARTITIONED_INDEX.

After checking all callers of ATSimplePermissions, I found that;

The two below are no longer used.

  ATT_TABLE | ATT_VIEW
  ATT_TABLE | ATT_MATVIEW | ATT_INDEX

The four below are not handled.

  ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX:
  ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX | ATT_FOREIGN_TABLE
  ATT_TABLE | ATT_PARTITIONED_INDEX:
  ATT_INDEX:

The attached is just fixing that.  I tried to make it generic but
didn't find a clean and translatable way.

Also I found that only three cases in the function are excecised by
make check.

ATT_TABLE                     : foreign_data, indexing checks 
ATT_TABLE | ATT_FOREIGN_TABLE : alter_table
ATT_TABLE | ATT_COMPOSITE_TYPE | ATT_FOREIGN_TABLE : alter_table

I'm not sure it's worth the trouble so the attached doesn't do
anything for that.


Versions back to PG11 have similar but different mistakes.

PG11, 12:
 the two below are not used
   ATT_TABLE | ATT_VIEW
   ATT_TABLE | ATT_MATVIEW | ATT_INDEX

 the two below are not handled
   ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX
   ATT_TABLE | ATT_PARTITIONED_INDEX

PG13:
 the two below are not used
   ATT_TABLE | ATT_VIEW
   ATT_TABLE | ATT_MATVIEW | ATT_INDEX

 the three below are not handled
   ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX
   ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX | ATT_FOREIGN_TABLE
   ATT_TABLE | ATT_PARTITIONED_INDEX

PG10:
  ATT_TABLE | ATT_VIEW is not used
  (all values are handled)

So the attached are the patches for PG11, 12, 13 and master.

It seems that the case lines in the function are intended to be in the
ATT_*'s definition order, but some of the them are out of that
order. However, I didn't reorder existing lines in the attached. I
didn't check the value itself is correct for the callers.

regareds.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a149ca044c..cf572a7c58 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -5063,9 +5063,6 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE:
             msg = _("\"%s\" is not a table");
             break;
-        case ATT_TABLE | ATT_VIEW:
-            msg = _("\"%s\" is not a table or view");
-            break;
         case ATT_TABLE | ATT_VIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, view, or foreign table");
             break;
@@ -5075,8 +5072,8 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW:
             msg = _("\"%s\" is not a table or materialized view");
             break;
-        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX:
-            msg = _("\"%s\" is not a table, materialized view, or index");
+        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table, materialized view, index, or partitioned index");
             break;
         case ATT_TABLE | ATT_MATVIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, or foreign table");
@@ -5090,6 +5087,9 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, index, or foreign table");
             break;
+        case ATT_TABLE | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table or partitioned index");
+            break;
         case ATT_VIEW:
             msg = _("\"%s\" is not a view");
             break;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 6f4a3e70a4..6c15a4e034 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -5350,9 +5350,6 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE:
             msg = _("\"%s\" is not a table");
             break;
-        case ATT_TABLE | ATT_VIEW:
-            msg = _("\"%s\" is not a table or view");
-            break;
         case ATT_TABLE | ATT_VIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, view, or foreign table");
             break;
@@ -5362,8 +5359,8 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW:
             msg = _("\"%s\" is not a table or materialized view");
             break;
-        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX:
-            msg = _("\"%s\" is not a table, materialized view, or index");
+        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table, materialized view, index, or partitioned index");
             break;
         case ATT_TABLE | ATT_MATVIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, or foreign table");
@@ -5377,6 +5374,9 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, index, or foreign table");
             break;
+        case ATT_TABLE | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table or partitioned index");
+            break;
         case ATT_VIEW:
             msg = _("\"%s\" is not a view");
             break;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index faba264135..fb49dbadc8 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -5627,9 +5627,6 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE:
             msg = _("\"%s\" is not a table");
             break;
-        case ATT_TABLE | ATT_VIEW:
-            msg = _("\"%s\" is not a table or view");
-            break;
         case ATT_TABLE | ATT_VIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, view, or foreign table");
             break;
@@ -5639,8 +5636,11 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW:
             msg = _("\"%s\" is not a table or materialized view");
             break;
-        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX:
-            msg = _("\"%s\" is not a table, materialized view, or index");
+        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table, materialized view, index, or partitioned index");
+            break;
+        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX | ATT_FOREIGN_TABLE:
+            msg = _("\"%s\" is not a table, materialized view, index, partitioned index, or foreign table");
             break;
         case ATT_TABLE | ATT_MATVIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, or foreign table");
@@ -5654,6 +5654,9 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, index, or foreign table");
             break;
+        case ATT_TABLE | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table or partitioned index");
+            break;
         case ATT_VIEW:
             msg = _("\"%s\" is not a view");
             break;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 420991e315..2b30dee333 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -5753,9 +5753,6 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE:
             msg = _("\"%s\" is not a table");
             break;
-        case ATT_TABLE | ATT_VIEW:
-            msg = _("\"%s\" is not a table or view");
-            break;
         case ATT_TABLE | ATT_VIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, view, or foreign table");
             break;
@@ -5765,9 +5762,12 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW:
             msg = _("\"%s\" is not a table or materialized view");
             break;
-        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX:
-            msg = _("\"%s\" is not a table, materialized view, or index");
+        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table, materialized view, index, or partitioned index");
             break;
+        case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX | ATT_FOREIGN_TABLE:
+            msg = _("\"%s\" is not a table, materialized view, index, partitioned index, or foreign table");
+             break;
         case ATT_TABLE | ATT_MATVIEW | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, or foreign table");
             break;
@@ -5780,9 +5780,15 @@ ATWrongRelkindError(Relation rel, int allowed_targets)
         case ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a table, materialized view, index, or foreign table");
             break;
+        case ATT_TABLE | ATT_PARTITIONED_INDEX:
+            msg = _("\"%s\" is not a table or partitioned index");
+            break;
         case ATT_VIEW:
             msg = _("\"%s\" is not a view");
             break;
+        case ATT_INDEX:
+            msg = _("\"%s\" is not an index");
+            break;
         case ATT_FOREIGN_TABLE:
             msg = _("\"%s\" is not a foreign table");
             break;

pgsql-hackers by date:

Previous
From: Takashi Menjo
Date:
Subject: Re: [PoC] Non-volatile WAL buffer
Next
From: David Rowley
Date:
Subject: Re: Tid scan improvements