From f6279751e4248c2bf0a1767959e4e0aef05947d3 Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Mon, 9 Nov 2020 23:23:50 -0800 Subject: [PATCH] Don't grab in additional locks cstore code when truncating --- src/backend/columnar/cstore_fdw.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/columnar/cstore_fdw.c b/src/backend/columnar/cstore_fdw.c index 97e6f5a3c..ab8fa69e8 100644 --- a/src/backend/columnar/cstore_fdw.c +++ b/src/backend/columnar/cstore_fdw.c @@ -718,7 +718,7 @@ FindCStoreTables(List *tableList) foreach(relationCell, tableList) { RangeVar *rangeVar = (RangeVar *) lfirst(relationCell); - Oid relationId = RangeVarGetRelid(rangeVar, AccessShareLock, true); + Oid relationId = RangeVarGetRelid(rangeVar, NoLock, true); if (IsCStoreFdwTable(relationId) && !DistributedTable(relationId)) { cstoreTableList = lappend(cstoreTableList, rangeVar); @@ -758,6 +758,16 @@ OpenRelationsForTruncate(List *cstoreTableList) { heap_close(relation, AccessExclusiveLock); } + /* + * Type of cstore tables can change since we checked last time, + * since we didn't hold a lock when checking. + */ + else if (!IsCStoreFdwTable(relationId)) + { + ereport(ERROR, (errmsg("relation \"%s\" not columnar anymore", + RelationGetRelationName(relation)), + errhint("try repeating the truncate command"))); + } else { relationIdList = lappend_oid(relationIdList, relationId);