Implement GetQueryLockMode helper (#3860)

If we want to get necessary lockmode for a relation RangeVar within
a query, we can get the lockmode easily from the RangeVar itself (if
pg version >= 12).

However, if we want to decide the lockmode appropriate for the
"query", we can derive this information by using GetQueryLockMode
according to the code comment from RangeTblEntry->rellockmode.
pull/3881/head
Onur Tirtir 2020-06-09 13:08:44 +03:00 committed by GitHub
parent 5781aaf6c7
commit a4f1c41391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 7 deletions

View File

@ -241,10 +241,7 @@ ExecuteLocalTaskListExtended(List *taskList,
if (localPlan != NULL)
{
Query *jobQuery = distributedPlan->workerJob->jobQuery;
LOCKMODE lockMode =
IsModifyCommand(jobQuery) ? RowExclusiveLock : (jobQuery->hasForUpdate ?
RowShareLock :
AccessShareLock);
LOCKMODE lockMode = GetQueryLockMode(jobQuery);
Oid relationId = InvalidOid;
foreach_oid(relationId, localPlan->relationOids)

View File

@ -527,6 +527,28 @@ GetRTEIdentity(RangeTblEntry *rte)
}
/*
* GetQueryLockMode returns the necessary lock mode to be acquired for the
* given query. (See comment written in RangeTblEntry->rellockmode)
*/
LOCKMODE
GetQueryLockMode(Query *query)
{
if (IsModifyCommand(query))
{
return RowExclusiveLock;
}
else if (query->hasForUpdate)
{
return RowShareLock;
}
else
{
return AccessShareLock;
}
}
/*
* IsModifyCommand returns true if the query performs modifications, false
* otherwise.

View File

@ -61,9 +61,7 @@ CacheLocalPlanForShardQuery(Task *task, DistributedPlan *originalDistributedPlan
UpdateRelationsToLocalShardTables((Node *) shardQuery, task->relationShardList);
LOCKMODE lockMode =
IsModifyCommand(shardQuery) ? RowExclusiveLock : (shardQuery->hasForUpdate ?
RowShareLock : AccessShareLock);
LOCKMODE lockMode = GetQueryLockMode(shardQuery);
/* fast path queries can only have a single RTE by definition */
RangeTblEntry *rangeTableEntry = (RangeTblEntry *) linitial(shardQuery->rtable);

View File

@ -203,6 +203,7 @@ extern Node * ResolveExternalParams(Node *inputNode, ParamListInfo boundParams);
extern bool IsMultiTaskPlan(struct DistributedPlan *distributedPlan);
extern RangeTblEntry * RemoteScanRangeTableEntry(List *columnNameList);
extern int GetRTEIdentity(RangeTblEntry *rte);
extern LOCKMODE GetQueryLockMode(Query *query);
extern int32 BlessRecordExpression(Expr *expr);
extern void DissuadePlannerFromUsingPlan(PlannedStmt *plan);
extern PlannedStmt * FinalizePlan(PlannedStmt *localPlan,