[fix](Nereids) toSql is not work well in non-query statement (#15752)
This commit is contained in:
@ -227,6 +227,8 @@ public class SlotRef extends Expr {
|
||||
return tblName.toSql() + "." + label;
|
||||
} else if (label != null) {
|
||||
if (ConnectContext.get() != null
|
||||
&& ConnectContext.get().getState().isNereids()
|
||||
&& !ConnectContext.get().getState().isQuery()
|
||||
&& ConnectContext.get().getSessionVariable() != null
|
||||
&& ConnectContext.get().getSessionVariable().isEnableNereidsPlanner()
|
||||
&& desc != null) {
|
||||
|
||||
@ -48,6 +48,7 @@ public class QueryState {
|
||||
private int warningRows = 0;
|
||||
// make it public for easy to use
|
||||
public int serverStatus = 0;
|
||||
public boolean isNereids = false;
|
||||
|
||||
public QueryState() {
|
||||
}
|
||||
@ -61,6 +62,7 @@ public class QueryState {
|
||||
isQuery = false;
|
||||
affectedRows = 0;
|
||||
warningRows = 0;
|
||||
isNereids = false;
|
||||
}
|
||||
|
||||
public MysqlStateType getStateType() {
|
||||
@ -136,6 +138,14 @@ public class QueryState {
|
||||
return warningRows;
|
||||
}
|
||||
|
||||
public void setNereids(boolean nereids) {
|
||||
isNereids = nereids;
|
||||
}
|
||||
|
||||
public boolean isNereids() {
|
||||
return isNereids;
|
||||
}
|
||||
|
||||
public MysqlPacket toResponsePacket() {
|
||||
MysqlPacket packet = null;
|
||||
switch (stateType) {
|
||||
|
||||
@ -94,6 +94,7 @@ import org.apache.doris.mysql.privilege.PrivPredicate;
|
||||
import org.apache.doris.nereids.NereidsPlanner;
|
||||
import org.apache.doris.nereids.StatementContext;
|
||||
import org.apache.doris.nereids.glue.LogicalPlanAdapter;
|
||||
import org.apache.doris.nereids.trees.plans.commands.Command;
|
||||
import org.apache.doris.planner.OlapScanNode;
|
||||
import org.apache.doris.planner.OriginalPlanner;
|
||||
import org.apache.doris.planner.Planner;
|
||||
@ -425,10 +426,18 @@ public class StmtExecutor implements ProfileWriter {
|
||||
context.setStmtId(STMT_ID_GENERATOR.incrementAndGet());
|
||||
context.setQueryId(queryId);
|
||||
// set isQuery first otherwise this state will be lost if some error occurs
|
||||
if (parsedStmt instanceof QueryStmt || parsedStmt instanceof LogicalPlanAdapter) {
|
||||
if (parsedStmt instanceof QueryStmt) {
|
||||
context.getState().setIsQuery(true);
|
||||
}
|
||||
|
||||
if (parsedStmt instanceof LogicalPlanAdapter) {
|
||||
context.getState().setNereids(true);
|
||||
if (parsedStmt.getExplainOptions() == null
|
||||
&& !(((LogicalPlanAdapter) parsedStmt).getLogicalPlan() instanceof Command)) {
|
||||
context.getState().setIsQuery(true);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (context.isTxnModel() && !(parsedStmt instanceof InsertStmt)
|
||||
&& !(parsedStmt instanceof TransactionStmt)) {
|
||||
@ -452,6 +461,7 @@ public class StmtExecutor implements ProfileWriter {
|
||||
// fall back to legacy planner
|
||||
LOG.warn("fall back to legacy planner, because: {}", e.getMessage(), e);
|
||||
parsedStmt = null;
|
||||
context.getState().setNereids(false);
|
||||
analyze(context.getSessionVariable().toThrift());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user