ERROR: "ft1" is of the wrong type.

Kyotaro Horiguchi <horikyota.ntt@gmail.com>

From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Date: 2021-02-16T09:14:15Z
Lists: pgsql-hackers

Attachments

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

Commits

  1. Fix unexpected error messages for various flavors of ALTER TABLE

  2. Revert per-index collation version tracking feature.

  3. Restructure ALTER TABLE execution to fix assorted bugs.