Code review comment: ```suggestion                                 // here, doris do different with mysql. ```

Code under review:
public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Exception {
        if (MetricRepo.isInit) {
            MetricRepo.COUNTER_REQUEST_ALL.increase(1L);
            MetricRepo.increaseClusterRequestAll(ctx.getCloudCluster(false));
        }

        String convertedStmt = convertOriginStmt(originStmt);
        String sqlHash = DigestUtils.md5Hex(convertedStmt);
        ctx.setSqlHash(sqlHash);

        SessionVariable sessionVariable = ctx.getSessionVariable();
        boolean wantToParseSqlFromSqlCache = sessionVariable.isEnableNereidsPlanner()
                && CacheAnalyzer.canUseSqlCache(sessionVariable);
        List<StatementBase> stmts = null;
        Exception nereidsParseException = null;
        Exception nereidsSyntaxException = null;
        long parseSqlStartTime = System.currentTimeMillis();
        List<StatementBase> cachedStmts = null;
        
        
        boolean nereidsUseServerPrep = sessionVariable.enableServeSidePreparedStatement
                        || mysqlCommand == MysqlCommand.COM_QUERY;
        if (nereidsUseServerPrep && sessionVariable.isEnableNereidsPlanner()) {
            if (wantToParseSqlFromSqlCache) {
                cachedStmts = parseFromSqlCache(originStmt);
                if (cachedStmts != null) {
                    stmts = cachedStmts;
                }
            }

            if (cachedStmts == null) {
                try {
                    stmts = new NereidsParser().parseSQL(convertedStmt, sessionVariable);
                } catch (NotSupportedException e) {
                    
                    handleQueryException(e, convertedStmt, null, null);
                    return;
                } catch (ParseException e) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Nereids parse sql failed. Reason: {}. Statement: \"{}\".",
                                e.getMessage(), convertedStmt);
                    }
                    
                    
                    
                    
                    nereidsParseException = e;
                } catch (Exception e) {
                    
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Nereids parse sql failed with other exception. Reason: {}. Statement: \"{}\".",
                                e.getMessage(), convertedStmt);
                    }
                    nereidsSyntaxException = e;
                }
            }
        }

        
        if (stmts == null) {
            try {
                stmts = parse(convertedStmt);
            } catch (Throwable throwable) {
                
                
                
                if (nereidsSyntaxException != null) {
                    throwable = nereidsSyntaxException;
                }
                
                handleQueryException(throwable, convertedStmt, null, null);
                return;
            }
        }

        if (mysqlCommand == MysqlCommand.COM_QUERY
                && ctx.getSessionVariable().isEnableNereidsPlanner()
                && !ctx.getSessionVariable().enableFallbackToOriginalPlanner
                && stmts.stream().allMatch(s -> s instanceof QueryStmt
                || s instanceof InsertStmt
                || s instanceof UpdateStmt
                || s instanceof DeleteStmt
                || s instanceof CreateTableAsSelectStmt
                || s instanceof CreateTableStmt
                || s instanceof CreateTableLikeStmt
                || s instanceof CreateViewStmt
                || s instanceof AlterViewStmt)) {
            String errMsg;
            Throwable exception = null;
            if (nereidsParseException != null) {
                errMsg = nereidsParseException.getMessage();
                exception = nereidsParseException;
            } else if (nereidsSyntaxException != null) {
                errMsg = nereidsSyntaxException.getMessage();
                exception = nereidsSyntaxException;
            } else {
                errMsg = "Nereids parse DQL failed. " + originStmt;
            }
            if (exception == null) {
                exception = new AnalysisException(errMsg);
            } else {
                exception = new AnalysisException(errMsg, exception);
            }
            handleQueryException(exception, originStmt, null, null);
            return;
        }

        List<String> origSingleStmtList = null;
        
        if (stmts.size() > 1) {
            try {
                origSingleStmtList = SqlUtils.splitMultiStmts(convertedStmt);
            } catch (Exception ignore) {
                LOG.warn("Try to parse multi origSingleStmt failed, originStmt: \"{}\"", convertedStmt);
            }
        }
        long parseSqlFinishTime = System.currentTimeMillis();

        boolean usingOrigSingleStmt = origSingleStmtList != null && origSingleStmtList.size() == stmts.size();
        for (int i = 0; i < stmts.size(); ++i) {
            String auditStmt = usingOrigSingleStmt ? origSingleStmtList.get(i) : convertedStmt;
            try {
                ctx.getState().reset();
                if (i > 0) {
                    ctx.resetReturnRows();
                }

                StatementBase parsedStmt = stmts.get(i);
                parsedStmt.setOrigStmt(new OriginStatement(convertedStmt, i));
                parsedStmt.setUserInfo(ctx.getCurrentUserIdentity());
                executor = new StmtExecutor(ctx, parsedStmt);
                executor.getProfile().getSummaryProfile().setParseSqlStartTime(parseSqlStartTime);
                executor.getProfile().getSummaryProfile().setParseSqlFinishTime(parseSqlFinishTime);
                ctx.setExecutor(executor);

                try {
                    executor.execute();
                    if (connectType.equals(ConnectType.MYSQL)) {
                        if (i != stmts.size() - 1) {
                            ctx.getState().serverStatus |= MysqlServerStatusFlag.SERVER_MORE_RESULTS_EXISTS;
                            if (ctx.getState().getStateType() != MysqlStateType.ERR) {
                                
                                
                                
                                
                                if (getConnectContext().getCapability().isClientMultiStatements()) {
                                    finalizeCommand();
                                }
                            }
                        }
                    } else if (connectType.equals(ConnectType.ARROW_FLIGHT_SQL)) {
                        if (!ctx.isReturnResultFromLocal()) {
                            returnResultFromRemoteExecutor.add(executor);
                        }
                        Preconditions.checkState(ctx.getFlightSqlChannel().resultNum() <= 1);
                        if (ctx.getFlightSqlChannel().resultNum() == 1 && i != stmts.size() - 1) {
                            String errMsg = "Only be one stmt that returns the result and it is at the end. "
                                    + "stmts.size(): " + stmts.size();
                            LOG.warn(errMsg);
                            ctx.getState().setError(ErrorCode.ERR_ARROW_FLIGHT_SQL_MUST_ONLY_RESULT_STMT, errMsg);
                            ctx.getState().setErrType(QueryState.ErrType.OTHER_ERR);
                            break;
                        }
                    }
                    auditAfterExec(auditStmt, executor.getParsedStmt(), executor.getQueryStatisticsForAuditLog(),
                            true);
                    LOG.debug("Write audit logs for query {}", DebugUtil.printId(ctx.queryId));
                    
                    if (ctx.getState().getStateType() == MysqlStateType.ERR) {
                        break;
                    }
                } catch (Throwable throwable) {
                    handleQueryException(throwable, auditStmt, executor.getParsedStmt(),
                            executor.getQueryStatisticsForAuditLog());
                    
                    throw throwable;
                }
            } finally {
                StatementContext statementContext = ctx.getStatementContext();
                if (statementContext != null) {
                    statementContext.close();
                }
            }
        }
    }


