Don't grab in additional locks cstore code when truncating

merge-cstore-pykello
Hadi Moshayedi 2020-11-09 23:23:50 -08:00
parent 5420dd6832
commit f6279751e4
1 changed files with 11 additions and 1 deletions

View File

@ -718,7 +718,7 @@ FindCStoreTables(List *tableList)
foreach(relationCell, tableList) foreach(relationCell, tableList)
{ {
RangeVar *rangeVar = (RangeVar *) lfirst(relationCell); RangeVar *rangeVar = (RangeVar *) lfirst(relationCell);
Oid relationId = RangeVarGetRelid(rangeVar, AccessShareLock, true); Oid relationId = RangeVarGetRelid(rangeVar, NoLock, true);
if (IsCStoreFdwTable(relationId) && !DistributedTable(relationId)) if (IsCStoreFdwTable(relationId) && !DistributedTable(relationId))
{ {
cstoreTableList = lappend(cstoreTableList, rangeVar); cstoreTableList = lappend(cstoreTableList, rangeVar);
@ -758,6 +758,16 @@ OpenRelationsForTruncate(List *cstoreTableList)
{ {
heap_close(relation, AccessExclusiveLock); 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 else
{ {
relationIdList = lappend_oid(relationIdList, relationId); relationIdList = lappend_oid(relationIdList, relationId);