Skip to content

Commit

Permalink
move lock position
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Sep 6, 2024
1 parent 27987d2 commit b204a0c
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ protected List<Plan> doRewrite(StructInfo queryStructInfo, CascadesContext casca
// Rewrite query by view
rewrittenPlan = rewriteQueryByView(matchMode, queryStructInfo, viewStructInfo, viewToQuerySlotMapping,
rewrittenPlan, materializationContext, cascadesContext);
// If rewrite successfully, try to get mv read lock to avoid data inconsistent,
// try to get lock which should added before RBO
if (materializationContext instanceof AsyncMaterializationContext && !materializationContext.isSuccess()) {
cascadesContext.getStatementContext()
.addTableReadLock(((AsyncMaterializationContext) materializationContext).getMtmv());
}
rewrittenPlan = MaterializedViewUtils.rewriteByRules(cascadesContext,
childContext -> {
Rewriter.getWholeTreeRewriter(childContext).execute();
Expand Down Expand Up @@ -356,12 +362,6 @@ protected List<Plan> doRewrite(StructInfo queryStructInfo, CascadesContext casca
rewriteResults.add(rewrittenPlan);
// if rewrite successfully, try to regenerate mv scan because it maybe used again
materializationContext.tryReGenerateScanPlan(cascadesContext);
// if rewrite successfully, try to get mv read lock to avoid data inconsistent
if (materializationContext instanceof AsyncMaterializationContext && !materializationContext.isSuccess()) {
// Need get mtmv read lock, to avoid the data of plan which use mv is wrong
cascadesContext.getStatementContext()
.addTableReadLock(((AsyncMaterializationContext) materializationContext).getMtmv());
}
recordIfRewritten(queryStructInfo.getOriginalPlan(), materializationContext);
}
return rewriteResults;
Expand Down

0 comments on commit b204a0c

Please sign in to comment.