Merge pull request #6048 from citusdata/relation-is-valid-check

we should check if relation is valid after fetching a relation
pull/6060/head
aykut-bozkurt 2022-07-06 22:49:35 +03:00 committed by GitHub
commit 79fd5eca8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 0 deletions

View File

@ -277,6 +277,11 @@ ColumnarSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti,
* into the scan of the table to minimize the data read. * into the scan of the table to minimize the data read.
*/ */
Relation relation = RelationIdGetRelation(rte->relid); Relation relation = RelationIdGetRelation(rte->relid);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", rte->relid)));
}
if (relation->rd_tableam == GetColumnarTableAmRoutine()) if (relation->rd_tableam == GetColumnarTableAmRoutine())
{ {
if (rte->tablesample != NULL) if (rte->tablesample != NULL)
@ -501,6 +506,11 @@ ColumnarIndexScanAdditionalCost(PlannerInfo *root, RelOptInfo *rel,
&indexCorrelation, &fakeIndexPages); &indexCorrelation, &fakeIndexPages);
Relation relation = RelationIdGetRelation(relationId); Relation relation = RelationIdGetRelation(relationId);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
uint64 rowCount = ColumnarTableRowCount(relation); uint64 rowCount = ColumnarTableRowCount(relation);
RelationClose(relation); RelationClose(relation);
double estimatedRows = rowCount * indexSelectivity; double estimatedRows = rowCount * indexSelectivity;
@ -596,6 +606,11 @@ static int
RelationIdGetNumberOfAttributes(Oid relationId) RelationIdGetNumberOfAttributes(Oid relationId)
{ {
Relation relation = RelationIdGetRelation(relationId); Relation relation = RelationIdGetRelation(relationId);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
int nattrs = relation->rd_att->natts; int nattrs = relation->rd_att->natts;
RelationClose(relation); RelationClose(relation);
return nattrs; return nattrs;
@ -1399,6 +1414,11 @@ static Cost
ColumnarPerStripeScanCost(RelOptInfo *rel, Oid relationId, int numberOfColumnsRead) ColumnarPerStripeScanCost(RelOptInfo *rel, Oid relationId, int numberOfColumnsRead)
{ {
Relation relation = RelationIdGetRelation(relationId); Relation relation = RelationIdGetRelation(relationId);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
List *stripeList = StripesForRelfilenode(relation->rd_node); List *stripeList = StripesForRelfilenode(relation->rd_node);
RelationClose(relation); RelationClose(relation);
@ -1451,6 +1471,11 @@ static uint64
ColumnarTableStripeCount(Oid relationId) ColumnarTableStripeCount(Oid relationId)
{ {
Relation relation = RelationIdGetRelation(relationId); Relation relation = RelationIdGetRelation(relationId);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
List *stripeList = StripesForRelfilenode(relation->rd_node); List *stripeList = StripesForRelfilenode(relation->rd_node);
int stripeCount = list_length(stripeList); int stripeCount = list_length(stripeList);
RelationClose(relation); RelationClose(relation);

View File

@ -857,6 +857,11 @@ static void
DropIndexesNotSupportedByColumnar(Oid relationId, bool suppressNoticeMessages) DropIndexesNotSupportedByColumnar(Oid relationId, bool suppressNoticeMessages)
{ {
Relation columnarRelation = RelationIdGetRelation(relationId); Relation columnarRelation = RelationIdGetRelation(relationId);
if (!RelationIsValid(columnarRelation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
List *indexIdList = RelationGetIndexList(columnarRelation); List *indexIdList = RelationGetIndexList(columnarRelation);
/* /*

View File

@ -891,6 +891,11 @@ static void
RenameShardRelationStatistics(Oid shardRelationId, uint64 shardId) RenameShardRelationStatistics(Oid shardRelationId, uint64 shardId)
{ {
Relation shardRelation = RelationIdGetRelation(shardRelationId); Relation shardRelation = RelationIdGetRelation(shardRelationId);
if (!RelationIsValid(shardRelation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", shardRelationId)));
}
List *statsOidList = RelationGetStatExtList(shardRelation); List *statsOidList = RelationGetStatExtList(shardRelation);
RelationClose(shardRelation); RelationClose(shardRelation);

View File

@ -321,6 +321,11 @@ ExecuteFunctionOnEachTableIndex(Oid relationId, PGIndexProcessor pgIndexProcesso
List *result = NIL; List *result = NIL;
Relation relation = RelationIdGetRelation(relationId); Relation relation = RelationIdGetRelation(relationId);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
List *indexIdList = RelationGetIndexList(relation); List *indexIdList = RelationGetIndexList(relation);
Oid indexId = InvalidOid; Oid indexId = InvalidOid;
foreach_oid(indexId, indexIdList) foreach_oid(indexId, indexIdList)

View File

@ -469,6 +469,11 @@ GetExplicitStatisticsCommandList(Oid relationId)
List *explicitStatisticsCommandList = NIL; List *explicitStatisticsCommandList = NIL;
Relation relation = RelationIdGetRelation(relationId); Relation relation = RelationIdGetRelation(relationId);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
List *statisticsIdList = RelationGetStatExtList(relation); List *statisticsIdList = RelationGetStatExtList(relation);
RelationClose(relation); RelationClose(relation);
@ -540,6 +545,11 @@ GetExplicitStatisticsSchemaIdList(Oid relationId)
List *schemaIdList = NIL; List *schemaIdList = NIL;
Relation relation = RelationIdGetRelation(relationId); Relation relation = RelationIdGetRelation(relationId);
if (!RelationIsValid(relation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", relationId)));
}
List *statsIdList = RelationGetStatExtList(relation); List *statsIdList = RelationGetStatExtList(relation);
RelationClose(relation); RelationClose(relation);

View File

@ -506,6 +506,11 @@ CreateFixPartitionShardIndexNamesTaskList(Oid parentRelationId, Oid partitionRel
} }
Relation parentRelation = RelationIdGetRelation(parentRelationId); Relation parentRelation = RelationIdGetRelation(parentRelationId);
if (!RelationIsValid(parentRelation))
{
ereport(ERROR, (errmsg("could not open relation with OID %u", parentRelationId)));
}
List *parentIndexIdList = NIL; List *parentIndexIdList = NIL;
if (parentIndexOid != InvalidOid) if (parentIndexOid != InvalidOid)