[fix](optimizer) Fix sql block when new optimizer is enabled (#23804)
The check would skipped since when checkBlockPolicy get invoked, new optimizer doesn't do plan yet
This commit is contained in:
@ -79,6 +79,7 @@ public class ExplainCommand extends Command implements NoForward {
|
||||
NereidsPlanner planner = new NereidsPlanner(ctx.getStatementContext());
|
||||
planner.plan(logicalPlanAdapter, ctx.getSessionVariable().toThrift());
|
||||
executor.setPlanner(planner);
|
||||
executor.checkBlockRules();
|
||||
executor.handleExplainStmt(planner.getExplainString(new ExplainOptions(level)));
|
||||
}
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync,
|
||||
LogicalPlanAdapter logicalPlanAdapter = new LogicalPlanAdapter(logicalQuery, ctx.getStatementContext());
|
||||
planner = new NereidsPlanner(ctx.getStatementContext());
|
||||
planner.plan(logicalPlanAdapter, ctx.getSessionVariable().toThrift());
|
||||
|
||||
executor.checkBlockRules();
|
||||
if (ctx.getMysqlChannel() != null) {
|
||||
ctx.getMysqlChannel().reset();
|
||||
}
|
||||
|
||||
@ -473,24 +473,32 @@ public class StmtExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkBlockRules() throws AnalysisException {
|
||||
if (originStmt != null) {
|
||||
Env.getCurrentEnv().getSqlBlockRuleMgr().matchSql(
|
||||
originStmt.originStmt, context.getSqlHash(), context.getQualifiedUser());
|
||||
}
|
||||
public void checkBlockRules() throws AnalysisException {
|
||||
checkBlockRulesByRegex(originStmt);
|
||||
checkBlockRulesByScan(planner);
|
||||
}
|
||||
|
||||
// limitations: partition_num, tablet_num, cardinality
|
||||
if (planner != null) {
|
||||
List<ScanNode> scanNodeList = planner.getScanNodes();
|
||||
for (ScanNode scanNode : scanNodeList) {
|
||||
if (scanNode instanceof OlapScanNode) {
|
||||
OlapScanNode olapScanNode = (OlapScanNode) scanNode;
|
||||
Env.getCurrentEnv().getSqlBlockRuleMgr().checkLimitations(
|
||||
olapScanNode.getSelectedPartitionNum().longValue(),
|
||||
olapScanNode.getSelectedTabletsNum(),
|
||||
olapScanNode.getCardinality(),
|
||||
context.getQualifiedUser());
|
||||
}
|
||||
public void checkBlockRulesByRegex(OriginStatement originStmt) throws AnalysisException {
|
||||
if (originStmt == null) {
|
||||
return;
|
||||
}
|
||||
Env.getCurrentEnv().getSqlBlockRuleMgr().matchSql(
|
||||
originStmt.originStmt, context.getSqlHash(), context.getQualifiedUser());
|
||||
}
|
||||
|
||||
public void checkBlockRulesByScan(Planner planner) throws AnalysisException {
|
||||
if (planner == null) {
|
||||
return;
|
||||
}
|
||||
List<ScanNode> scanNodeList = planner.getScanNodes();
|
||||
for (ScanNode scanNode : scanNodeList) {
|
||||
if (scanNode instanceof OlapScanNode) {
|
||||
OlapScanNode olapScanNode = (OlapScanNode) scanNode;
|
||||
Env.getCurrentEnv().getSqlBlockRuleMgr().checkLimitations(
|
||||
olapScanNode.getSelectedPartitionNum().longValue(),
|
||||
olapScanNode.getSelectedTabletsNum(),
|
||||
olapScanNode.getCardinality(),
|
||||
context.getQualifiedUser());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,7 +510,6 @@ public class StmtExecutor {
|
||||
profile.getSummaryProfile().setQueryBeginTime();
|
||||
context.setStmtId(STMT_ID_GENERATOR.incrementAndGet());
|
||||
|
||||
checkBlockRules();
|
||||
parseByNereids();
|
||||
Preconditions.checkState(parsedStmt instanceof LogicalPlanAdapter,
|
||||
"Nereids only process LogicalPlanAdapter, but parsedStmt is " + parsedStmt.getClass().getName());
|
||||
@ -556,6 +563,7 @@ public class StmtExecutor {
|
||||
planner = new NereidsPlanner(statementContext);
|
||||
try {
|
||||
planner.plan(parsedStmt, context.getSessionVariable().toThrift());
|
||||
checkBlockRules();
|
||||
} catch (Exception e) {
|
||||
LOG.debug("Nereids plan query failed:\n{}", originStmt.originStmt);
|
||||
throw new NereidsException(new AnalysisException(e.getMessage(), e));
|
||||
|
||||
Reference in New Issue
Block a user