public void execute() throws DdlException {
        Map<String, UserVariable> clonedUserVars = new ConcurrentHashMap<>();
        boolean hasUserVar = stmt.getSetListItems().stream().anyMatch(var -> var instanceof UserVariable);
        boolean executeSuccess = true;
        if (hasUserVar) {
            clonedUserVars.putAll(ctx.getUserVariables());
            ctx.modifyUserVariablesCopyInWrite(clonedUserVars);
        }
        try {
            for (SetListItem var : stmt.getSetListItems()) {
                setVariablesOfAllType(var);
            }
        } catch (Throwable e) {
            if (hasUserVar) {
                executeSuccess = false;
            }
            throw e;
        } finally {
            //If the set sql contains more than one user variable,
            //the atomicity of the modification of this set of variables must be ensured.
            if (hasUserVar) {
                ctx.resetUserVariableCopyInWrite();
                if (executeSuccess) {
                    ctx.modifyUserVariables(clonedUserVars);
                }
            }
        }
    }
@Test
    public void test1SetSessionAndGlobal() throws Exception {
        ConnectContext ctx = starRocksAssert.getCtx();
        ctxToRoot();
        DDLStmtExecutor.execute(UtFrameUtils.parseStmtWithNewParser(
                "grant operate on system to testUser", ctx), ctx);
        ctxToTestUser();

        String globalSQL = "set global query_timeout = 10";
        SetStmt stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(globalSQL, ctx);
        SetExecutor executor = new SetExecutor(ctx, stmt);
        executor.execute();
        Assert.assertEquals(null, ctx.getModifiedSessionVariables());
        Assert.assertEquals(10, ctx.sessionVariable.getQueryTimeoutS());

        String sessionSQL = "set query_timeout = 9";
        stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sessionSQL, ctx);
        executor = new SetExecutor(ctx, stmt);
        executor.execute();
        Assert.assertEquals(1, ctx.getModifiedSessionVariables().getSetListItems().size());
        Assert.assertEquals(9, ctx.sessionVariable.getQueryTimeoutS());

        ctx.modifyUserVariable(new UserVariable("test_b", new IntLiteral(1), true, NodePosition.ZERO));
        String userVarSql = "set @a = 10";
        stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(userVarSql, ctx);
        executor = new SetExecutor(ctx, stmt);
        executor.execute();
        Assert.assertEquals(2, ctx.getModifiedSessionVariables().getSetListItems().size());
        Assert.assertEquals("10", ctx.getModifiedSessionVariables().getSetListItems().get(1).toSql());
        ctx.getUserVariables().remove("test_b");
    }