mirror of https://github.com/citusdata/citus.git
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
parent
5781aaf6c7
commit
a4f1c41391
|
@ -241,10 +241,7 @@ ExecuteLocalTaskListExtended(List *taskList,
|
||||||
if (localPlan != NULL)
|
if (localPlan != NULL)
|
||||||
{
|
{
|
||||||
Query *jobQuery = distributedPlan->workerJob->jobQuery;
|
Query *jobQuery = distributedPlan->workerJob->jobQuery;
|
||||||
LOCKMODE lockMode =
|
LOCKMODE lockMode = GetQueryLockMode(jobQuery);
|
||||||
IsModifyCommand(jobQuery) ? RowExclusiveLock : (jobQuery->hasForUpdate ?
|
|
||||||
RowShareLock :
|
|
||||||
AccessShareLock);
|
|
||||||
|
|
||||||
Oid relationId = InvalidOid;
|
Oid relationId = InvalidOid;
|
||||||
foreach_oid(relationId, localPlan->relationOids)
|
foreach_oid(relationId, localPlan->relationOids)
|
||||||
|
|
|
@ -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
|
* IsModifyCommand returns true if the query performs modifications, false
|
||||||
* otherwise.
|
* otherwise.
|
||||||
|
|
|
@ -61,9 +61,7 @@ CacheLocalPlanForShardQuery(Task *task, DistributedPlan *originalDistributedPlan
|
||||||
|
|
||||||
UpdateRelationsToLocalShardTables((Node *) shardQuery, task->relationShardList);
|
UpdateRelationsToLocalShardTables((Node *) shardQuery, task->relationShardList);
|
||||||
|
|
||||||
LOCKMODE lockMode =
|
LOCKMODE lockMode = GetQueryLockMode(shardQuery);
|
||||||
IsModifyCommand(shardQuery) ? RowExclusiveLock : (shardQuery->hasForUpdate ?
|
|
||||||
RowShareLock : AccessShareLock);
|
|
||||||
|
|
||||||
/* fast path queries can only have a single RTE by definition */
|
/* fast path queries can only have a single RTE by definition */
|
||||||
RangeTblEntry *rangeTableEntry = (RangeTblEntry *) linitial(shardQuery->rtable);
|
RangeTblEntry *rangeTableEntry = (RangeTblEntry *) linitial(shardQuery->rtable);
|
||||||
|
|
|
@ -203,6 +203,7 @@ extern Node * ResolveExternalParams(Node *inputNode, ParamListInfo boundParams);
|
||||||
extern bool IsMultiTaskPlan(struct DistributedPlan *distributedPlan);
|
extern bool IsMultiTaskPlan(struct DistributedPlan *distributedPlan);
|
||||||
extern RangeTblEntry * RemoteScanRangeTableEntry(List *columnNameList);
|
extern RangeTblEntry * RemoteScanRangeTableEntry(List *columnNameList);
|
||||||
extern int GetRTEIdentity(RangeTblEntry *rte);
|
extern int GetRTEIdentity(RangeTblEntry *rte);
|
||||||
|
extern LOCKMODE GetQueryLockMode(Query *query);
|
||||||
extern int32 BlessRecordExpression(Expr *expr);
|
extern int32 BlessRecordExpression(Expr *expr);
|
||||||
extern void DissuadePlannerFromUsingPlan(PlannedStmt *plan);
|
extern void DissuadePlannerFromUsingPlan(PlannedStmt *plan);
|
||||||
extern PlannedStmt * FinalizePlan(PlannedStmt *localPlan,
|
extern PlannedStmt * FinalizePlan(PlannedStmt *localPlan,
|
||||||
|
|
Loading…
Reference in New Issue