On 2018/09/13 1:14, Tom Lane wrote: > Amit Langote <langote_amit...@lab.ntt.co.jp> writes: >> The infamous missing-relkind-check in heap_truncate() seems to be behind >> this. Perhaps, a patch like the attached will do? > > That seems excessively restrictive. Anything that has storage (e.g. > matviews) ought to be truncatable, no?
Not by heap_truncate it seems. The header comment of heap_truncate says that it concerns itself only with ON COMMIT truncation of temporary tables: /* * heap_truncate * * This routine deletes all data within all the specified relations. * * This is not transaction-safe! There is another, transaction-safe * implementation in commands/tablecmds.c. We now use this only for * ON COMMIT truncation of temporary tables, where it doesn't matter. */ ON COMMIT clause can only be used with temporary tables, so the only two possible relkind values that can be encountered here are RELKIND_RELATION and RELKIND_PARTITIONED_TABLE. Of the two, only the RELKIND_RELATION can have storage. > I thought we had a macro or utility function somewhere that knew which > relkinds have storage, though I can't find it right now. I'd be > inclined to instantiate that if it doesn't exist, and then the code > here ought to read something like > > if (RelkindHasStorage(rel->rd_rel->relkind)) > heap_truncate_one_rel(rel); There have been discussions (such as [1]), but none that led to some patch being committed. Might be a good idea to revive that discussion again, or perhaps there is already some solution being discussed on the pluggable storage thread. > Also, possibly the test ought to be inside heap_truncate_one_rel > rather than its callers? Hmm, perhaps. ExecuteTruncateGuts, the only other caller of heap_truncate_one_rel, also checks the relkind to skip partitioned tables. There seem to be reasons to do it in the caller in that case though, other than heap_truncate_one_rel being incapable of handling them. Thanks, Amit [1] Macros bundling RELKIND_* conditions https://www.postgresql.org/message-id/CAFjFpRcfzs%2Byst6YBCseD_orEcDNuAr9GUTraZ5GC%3DAvCYh55Q%40mail.gmail.com