Revised code:
public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Exception {
        if (MetricRepo.isInit) {
            MetricRepo.COUNTER_REQUEST_ALL.increase(1L);
            MetricRepo.increaseClusterRequestAll(ctx.getCloudCluster(false));
        }

        String convertedStmt = convertOriginStmt(originStmt);
        String sqlHash = DigestUtils.md5Hex(convertedStmt);
        ctx.setSqlHash(sqlHash);

        SessionVariable sessionVariable = ctx.getSessionVariable();
        boolean wantToParseSqlFromSqlCache = sessionVariable.isEnableNereidsPlanner()
                && CacheAnalyzer.canUseSqlCache(sessionVariable);
        List<StatementBase> stmts = null;
        Exception nereidsParseException = null;
        Exception nereidsSyntaxException = null;
        long parseSqlStartTime = System.currentTimeMillis();
        List<StatementBase> cachedStmts = null;
        
        
        boolean nereidsUseServerPrep = sessionVariable.enableServeSidePreparedStatement
                        || mysqlCommand == MysqlCommand.COM_QUERY;
        if (nereidsUseServerPrep && sessionVariable.isEnableNereidsPlanner()) {
            if (wantToParseSqlFromSqlCache) {
                cachedStmts = parseFromSqlCache(originStmt);
                if (cachedStmts != null) {
                    stmts = cachedStmts;
                }
            }

            if (cachedStmts == null) {
                try {
                    stmts = new NereidsParser().parseSQL(convertedStmt, sessionVariable);
                } catch (NotSupportedException e) {
                    
                    handleQueryException(e, convertedStmt, null, null);
                    return;
                } catch (ParseException e) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Nereids parse sql failed. Reason: {}. Statement: \"{}\".",
                                e.getMessage(), convertedStmt);
                    }
                    
                    
                    
                    
                    nereidsParseException = e;
                } catch (Exception e) {
                    
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Nereids parse sql failed with other exception. Reason: {}. Statement: \"{}\".",
                                e.getMessage(), convertedStmt);
                    }
                    nereidsSyntaxException = e;
                }
            }
        }

        
        if (stmts == null) {
            try {
                stmts = parse(convertedStmt);
            } catch (Throwable throwable) {
                
                
                
                if (nereidsSyntaxException != null) {
                    throwable = nereidsSyntaxException;
                }
                
                handleQueryException(throwable, convertedStmt, null, null);
                return;
            }
        }

        if (mysqlCommand == MysqlCommand.COM_QUERY
                && ctx.getSessionVariable().isEnableNereidsPlanner()
                && !ctx.getSessionVariable().enableFallbackToOriginalPlanner
                && stmts.stream().allMatch(s -> s instanceof QueryStmt
                || s instanceof InsertStmt
                || s instanceof UpdateStmt
                || s instanceof DeleteStmt
                || s instanceof CreateTableAsSelectStmt
                || s instanceof CreateTableStmt
                || s instanceof CreateTableLikeStmt
                || s instanceof CreateViewStmt
                || s instanceof AlterViewStmt)) {
            String errMsg;
            Throwable exception = null;
            if (nereidsParseException != null) {
                errMsg = nereidsParseException.getMessage();
                exception = nereidsParseException;
            } else if (nereidsSyntaxException != null) {
                errMsg = nereidsSyntaxException.getMessage();
                exception = nereidsSyntaxException;
            } else {
                errMsg = "Nereids parse DQL failed. " + originStmt;
            }
            if (exception == null) {
                exception = new AnalysisException(errMsg);
            } else {
                exception = new AnalysisException(errMsg, exception);
            }
            handleQueryException(exception, originStmt, null, null);
            return;
        }

        List<String> origSingleStmtList = null;
        
        if (stmts.size() > 1) {
            try {
                origSingleStmtList = SqlUtils.splitMultiStmts(convertedStmt);
            } catch (Exception ignore) {
                LOG.warn("Try to parse multi origSingleStmt failed, originStmt: \"{}\"", convertedStmt);
            }
        }
        long parseSqlFinishTime = System.currentTimeMillis();

        boolean usingOrigSingleStmt = origSingleStmtList != null && origSingleStmtList.size() == stmts.size();
        for (int i = 0; i < stmts.size(); ++i) {
            String auditStmt = usingOrigSingleStmt ? origSingleStmtList.get(i) : convertedStmt;
            try {
                ctx.getState().reset();
                if (i > 0) {
                    ctx.resetReturnRows();
                }

                StatementBase parsedStmt = stmts.get(i);
                parsedStmt.setOrigStmt(new OriginStatement(convertedStmt, i));
                parsedStmt.setUserInfo(ctx.getCurrentUserIdentity());
                executor = new StmtExecutor(ctx, parsedStmt);
                executor.getProfile().getSummaryProfile().setParseSqlStartTime(parseSqlStartTime);
                executor.getProfile().getSummaryProfile().setParseSqlFinishTime(parseSqlFinishTime);
                ctx.setExecutor(executor);

                try {
                    executor.execute();
                    if (connectType.equals(ConnectType.MYSQL)) {
                        if (i != stmts.size() - 1) {
                            ctx.getState().serverStatus |= MysqlServerStatusFlag.SERVER_MORE_RESULTS_EXISTS;
                            if (ctx.getState().getStateType() != MysqlStateType.ERR) {
                                
                                
                                
                                
                                if (getConnectContext().getCapability().isClientMultiStatements()) {
                                    finalizeCommand();
                                }
                            }
                        }
                    } else if (connectType.equals(ConnectType.ARROW_FLIGHT_SQL)) {
                        if (!ctx.isReturnResultFromLocal()) {
                            returnResultFromRemoteExecutor.add(executor);
                        }
                        Preconditions.checkState(ctx.getFlightSqlChannel().resultNum() <= 1);
                        if (ctx.getFlightSqlChannel().resultNum() == 1 && i != stmts.size() - 1) {
                            String errMsg = "Only be one stmt that returns the result and it is at the end. "
                                    + "stmts.size(): " + stmts.size();
                            LOG.warn(errMsg);
                            ctx.getState().setError(ErrorCode.ERR_ARROW_FLIGHT_SQL_MUST_ONLY_RESULT_STMT, errMsg);
                            ctx.getState().setErrType(QueryState.ErrType.OTHER_ERR);
                            break;
                        }
                    }
                    auditAfterExec(auditStmt, executor.getParsedStmt(), executor.getQueryStatisticsForAuditLog(),
                            true);
                    LOG.debug("Write audit logs for query {}", DebugUtil.printId(ctx.queryId));
                    
                    if (ctx.getState().getStateType() == MysqlStateType.ERR) {
                        break;
                    }
                } catch (Throwable throwable) {
                    handleQueryException(throwable, auditStmt, executor.getParsedStmt(),
                            executor.getQueryStatisticsForAuditLog());
                    
                    throw throwable;
                }
            } finally {
                StatementContext statementContext = ctx.getStatementContext();
                if (statementContext != null) {
                    statementContext.close();
                }
            }
        }
    }