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 testUserDefineVariable3() throws Exception {
        ConnectContext ctx = starRocksAssert.getCtx();
        String sql = "set @aVar = 5, @bVar = @aVar + 1, @cVar = @bVar + 1";
        SetStmt stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
        SetExecutor executor = new SetExecutor(ctx, stmt);
        executor.execute();
        UserVariable userVariableA = ctx.getUserVariable("aVar");
        UserVariable userVariableB = ctx.getUserVariable("bVar");
        UserVariable userVariableC = ctx.getUserVariable("cVar");
        Assert.assertTrue(userVariableA.getEvaluatedExpression().getType().matchesType(Type.TINYINT));
        Assert.assertTrue(userVariableB.getEvaluatedExpression().getType().matchesType(Type.SMALLINT));
        Assert.assertTrue(userVariableC.getEvaluatedExpression().getType().matchesType(Type.INT));

        LiteralExpr literalExprA = (LiteralExpr) userVariableA.getEvaluatedExpression();
        Assert.assertEquals("5", literalExprA.getStringValue());

        LiteralExpr literalExprB = (LiteralExpr) userVariableB.getEvaluatedExpression();
        Assert.assertEquals("6", literalExprB.getStringValue());

        LiteralExpr literalExprC = (LiteralExpr) userVariableC.getEvaluatedExpression();
        Assert.assertEquals("7", literalExprC.getStringValue());

        sql = "set @aVar = 6, @bVar = @aVar + 1, @cVar = @bVar + 1";
        stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
        executor = new SetExecutor(ctx, stmt);
        executor.execute();
        userVariableA = ctx.getUserVariable("aVar");
        userVariableB = ctx.getUserVariable("bVar");
        userVariableC = ctx.getUserVariable("cVar");
        Assert.assertTrue(userVariableA.getEvaluatedExpression().getType().matchesType(Type.TINYINT));
        Assert.assertTrue(userVariableB.getEvaluatedExpression().getType().matchesType(Type.SMALLINT));
        Assert.assertTrue(userVariableC.getEvaluatedExpression().getType().matchesType(Type.INT));
        literalExprA = (LiteralExpr) userVariableA.getEvaluatedExpression();
        Assert.assertEquals("6", literalExprA.getStringValue());

        literalExprB = (LiteralExpr) userVariableB.getEvaluatedExpression();
        Assert.assertEquals("7", literalExprB.getStringValue());

        literalExprC = (LiteralExpr) userVariableC.getEvaluatedExpression();
        Assert.assertEquals("8", literalExprC.getStringValue());


        sql = "set @aVar = 5, @bVar = @aVar + 1, @cVar = @eVar + 1";
        stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
        executor = new SetExecutor(ctx, stmt);
        executor.execute();
        userVariableA = ctx.getUserVariable("aVar");
        userVariableB = ctx.getUserVariable("bVar");
        userVariableC = ctx.getUserVariable("cVar");
        Assert.assertTrue(userVariableA.getEvaluatedExpression().getType().matchesType(Type.TINYINT));
        Assert.assertTrue(userVariableB.getEvaluatedExpression().getType().matchesType(Type.SMALLINT));
        Assert.assertTrue(userVariableC.getEvaluatedExpression() instanceof NullLiteral);

        literalExprA = (LiteralExpr) userVariableA.getEvaluatedExpression();
        Assert.assertEquals("5", literalExprA.getStringValue());

        literalExprB = (LiteralExpr) userVariableB.getEvaluatedExpression();
        Assert.assertEquals("6", literalExprB.getStringValue());

        literalExprC = (LiteralExpr) userVariableC.getEvaluatedExpression();
        Assert.assertEquals("NULL", literalExprC.getStringValue());

        try {
            sql = "set @fVar = 1, " +
                    "@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz=2";
            stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
            executor = new SetExecutor(ctx, stmt);
            executor.execute();
        } catch (AnalysisException e) {
            Assert.assertTrue(e.getMessage().contains("User variable name " +
                    "'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' is illegal"));
        }
        Assert.assertTrue(ctx.getUserVariable("fVar") == null);

        ctx.getUserVariables().clear();
        for (int i = 0; i < 1023; ++i) {
            ctx.getUserVariables().put(String.valueOf(i), new UserVariable(null, null, null));
        }
        System.out.println(ctx.getUserVariables().keySet().size());
        try {
            sql = "set @aVar = 6, @bVar = @aVar + 1, @cVar = @bVar + 1";
            stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
            executor = new SetExecutor(ctx, stmt);
            executor.execute();
        } catch (SemanticException e) {
            Assert.assertTrue(e.getMessage().contains("User variable exceeds the maximum limit of 1024"));
        }
        Assert.assertFalse(ctx.getUserVariables().containsKey("aVar"));
        Assert.assertFalse(ctx.getUserVariables().containsKey("bVar"));
        Assert.assertFalse(ctx.getUserVariables().containsKey("cVar"));
        Assert.assertTrue(ctx.getUserVariables().size() == 1023);
    }