This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new 5507d1fe4dd branch-4.1: [fix](dcl) Support WHERE and LIKE in SHOW 
CHARACTER SET (70706) (#70782)
5507d1fe4dd is described below

commit 5507d1fe4ddfa319ea22204ea3ca5ef310895aa2
Author: 924060929 <[email protected]>
AuthorDate: Fri Nov 27 17:07:33 2026 +0800

    branch-4.1: [fix](dcl) Support WHERE and LIKE in SHOW CHARACTER SET (70706) 
(#70782)
    
    cherry pick from #70706
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |   2 +-
 .../org/apache/doris/nereids/StatementContext.java |  44 ++--
 .../doris/nereids/parser/LogicalPlanBuilder.java   |   9 +-
 .../nereids/rules/rewrite/AddDefaultLimit.java     |   7 +-
 .../trees/plans/commands/ShowCharsetCommand.java   |  77 ++++++-
 .../java/org/apache/doris/qe/ConnectContext.java   |  37 ++-
 .../java/org/apache/doris/qe/StmtExecutor.java     |  57 ++++-
 .../plans/commands/ShowCharsetCommandTest.java     | 250 +++++++++++++++++++++
 .../org/apache/doris/qe/ConnectContextTest.java    |  22 ++
 .../test_show_charset_over_arrow_flight.out        |   9 +
 .../nereids_p0/show/test_show_charset_command.out  |  81 +++++++
 .../test_show_charset_over_arrow_flight.groovy}    |  17 +-
 .../show/test_show_charset_command.groovy          |  72 +++++-
 13 files changed, 637 insertions(+), 47 deletions(-)

diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 16cb8d92e00..4ba94e1a68c 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -395,7 +395,7 @@ supportedShowStatement
     | SHOW EXPORT ((FROM | IN) database=multipartIdentifier)? wildWhere?
         sortClause? limitClause?                                               
     #showExport
     | SHOW LAST INSERT                                                         
     #showLastInsert
-    | SHOW ((CHAR SET) | CHARSET)                                              
     #showCharset
+    | SHOW ((CHAR SET) | CHARSET) wildWhere?                                   
     #showCharset
     | SHOW DELETE ((FROM | IN) database=multipartIdentifier)?                  
     #showDelete
     | SHOW CREATE statementScope? FUNCTION functionIdentifier
         LEFT_PAREN functionArguments? RIGHT_PAREN
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java
index 8fa3f65966b..bb990254c37 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java
@@ -181,6 +181,7 @@ public class StatementContext implements Closeable {
     private final Map<CTEId, LogicalPlan> rewrittenCteConsumer = new 
HashMap<>();
     private final Set<String> viewDdlSqlSet = Sets.newHashSet();
     private final SqlCacheContext sqlCacheContext;
+    private final boolean showQuery;
 
     // generate for next id for prepared statement's placeholders, which is
     // connection level
@@ -369,10 +370,16 @@ public class StatementContext implements Closeable {
      * StatementContext
      */
     private StatementContext(ConnectContext connectContext, OriginStatement 
originStatement, int initialId) {
+        this(connectContext, originStatement, initialId, false);
+    }
+
+    private StatementContext(ConnectContext connectContext, OriginStatement 
originStatement, int initialId,
+            boolean showQuery) {
         this.connectContext = connectContext;
         this.originStatement = originStatement;
+        this.showQuery = showQuery;
         exprIdGenerator = ExprId.createGenerator(initialId);
-        if (connectContext != null && connectContext.getSessionVariable() != 
null) {
+        if (!showQuery && connectContext != null && 
connectContext.getSessionVariable() != null) {
             if 
(CacheAnalyzer.canUseSqlCache(connectContext.getSessionVariable())) {
                 // cannot set the queryId here because the queryId for the 
current query is set
                 // in the subsequent steps.
@@ -414,25 +421,36 @@ public class StatementContext implements Closeable {
      * scope, ...) starts empty/fresh on the new context.
      */
     public StatementContext createNextExecuteContext() {
-        // Continue the id generators from the previous context. The cached 
analyzed plan from
-        // PREPARE (and every prior execution) already consumed ids from them, 
so a fresh
-        // generator starting at 0 would collide with those ids during this 
execution's planning.
-        StatementContext next = new StatementContext(connectContext, 
originStatement,
-                exprIdGenerator.getCurrentId());
+        StatementContext next = copyExpressionState(connectContext, showQuery);
+        // Carry over the short-circuit state used to execute the cached 
prepared plan.
+        next.idToComparisonSlot.putAll(idToComparisonSlot);
+        next.isShortCircuitQuery = isShortCircuitQuery;
+        next.hasNondeterministic = hasNondeterministic;
+        return next;
+    }
+
+    /**
+     * Create a context for a query that filters SHOW output using the already 
parsed predicate.
+     */
+    public StatementContext createShowQueryContext(ConnectContext 
internalContext) {
+        return copyExpressionState(internalContext, true);
+    }
+
+    public boolean isShowQuery() {
+        return showQuery;
+    }
+
+    private StatementContext copyExpressionState(ConnectContext context, 
boolean showQuery) {
+        // Already parsed or analyzed expressions may hold ids allocated by 
this context.
+        StatementContext next = new StatementContext(context, originStatement,
+                exprIdGenerator.getCurrentId(), showQuery);
         next.objectIdGenerator.resetId(objectIdGenerator.getCurrentId());
         next.relationIdGenerator.resetId(relationIdGenerator.getCurrentId());
         next.cteIdGenerator.resetId(cteIdGenerator.getCurrentId());
         next.talbeIdGenerator.resetId(talbeIdGenerator.getCurrentId());
         
next.placeHolderIdGenerator.resetId(placeHolderIdGenerator.getCurrentId());
-        // Placeholder bindings of this EXECUTE, and the comparison-slot 
registry used to replace
-        // conjuncts on the cached short-circuit plan without re-planning.
         next.idToPlaceholderRealExpr.putAll(idToPlaceholderRealExpr);
-        next.idToComparisonSlot.putAll(idToComparisonSlot);
         next.placeholders = new ArrayList<>(placeholders);
-        // Short-circuit gating flags are computed by the previous execution's 
planning and gate
-        // the fast path of this execution before any re-planning happens.
-        next.isShortCircuitQuery = isShortCircuitQuery;
-        next.hasNondeterministic = hasNondeterministic;
         return next;
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 413434741de..ab33c11df08 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -7175,7 +7175,14 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
 
     @Override
     public LogicalPlan visitShowCharset(ShowCharsetContext ctx) {
-        return new ShowCharsetCommand();
+        if (ctx.wildWhere() != null) {
+            if (ctx.wildWhere().LIKE() != null) {
+                return new ShowCharsetCommand(
+                        
SqlLiteralUtils.parseStringLiteral(ctx.wildWhere().STRING_LITERAL().getText()), 
null);
+            }
+            return new ShowCharsetCommand(null, 
getExpression(ctx.wildWhere().expression()));
+        }
+        return new ShowCharsetCommand(null, null);
     }
 
     @Override
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
index c54439b1774..336093e091e 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
@@ -38,11 +38,12 @@ public class AddDefaultLimit extends 
DefaultPlanRewriter<StatementContext> imple
 
     @Override
     public Plan rewriteRoot(Plan plan, JobContext jobContext) {
-        if (jobContext.getCascadesContext().getConnectContext() == null
-                || 
!jobContext.getCascadesContext().getConnectContext().getState().isQuery()) {
+        StatementContext statementContext = 
jobContext.getCascadesContext().getStatementContext();
+        ConnectContext ctx = 
jobContext.getCascadesContext().getConnectContext();
+        if (ctx == null || !ctx.getState().isQuery() || 
statementContext.isShowQuery()) {
             return plan;
         }
-        return plan.accept(this, 
jobContext.getCascadesContext().getStatementContext());
+        return plan.accept(this, statementContext);
     }
 
     @Override
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
index 7ff2272f65f..12e5e512147 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
@@ -19,19 +19,38 @@ package org.apache.doris.nereids.trees.plans.commands;
 
 import org.apache.doris.catalog.Column;
 import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.PatternMatcherWrapper;
+import org.apache.doris.common.Status;
+import org.apache.doris.common.UserException;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.analyzer.UnboundResultSink;
+import org.apache.doris.nereids.glue.LogicalPlanAdapter;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
 import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation;
 import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.util.ExpressionUtils;
+import org.apache.doris.qe.AutoCloseConnectContext;
 import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.qe.ShowResultSet;
 import org.apache.doris.qe.ShowResultSetMetaData;
 import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.statistics.ResultRow;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
- * Represents the command for SHOW CHARSETG
+ * Represents the command for SHOW CHARACTER SET
  */
 public class ShowCharsetCommand extends ShowCommand {
     private static final ShowResultSetMetaData CHARSET_META_DATA =
@@ -42,8 +61,13 @@ public class ShowCharsetCommand extends ShowCommand {
                     .addColumn(new Column("Maxlen", 
ScalarType.createVarchar(10)))
                     .build();
 
-    public ShowCharsetCommand() {
+    private final String likePattern;
+    private final Expression whereClause;
+
+    public ShowCharsetCommand(String likePattern, Expression whereClause) {
         super(PlanType.SHOW_CHARSET_COMMAND);
+        this.likePattern = likePattern;
+        this.whereClause = whereClause;
     }
 
     @Override
@@ -53,7 +77,17 @@ public class ShowCharsetCommand extends ShowCommand {
 
     @Override
     public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        if (whereClause != null) {
+            List<List<String>> rows = filterRows(ctx, executor);
+            // A timeout can arrive while the nested query is releasing its 
resources.
+            checkCancelled(executor);
+            return new ShowResultSet(getMetaData(), rows);
+        }
         List<List<String>> rows = Lists.newArrayList();
+        if (likePattern != null && 
!PatternMatcherWrapper.createMysqlPattern(likePattern, false)
+                .match(ctx.getSessionVariable().getCharsetServer())) {
+            return new ShowResultSet(getMetaData(), rows);
+        }
         List<String> row = Lists.newArrayList();
         // | utf8mb4 | UTF-8 Unicode | utf8mb4_general_ci | 4|
         row.add(ctx.getSessionVariable().getCharsetServer());
@@ -65,6 +99,45 @@ public class ShowCharsetCommand extends ShowCommand {
         return new ShowResultSet(getMetaData(), rows);
     }
 
+    private List<List<String>> filterRows(ConnectContext ctx, StmtExecutor 
executor) throws UserException {
+        try (AutoCloseConnectContext scope = new 
AutoCloseConnectContext(ctx.createInternalQueryContext());
+                StatementContext statementContext = ctx.getStatementContext()
+                        .createShowQueryContext(scope.connectContext)) {
+            ConnectContext internalContext = scope.connectContext;
+            internalContext.setStatementContext(statementContext);
+
+            List<NamedExpression> projects = ImmutableList.of(
+                    new Alias(new 
StringLiteral(ctx.getSessionVariable().getCharsetServer()), "Charset"),
+                    new Alias(new StringLiteral("UTF-8 Unicode"), 
"Description"),
+                    new Alias(new 
StringLiteral(ctx.getSessionVariable().getCollationConnection()),
+                            "Default collation"),
+                    new Alias(new IntegerLiteral(4), "Maxlen"));
+            LogicalOneRowRelation relation = new LogicalOneRowRelation(
+                    StatementScopeIdGenerator.newRelationId(), projects);
+            LogicalFilter<LogicalOneRowRelation> filter = new LogicalFilter<>(
+                    ExpressionUtils.extractConjunctionToSet(whereClause), 
relation);
+            LogicalPlanAdapter adapter = new LogicalPlanAdapter(new 
UnboundResultSink<>(filter), statementContext);
+            adapter.setOrigStmt(executor.getOriginStmt());
+            StmtExecutor internalExecutor = new StmtExecutor(internalContext, 
adapter);
+            internalContext.setExecutor(internalExecutor);
+            executor.setCancelDelegate(internalExecutor::cancel);
+            // Publish the delegate before checking for cancellation that 
arrived before publication.
+            checkCancelled(executor);
+            return internalExecutor.executeInternalQuery().stream()
+                    .map(ResultRow::getValues)
+                    .collect(Collectors.toList());
+        } finally {
+            executor.clearCancelDelegate();
+        }
+    }
+
+    private static void checkCancelled(StmtExecutor executor) throws 
UserException {
+        Status reason = executor.getPendingCancelReason();
+        if (reason != null) {
+            throw new UserException(reason.getErrorMsg());
+        }
+    }
+
     @Override
     public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
         return visitor.visitShowCharsetCommand(this, context);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
index 28b395d2ebb..191dcd27d75 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
@@ -499,7 +499,7 @@ public class ConnectContext {
     }
 
     public ConnectContext() {
-        this(null);
+        this((StreamConnection) null);
     }
 
     public ConnectContext(StreamConnection connection) {
@@ -538,6 +538,41 @@ public class ConnectContext {
         return context;
     }
 
+    /**
+     * Isolate a read-only internal query from the client protocol and 
statement state while
+     * retaining the caller's session identity, name resolution and variable 
values.
+     * The caller still owns the session and its cleanup.
+     */
+    public ConnectContext createInternalQueryContext() {
+        return new ConnectContext(this);
+    }
+
+    private ConnectContext(ConnectContext parent) {
+        connectType = ConnectType.MYSQL;
+        mysqlChannel = new DummyMysqlChannel();
+        command = MysqlCommand.COM_QUERY;
+        state = new QueryState();
+        sessionVariable = 
VariableMgr.cloneSessionVariable(parent.sessionVariable);
+        userVars.putAll(parent.userVars);
+        env = parent.env;
+        currentUserIdentity = parent.currentUserIdentity;
+        authenticatedPrincipal = parent.authenticatedPrincipal;
+        authenticatedRoles = parent.authenticatedRoles;
+        sessionContext = parent.sessionContext;
+        isTempUser = parent.isTempUser;
+        remoteIP = parent.remoteIP;
+        connectionId = parent.connectionId;
+        startTime = parent.startTime;
+        lastQueryId = parent.lastQueryId;
+        computeGroup = parent.computeGroup;
+        cloudCluster = parent.cloudCluster;
+        defaultCatalog = parent.defaultCatalog;
+        currentDb = parent.currentDb;
+        currentDbId = parent.currentDbId;
+        // Borrow the caller's temporary-table namespace without registering a 
new session.
+        sessionId = parent.sessionId;
+    }
+
     public Map<String, String> getConnectAttributes() {
         return connectAttributes;
     }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index cd0bde5d797..eed1e3c1d2a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -165,6 +165,7 @@ import java.util.UUID;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -206,6 +207,11 @@ public class StmtExecutor {
     // ConnectContext.getExecTimeoutS() later would report the session value 
instead.
     private volatile int deferredExecTimeoutS = -1;
     private MasterOpExecutor masterOpExecutor = null;
+    // Optional forward target for cancellations issued on this executor: 
statements that
+    // spawn a nested internal executor with its own query id (e.g. SHOW 
CHARACTER SET WHERE)
+    // register it here so Ctrl+C / KILL QUERY / statement timeout on the 
outer statement also
+    // cancel the inner work, which those paths cannot address directly.
+    private volatile Consumer<Status> cancelDelegate = null;
     private RedirectStatus redirectStatus = null;
     private Planner planner;
     private boolean isProxy;
@@ -218,7 +224,7 @@ public class StmtExecutor {
     // Handle selects that fe can do without be
     private boolean isHandleQueryInFe = false;
     // The profile of this execution
-    private final Profile profile;
+    private Profile profile;
     private Boolean isForwardedToMaster = null;
     // Flag for execute prepare statement, need to use binary protocol 
resultset
     private boolean isComStmtExecute = false;
@@ -1240,10 +1246,27 @@ public class StmtExecutor {
     }
 
     // Because this is called by other thread
+    /**
+     * Routes cancellation of this (outer) executor to a nested internal 
executor, e.g. the
+     * internal filter query executor of SHOW CHARACTER SET WHERE. The 
delegate receives the same
+     * cancel reason and must be cleared once the nested work is done.
+     */
+    public void setCancelDelegate(Consumer<Status> cancelDelegate) {
+        this.cancelDelegate = cancelDelegate;
+    }
+
+    public void clearCancelDelegate() {
+        this.cancelDelegate = null;
+    }
+
     public void cancel(Status cancelReason, boolean needWaitCancelComplete) {
         pendingCoordinatorCancelReason.compareAndSet(null, cancelReason);
         Status coordinatorCancelReason = pendingCoordinatorCancelReason.get();
         scanTaskScope.cancel(coordinatorCancelReason);
+        Consumer<Status> delegate = cancelDelegate;
+        if (delegate != null) {
+            delegate.accept(coordinatorCancelReason);
+        }
         if (masterOpExecutor != null) {
             try {
                 masterOpExecutor.cancel();
@@ -2193,6 +2216,12 @@ public class StmtExecutor {
         context.getState().setNereids(true);
         context.getState().setIsQuery(true);
         context.getState().setInternal(true);
+        SessionVariable session = context.getSessionVariable();
+        if (Config.enable_collect_internal_query_profile && 
!session.enableProfile()) {
+            session.enableProfile = true;
+            // The executor may have been constructed with profiling disabled.
+            profile = new Profile(true, session.getProfileLevel(), 
session.getAutoProfileThresholdMs());
+        }
         try {
             List<ResultRow> resultRows = new ArrayList<>();
             try {
@@ -2206,10 +2235,26 @@ public class StmtExecutor {
                 LOG.warn("Failed to run internal SQL: {}", originStmt, e);
                 throw new RuntimeException("Failed to execute internal SQL. " 
+ Util.getRootCauseMessage(e), e);
             }
-            RowBatch batch;
-            if (Config.enable_collect_internal_query_profile) {
-                context.getSessionVariable().enableProfile = true;
+            if (context.supportHandleByFe()) {
+                Optional<ResultSet> resultSet = 
planner.handleQueryInFe(parsedStmt);
+                if (resultSet.isPresent()) {
+                    Status cancelReason = pendingCoordinatorCancelReason.get();
+                    if (cancelReason != null) {
+                        throw new 
InternalQueryExecutionException(cancelReason.getErrorMsg(),
+                                new UserException(cancelReason.getErrorMsg()));
+                    }
+                    List<List<String>> rows = resultSet.get().getResultRows();
+                    context.updateReturnRows(rows.size());
+                    isHandleQueryInFe = true;
+                    if (context.getSessionVariable().enableProfile() && 
profile != null) {
+                        
profile.getSummaryProfile().setExecutedByFrontend(true);
+                    }
+                    return rows.stream()
+                            .map(ResultRow::new)
+                            .collect(Collectors.toList());
+                }
             }
+            RowBatch batch;
             setCoord(EnvFactory.getInstance().createCoordinator(context,
                     planner, context.getStatsErrorEstimator()));
             profile.addExecutionProfile(coord.getExecutionProfile());
@@ -2221,6 +2266,10 @@ public class StmtExecutor {
             }
             updateProfile(false);
             try {
+                Status cancelReason = pendingCoordinatorCancelReason.get();
+                if (cancelReason != null) {
+                    throw new UserException(cancelReason.getErrorMsg());
+                }
                 coord.exec();
             } catch (Exception e) {
                 throw new InternalQueryExecutionException(e.getMessage() + 
Util.getRootCauseMessage(e), e);
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommandTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommandTest.java
new file mode 100644
index 00000000000..a1b6ff94198
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommandTest.java
@@ -0,0 +1,250 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.common.Config;
+import org.apache.doris.common.Status;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.DebugUtil;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.qe.AutoCloseConnectContext;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.OriginStatement;
+import org.apache.doris.qe.ShowResultSet;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.thrift.TStatusCode;
+import org.apache.doris.thrift.TUniqueId;
+import org.apache.doris.utframe.TestWithFeService;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+class ShowCharsetCommandTest extends TestWithFeService {
+    private static final List<List<String>> EXPECTED_ROWS = ImmutableList.of(
+            ImmutableList.of("utf8mb4", "UTF-8 Unicode", "utf8mb4_0900_bin", 
"4"));
+
+    private ShowResultSet execute(String sql) throws Exception {
+        connectContext.getState().reset();
+        StmtExecutor executor = new StmtExecutor(connectContext, sql);
+        ShowCharsetCommand command = (ShowCharsetCommand) new 
NereidsParser().parseSingle(sql);
+        StatementContext statementContext = 
connectContext.getStatementContext();
+        TUniqueId queryId = new TUniqueId(1, 2);
+        connectContext.setQueryId(queryId);
+        try {
+            return command.doRun(connectContext, executor);
+        } finally {
+            Assertions.assertSame(connectContext, ConnectContext.get());
+            Assertions.assertSame(executor, connectContext.getExecutor());
+            Assertions.assertSame(statementContext, 
connectContext.getStatementContext());
+            Assertions.assertSame(queryId, connectContext.queryId());
+            Assertions.assertFalse(connectContext.getState().isInternal());
+            Assertions.assertFalse(connectContext.getState().isQuery());
+        }
+    }
+
+    @Test
+    void testUnfiltered() throws Exception {
+        Assertions.assertEquals(EXPECTED_ROWS, execute("SHOW 
CHARSET").getResultRows());
+        ShowResultSet result = execute("SHOW CHARACTER SET");
+        Assertions.assertEquals(EXPECTED_ROWS, result.getResultRows());
+        Assertions.assertEquals("Charset", 
result.getMetaData().getColumn(0).getName());
+        Assertions.assertEquals("Default collation", 
result.getMetaData().getColumn(2).getName());
+    }
+
+    @Test
+    void testLike() throws Exception {
+        for (String pattern : ImmutableList.of("utf8mb4", "utf8%", "utf8mb_", 
"UTF8%", "%")) {
+            Assertions.assertEquals(EXPECTED_ROWS,
+                    execute("SHOW CHARACTER SET LIKE '" + pattern + 
"'").getResultRows(), pattern);
+        }
+        Assertions.assertTrue(execute("SHOW CHARSET LIKE 
'latin%'").getResultRows().isEmpty());
+        Assertions.assertTrue(execute("SHOW CHARSET LIKE 
''").getResultRows().isEmpty());
+    }
+
+    @Test
+    void testWhere() throws Exception {
+        Assertions.assertEquals(EXPECTED_ROWS,
+                execute("SHOW CHARACTER SET WHERE charset = 
'utf8mb4'").getResultRows());
+        Assertions.assertEquals(EXPECTED_ROWS,
+                execute("SHOW CHARSET WHERE CHARSET = 'utf8mb4' AND Maxlen >= 
4").getResultRows());
+        Assertions.assertEquals(EXPECTED_ROWS,
+                execute("SHOW CHARSET WHERE Charset = 'latin1' OR Description 
= 'UTF-8 Unicode'").getResultRows());
+        Assertions.assertEquals(EXPECTED_ROWS,
+                execute("SHOW CHARSET WHERE `Default collation` = 
'utf8mb4_0900_bin'").getResultRows());
+        Assertions.assertTrue(execute("SHOW CHARSET WHERE Charset = 
'latin1'").getResultRows().isEmpty());
+        Assertions.assertTrue(execute("SHOW CHARSET WHERE Maxlen > 
4").getResultRows().isEmpty());
+        Assertions.assertEquals(EXPECTED_ROWS,
+                execute("SHOW CHARSET WHERE upper(Charset) = 'UTF8MB4' AND 
Maxlen + 1 = 5").getResultRows());
+    }
+
+    @Test
+    void testNullAndConstantPredicates() throws Exception {
+        Assertions.assertEquals(EXPECTED_ROWS, execute("SHOW CHARSET WHERE 
TRUE").getResultRows());
+        Assertions.assertTrue(execute("SHOW CHARSET WHERE 
FALSE").getResultRows().isEmpty());
+        Assertions.assertTrue(execute("SHOW CHARSET WHERE 
NULL").getResultRows().isEmpty());
+        Assertions.assertTrue(execute("SHOW CHARSET WHERE Charset = 
NULL").getResultRows().isEmpty());
+        Assertions.assertEquals(EXPECTED_ROWS,
+                execute("SHOW CHARSET WHERE Charset IS NOT 
NULL").getResultRows());
+    }
+
+    @Test
+    void testCancelledBeforeFilterStarts() {
+        String sql = "SHOW CHARSET WHERE TRUE";
+        StmtExecutor executor = new StmtExecutor(connectContext, sql);
+        ShowCharsetCommand command = (ShowCharsetCommand) new 
NereidsParser().parseSingle(sql);
+        Status reason = new Status(TStatusCode.CANCELLED, "cancelled before 
SHOW filter starts");
+        executor.cancel(reason, false);
+
+        UserException exception = Assertions.assertThrows(UserException.class,
+                () -> command.doRun(connectContext, executor));
+        Assertions.assertEquals(reason.getErrorMsg(), 
exception.getDetailMessage());
+        Assertions.assertSame(connectContext, ConnectContext.get());
+    }
+
+    @Test
+    void testNestedExecutorReceivesFirstCancellationReason() {
+        StmtExecutor outer = new StmtExecutor(connectContext, "SHOW CHARSET 
WHERE TRUE");
+        StmtExecutor inner = new 
StmtExecutor(connectContext.createInternalQueryContext(), "SELECT 1");
+        Status timeout = new Status(TStatusCode.TIMEOUT, "first timeout");
+        outer.cancel(timeout, false);
+        outer.setCancelDelegate(inner::cancel);
+        try {
+            outer.cancel(new Status(TStatusCode.CANCELLED, "later 
cancellation"), false);
+            Assertions.assertSame(timeout, inner.getPendingCancelReason());
+        } finally {
+            outer.clearCancelDelegate();
+        }
+    }
+
+    @Test
+    void testCancelDuringInternalQueryCleanupDoesNotPublishShowResult() {
+        String sql = "SHOW CHARSET WHERE TRUE";
+        Status timeout = new Status(TStatusCode.TIMEOUT, "timeout before SHOW 
result delivery");
+        StmtExecutor executor = new StmtExecutor(connectContext, new 
OriginStatement(sql, 0), true);
+        StatementContext original = connectContext.getStatementContext();
+        connectContext.setStatementContext(new 
StatementContext(connectContext, executor.getOriginStmt()) {
+            @Override
+            public StatementContext createShowQueryContext(ConnectContext 
inner) {
+                StatementContext nested = super.createShowQueryContext(inner);
+                // Deliver the timeout after FE evaluation, while the nested 
statement releases its resources.
+                nested.getOrRegisterStatementResource(this, () -> () -> 
executor.cancel(timeout, false));
+                return nested;
+            }
+        });
+        try {
+            ShowCharsetCommand command = (ShowCharsetCommand) new 
NereidsParser().parseSingle(sql);
+            UserException failure = 
Assertions.assertThrows(UserException.class,
+                    () -> command.run(connectContext, executor));
+            Assertions.assertEquals(timeout.getErrorMsg(), 
failure.getDetailMessage());
+            Assertions.assertNull(executor.getProxyShowResultSet());
+        } finally {
+            connectContext.setStatementContext(original);
+        }
+    }
+
+    @Test
+    void testUnknownColumn() {
+        RuntimeException exception = 
Assertions.assertThrows(RuntimeException.class,
+                () -> execute("SHOW CHARSET WHERE unknown_column = 
'utf8mb4'"));
+        
Assertions.assertTrue(exception.getMessage().contains("unknown_column"));
+    }
+
+    @Test
+    void testSessionValues() throws Exception {
+        boolean originalEnableSqlCache = 
connectContext.getSessionVariable().isEnableSqlCache();
+        String originalCharset = 
connectContext.getSessionVariable().charsetServer;
+        String originalCollation = 
connectContext.getSessionVariable().collationConnection;
+        try {
+            connectContext.getSessionVariable().setEnableSqlCache(true);
+            Assertions.assertEquals(EXPECTED_ROWS, execute("SHOW CHARSET WHERE 
TRUE").getResultRows());
+            connectContext.getSessionVariable().charsetServer = "test_charset";
+            connectContext.getSessionVariable().collationConnection = 
"test_collation";
+            List<List<String>> expected = execute("SHOW 
CHARSET").getResultRows();
+            Assertions.assertEquals(expected, execute("SHOW CHARSET LIKE 
'test_%'").getResultRows());
+            Assertions.assertEquals(expected, execute("SHOW CHARSET WHERE 
TRUE").getResultRows());
+            
Assertions.assertTrue(connectContext.getSessionVariable().isEnableSqlCache());
+            Assertions.assertEquals(expected, execute("SHOW CHARSET WHERE 
Charset = 'test_charset' "
+                    + "AND `Default collation` = 
'test_collation'").getResultRows());
+            Assertions.assertTrue(execute("SHOW CHARSET WHERE Charset = 
'utf8mb4'").getResultRows().isEmpty());
+        } finally {
+            
connectContext.getSessionVariable().setEnableSqlCache(originalEnableSqlCache);
+            connectContext.getSessionVariable().charsetServer = 
originalCharset;
+            connectContext.getSessionVariable().collationConnection = 
originalCollation;
+        }
+    }
+
+    @Test
+    void testWherePreservesDatabaseAndCatalogNamespace() throws Exception {
+        String originalCatalog = connectContext.getDefaultCatalog();
+        String originalDb = connectContext.getDatabase();
+        try {
+            connectContext.changeDefaultCatalog("internal");
+            connectContext.setDatabase("test_namespace_db");
+            Assertions.assertEquals(EXPECTED_ROWS,
+                    execute("SHOW CHARSET WHERE DATABASE() = 
'test_namespace_db' AND CURRENT_CATALOG() = 'internal'")
+                            .getResultRows());
+            Assertions.assertTrue(
+                    execute("SHOW CHARSET WHERE DATABASE() = 
'other_db'").getResultRows().isEmpty());
+        } finally {
+            connectContext.changeDefaultCatalog(originalCatalog);
+            connectContext.setDatabase(originalDb);
+        }
+    }
+
+    @Test
+    void testCancelledInternalQueryDoesNotReturnFeResult() {
+        ConnectContext internal = connectContext.createInternalQueryContext();
+        try (AutoCloseConnectContext scope = new 
AutoCloseConnectContext(internal)) {
+            StmtExecutor executor = new StmtExecutor(internal, "SELECT 1");
+            executor.cancel(new Status(TStatusCode.TIMEOUT, "internal filter 
timed out"), false);
+            RuntimeException failure = 
Assertions.assertThrows(RuntimeException.class, executor::executeInternalQuery);
+            Assertions.assertTrue(failure.getMessage().contains("internal 
filter timed out"));
+            Assertions.assertEquals(0, internal.getReturnRows());
+        }
+    }
+
+    @Test
+    void testConfiguredProfileForFeInternalQuery() {
+        boolean previous = Config.enable_collect_internal_query_profile;
+        ConnectContext internal = connectContext.createInternalQueryContext();
+        try (AutoCloseConnectContext scope = new 
AutoCloseConnectContext(internal)) {
+            Config.enable_collect_internal_query_profile = true;
+            internal.getSessionVariable().enableProfile = false;
+            StmtExecutor executor = new StmtExecutor(internal, "SELECT 1");
+            Assertions.assertEquals(1, executor.executeInternalQuery().size());
+            Assertions.assertTrue(executor.isHandleQueryInFe());
+            Assertions.assertEquals(DebugUtil.printId(internal.queryId()), 
executor.getProfile().getId());
+        } finally {
+            Config.enable_collect_internal_query_profile = previous;
+        }
+    }
+
+    @Test
+    void testInternalQueryUpdatesReturnRowsOnFeShortcut() {
+        ConnectContext internalContext = 
connectContext.createInternalQueryContext();
+        try (AutoCloseConnectContext scope = new 
AutoCloseConnectContext(internalContext)) {
+            StmtExecutor internalExecutor = new StmtExecutor(internalContext, 
"SELECT 1");
+            Assertions.assertEquals(1, 
internalExecutor.executeInternalQuery().size());
+            Assertions.assertEquals(1L, internalContext.getReturnRows());
+        }
+    }
+}
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
index 3bf5588e28e..14a05119a35 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
@@ -84,6 +84,28 @@ public class ConnectContextTest {
     public void setUp() throws Exception {
     }
 
+    @Test
+    public void testInternalQueryInheritsSessionState() {
+        ConnectContext parent = new ConnectContext();
+        
parent.setCurrentUserIdentity(UserIdentity.createAnalyzedUserIdentWithIp("testUser",
 "%"));
+        parent.getSessionVariable().charsetServer = "test_charset";
+        parent.changeDefaultCatalog("external_catalog");
+        parent.currentDb = "test_db";
+        parent.currentDbId = 42L;
+
+        ConnectContext child = parent.createInternalQueryContext();
+        Assert.assertEquals(parent.getCurrentUserIdentity(), 
child.getCurrentUserIdentity());
+        Assert.assertEquals(parent.getSessionId(), child.getSessionId());
+        Assert.assertNotSame(parent.getSessionVariable(), 
child.getSessionVariable());
+        Assert.assertEquals("test_charset", 
child.getSessionVariable().charsetServer);
+        Assert.assertEquals("external_catalog", child.getDefaultCatalog());
+        Assert.assertEquals("test_db", child.getDatabase());
+        Assert.assertEquals(42L, child.getCurrentDbId());
+
+        child.getSessionVariable().charsetServer = "child_charset";
+        Assert.assertEquals("test_charset", 
parent.getSessionVariable().charsetServer);
+    }
+
     @Test
     public void testResetConnectionClearsSessionState() throws Exception {
         Env env = Mockito.mock(Env.class);
diff --git 
a/regression-test/data/arrow_flight_sql_p0/test_show_charset_over_arrow_flight.out
 
b/regression-test/data/arrow_flight_sql_p0/test_show_charset_over_arrow_flight.out
new file mode 100644
index 00000000000..d801aa583f1
--- /dev/null
+++ 
b/regression-test/data/arrow_flight_sql_p0/test_show_charset_over_arrow_flight.out
@@ -0,0 +1,9 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !arrow_flight_sql_show_charset --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !arrow_flight_sql_show_charset_on_be --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !arrow_flight_sql_show_charset_no_match --
+
diff --git a/regression-test/data/nereids_p0/show/test_show_charset_command.out 
b/regression-test/data/nereids_p0/show/test_show_charset_command.out
index dd9ca552bf7..5b399b450cc 100644
--- a/regression-test/data/nereids_p0/show/test_show_charset_command.out
+++ b/regression-test/data/nereids_p0/show/test_show_charset_command.out
@@ -2,3 +2,84 @@
 -- !cmd --
 utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
 
+-- !character_set --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !like_exact --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !like_percent --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !like_underscore --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !like_case --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !like_no_match --
+
+-- !like_empty --
+
+-- !where_charset --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_no_match --
+
+-- !where_like --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_not_like --
+
+-- !where_and --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_or --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_collation --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_numeric --
+
+-- !where_expression --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_true --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_false --
+
+-- !where_null --
+
+-- !where_equals_null --
+
+-- !where_not_null --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !like_backspace --
+
+-- !like_backslash --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !like_no_backslash_escapes --
+
+-- !where_before_collation_change --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !where_after_collation_change --
+utf8mb4        UTF-8 Unicode   utf8mb4_general_ci      4
+
+-- !where_with_select_limit --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !select_limit_still_applies --
+
+-- !where_database --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !prepared_match --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
+-- !prepared_no_match --
+
diff --git 
a/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy 
b/regression-test/suites/arrow_flight_sql_p0/test_show_charset_over_arrow_flight.groovy
similarity index 67%
copy from 
regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
copy to 
regression-test/suites/arrow_flight_sql_p0/test_show_charset_over_arrow_flight.groovy
index 30ad3631b94..f6dc581fdff 100644
--- a/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
+++ 
b/regression-test/suites/arrow_flight_sql_p0/test_show_charset_over_arrow_flight.groovy
@@ -15,16 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-suite("test_show_charset_command", "query,charset") {
-    try {
-        // Execute the SHOW CHARSET command and verify the output
-        checkNereidsExecute("SHOW CHARSET")
-        qt_cmd("SHOW CHARSET")
-
-    } catch (Exception e) {
-        // Log any exceptions that occur during testing
-        log.error("Failed to execute SHOW CHARSET command", e)
-        throw e
-    }
+suite("test_show_charset_over_arrow_flight", "arrow_flight_sql") {
+    order_qt_arrow_flight_sql_show_charset "SHOW CHARSET WHERE TRUE"
+    // RAND() is evaluated by a backend, exercising the internal result 
receiver.
+    order_qt_arrow_flight_sql_show_charset_on_be "SHOW CHARSET WHERE RAND() >= 
0"
+    order_qt_arrow_flight_sql_show_charset_no_match "SHOW CHARACTER SET WHERE 
Maxlen < 4"
 }
-
diff --git 
a/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy 
b/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
index 30ad3631b94..52552c36b54 100644
--- a/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
+++ b/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
@@ -16,15 +16,67 @@
 // under the License.
 
 suite("test_show_charset_command", "query,charset") {
-    try {
-        // Execute the SHOW CHARSET command and verify the output
-        checkNereidsExecute("SHOW CHARSET")
-        qt_cmd("SHOW CHARSET")
-
-    } catch (Exception e) {
-        // Log any exceptions that occur during testing
-        log.error("Failed to execute SHOW CHARSET command", e)
-        throw e
+    checkNereidsExecute("SHOW CHARSET")
+    order_qt_cmd "SHOW CHARSET"
+    order_qt_character_set "SHOW CHARACTER SET"
+
+    order_qt_like_exact "SHOW CHARACTER SET LIKE 'utf8mb4'"
+    order_qt_like_percent "SHOW CHARSET LIKE 'utf8%'"
+    order_qt_like_underscore "SHOW CHARSET LIKE 'utf8mb_'"
+    order_qt_like_case "SHOW CHARSET LIKE 'UTF8%'"
+    order_qt_like_no_match "SHOW CHARACTER SET LIKE 'latin%'"
+    order_qt_like_empty "SHOW CHARSET LIKE ''"
+
+    order_qt_where_charset "SHOW CHARACTER SET WHERE charset = 'utf8mb4'"
+    order_qt_where_no_match "SHOW CHARSET WHERE Charset = 'latin1'"
+    order_qt_where_like "SHOW CHARSET WHERE Charset LIKE 'utf8%'"
+    order_qt_where_not_like "SHOW CHARSET WHERE Charset NOT LIKE 'utf8%'"
+    order_qt_where_and "SHOW CHARSET WHERE CHARSET = 'utf8mb4' AND Maxlen >= 4"
+    order_qt_where_or "SHOW CHARSET WHERE Charset = 'latin1' OR Description = 
'UTF-8 Unicode'"
+    order_qt_where_collation "SHOW CHARSET WHERE `Default collation` = 
'utf8mb4_0900_bin'"
+    order_qt_where_numeric "SHOW CHARSET WHERE Maxlen > 4"
+    order_qt_where_expression "SHOW CHARSET WHERE upper(Charset) = 'UTF8MB4' 
AND Maxlen + 1 = 5"
+    order_qt_where_true "SHOW CHARSET WHERE TRUE"
+    order_qt_where_false "SHOW CHARSET WHERE FALSE"
+    order_qt_where_null "SHOW CHARSET WHERE NULL"
+    order_qt_where_equals_null "SHOW CHARSET WHERE Charset = NULL"
+    order_qt_where_not_null "SHOW CHARSET WHERE Charset IS NOT NULL"
+
+    sql "SET sql_mode = ''"
+    order_qt_like_backspace "SHOW CHARSET LIKE 'utf8m\\b4'"
+    order_qt_like_backslash "SHOW CHARSET LIKE 'utf8m\\\\b4'"
+    sql "SET sql_mode = 'NO_BACKSLASH_ESCAPES'"
+    order_qt_like_no_backslash_escapes "SHOW CHARSET LIKE 'utf8m\\\\b4'"
+    sql "SET sql_mode = DEFAULT"
+
+    sql "SET enable_sql_cache = true"
+    order_qt_where_before_collation_change "SHOW CHARSET WHERE TRUE"
+    sql "SET collation_connection = 'utf8mb4_general_ci'"
+    order_qt_where_after_collation_change "SHOW CHARSET WHERE TRUE"
+    sql "SET collation_connection = DEFAULT"
+    sql "SET enable_sql_cache = DEFAULT"
+
+    sql "SET sql_select_limit = 0"
+    order_qt_where_with_select_limit "SHOW CHARSET WHERE @@sql_select_limit = 
0"
+    order_qt_select_limit_still_applies "SELECT 1"
+    sql "SET sql_select_limit = DEFAULT"
+
+    order_qt_where_database "SHOW CHARSET WHERE DATABASE() = 
'${context.dbName}' AND CURRENT_CATALOG() = 'internal'"
+
+    def url = getServerPrepareJdbcUrl(context.config.jdbcUrl, context.dbName, 
false) +
+            "&emulateUnsupportedPstmts=false"
+    connect(context.config.jdbcUser, context.config.jdbcPassword, url) {
+        context.getConnection().prepareStatement("SHOW CHARSET WHERE Maxlen = 
?").withCloseable { stmt ->
+            assertTrue(stmt instanceof 
com.mysql.cj.jdbc.ServerPreparedStatement)
+            stmt.setInt(1, 4)
+            qe_prepared_match stmt
+            stmt.setInt(1, 5)
+            qe_prepared_no_match stmt
+        }
     }
-}
 
+    test {
+        sql "SHOW CHARSET WHERE unknown_column = 'utf8mb4'"
+        exception "unknown_column"
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to