ERROR: "ft1" is of the wrong type.

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: ERROR: "ft1" is of the wrong type.
Date: 2021-02-16 09:14:15
Message-ID: 20210216.181415.368926598204753659.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Attachment Content-Type Size
fix_ATWrongRelKindError_pg11.patch text/x-patch 1.5 KB
fix_ATWrongRelKindError_pg12.patch text/x-patch 1.5 KB
fix_ATWrongRelKindError_pg13.patch text/x-patch 1.7 KB
fix_ATWrongRelKindError.patch text/x-patch 1.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2021-02-16 09:22:41 Re: Tid scan improvements
Previous Message Takashi Menjo 2021-02-16 09:10:11 Re: [PoC] Non-volatile WAL buffer