github-actions[bot] commented on code in PR #70706:
URL: https://github.com/apache/doris/pull/70706#discussion_r4609197711


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java:
##########
@@ -53,7 +71,26 @@ public ShowResultSetMetaData getMetaData() {
 
     @Override
     public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        if (whereClause != null) {
+            // Filter the same session-dependent values returned by the 
unfiltered command.
+            // Let the query analyzer bind output column names and apply SQL 
expression semantics.
+            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> plan = new LogicalFilter<>(
+                    ExpressionUtils.extractConjunctionToSet(whereClause), 
relation);
+            return new ShowResultSet(getMetaData(), Utils.executePlan(ctx, 
executor, new UnboundResultSink<>(plan)));

Review Comment:
   [P2] Restore the client's internal-query state after filtering
   
   `Utils.executePlan` reuses this client executor, and 
`StmtExecutor.executeInternalQueryCommon` unconditionally calls 
`ctx.getState().setInternal(true)` without restoring it. `QueryState.reset()` 
also leaves that flag intact. A connection that runs `SHOW CHARSET WHERE TRUE` 
therefore treats subsequent ordinary SELECTs as internal: request/query/error 
counters are skipped, audits are classified as internal, and query-hit 
statistics are disabled. Preserve and restore the caller's flag on success and 
failure, or evaluate using an isolated context; add a normal client-path test 
that executes another statement afterward.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java:
##########
@@ -53,7 +71,26 @@ public ShowResultSetMetaData getMetaData() {
 
     @Override
     public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        if (whereClause != null) {
+            // Filter the same session-dependent values returned by the 
unfiltered command.
+            // Let the query analyzer bind output column names and apply SQL 
expression semantics.
+            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()),

Review Comment:
   [P2] Keep session-dependent charset rows out of an untracked SQL cache
   
   These session values become ordinary `StringLiteral`s, so the SQL cache 
records no variable dependencies for them. With the default 
`enable_sql_cache=true`, `SHOW CHARSET WHERE TRUE` simplifies to a one-row FE 
result and `NereidsPlanner.handleQueryInFe` publishes it under the SHOW SQL. 
Run that statement, then `SET collation_connection='utf8mb4_general_ci'`, then 
repeat the statement: normal `ConnectProcessor` cache lookup can return the old 
`utf8mb4_0900_bin` row without invoking this command. The collation/charset 
fields have no `affectQueryResult` flags either. Disable caching for this 
metadata plan or register its session dependencies, and test repeated normal 
SQL execution across a session-value change.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -7167,7 +7167,13 @@ public LogicalPlan visitCreateFile(CreateFileContext 
ctx) {
 
     @Override
     public LogicalPlan visitShowCharset(ShowCharsetContext ctx) {
-        return new ShowCharsetCommand();
+        if (ctx.wildWhere() != null) {
+            if (ctx.wildWhere().LIKE() != null) {
+                return new 
ShowCharsetCommand(stripQuotes(ctx.wildWhere().STRING_LITERAL().getText()), 
null);

Review Comment:
   [P2] Decode the SQL string literal before applying LIKE matching
   
   `stripQuotes` removes only the surrounding quotes, bypassing the SQL-literal 
decoding used by `visitStringLiteral`. For example, with default SQL mode, 
`SHOW CHARSET LIKE 'utf8m\b4'` (one backslash before `b`) should match no row 
because `\b` decodes to a backspace. Here the raw token reaches 
`PatternMatcher`, whose escape handling instead drops the backslash and matches 
`utf8mb4`; the equivalent `WHERE Charset LIKE 'utf8m\b4'` correctly returns no 
row. Use `SqlLiteralUtils.parseStringLiteral` before the pattern matcher and 
cover escaped literals and `NO_BACKSLASH_ESCAPES`.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java:
##########
@@ -53,7 +71,26 @@ public ShowResultSetMetaData getMetaData() {
 
     @Override
     public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        if (whereClause != null) {
+            // Filter the same session-dependent values returned by the 
unfiltered command.
+            // Let the query analyzer bind output column names and apply SQL 
expression semantics.
+            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> plan = new LogicalFilter<>(
+                    ExpressionUtils.extractConjunctionToSet(whereClause), 
relation);

Review Comment:
   [P2] Exclude SELECT-only row limits from the metadata filter
   
   After `SET sql_select_limit=0`, `SHOW CHARSET` and `SHOW CHARSET LIKE '%'` 
still return their metadata row, but `SHOW CHARSET WHERE TRUE` returns none. 
The internal executor marks this plan as a query, so `AddDefaultLimit` rewrites 
`ResultSink(Filter(TRUE, OneRowRelation(...)))` into `ResultSink(Limit(0, 
...))`, and `EliminateLimit` replaces the child with `EmptyRelation`. A true 
SHOW predicate should preserve the unfiltered row regardless of the SELECT 
result cap. Evaluate this metadata plan without inheriting that cap and add the 
nondefault-session-setting case.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java:
##########
@@ -53,7 +71,26 @@ public ShowResultSetMetaData getMetaData() {
 
     @Override
     public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        if (whereClause != null) {
+            // Filter the same session-dependent values returned by the 
unfiltered command.
+            // Let the query analyzer bind output column names and apply SQL 
expression semantics.
+            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> plan = new LogicalFilter<>(
+                    ExpressionUtils.extractConjunctionToSet(whereClause), 
relation);
+            return new ShowResultSet(getMetaData(), Utils.executePlan(ctx, 
executor, new UnboundResultSink<>(plan)));

Review Comment:
   [P2] Collect prepared SHOW rows using the decoder's expected format
   
   A client can prepare and execute `SHOW CHARSET WHERE TRUE` with 
`COM_STMT_PREPARE`/`COM_STMT_EXECUTE`. `supportHandleByFe()` excludes binary 
execution, so this plan runs on BE, and `CoordinatorContext` sets 
`mysql_row_binary_format=true` from the caller command. The internal collector 
nevertheless calls `InternalQueryBuffer.readStringWithLength`, which only 
decodes text rows. The binary header and null-bitmap bytes become two empty 
fields, returning `["", "", "utf8mb4", "UTF-8 Unicode"]` instead of the charset 
metadata. Unfiltered/LIKE SHOW avoids this collector. Force text encoding for 
collected internal rows independently of the outer protocol, or decode the 
binary rows correctly, and test all four values through binary prepare/execute.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java:
##########
@@ -53,7 +71,26 @@ public ShowResultSetMetaData getMetaData() {
 
     @Override
     public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        if (whereClause != null) {
+            // Filter the same session-dependent values returned by the 
unfiltered command.
+            // Let the query analyzer bind output column names and apply SQL 
expression semantics.
+            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> plan = new LogicalFilter<>(
+                    ExpressionUtils.extractConjunctionToSet(whereClause), 
relation);
+            return new ShowResultSet(getMetaData(), Utils.executePlan(ctx, 
executor, new UnboundResultSink<>(plan)));

Review Comment:
   [P2] Choose an internal result sink independently of the Flight connection
   
   On an Arrow Flight connection, even `SHOW CHARSET WHERE TRUE` takes the BE 
path because `FlightProtocolAdapter.supportsFeSideResult()` is false. 
`PhysicalPlanTranslator` inherits the caller's `ARROW_FLIGHT_PROTOCOL` sink, so 
BE creates an `ArrowFlightResultBlockBuffer`. This collect-mode internal 
execution bypasses `beforeQuery`, leaving `returnResultFromLocal=true`; 
`QueryProcessor` therefore creates ordinary `ResultReceiver`s and sends MySQL 
`fetch_data` requests. BE looks up a `MySQLResultBlockBuffer`, whose cast from 
the Arrow buffer fails, so the metadata row cannot be collected. 
Unfiltered/LIKE SHOW stays local and works through the Flight sender. Use an 
explicit internal MySQL text sink/context, or collect Arrow results correctly, 
and cover Flight `SHOW CHARSET WHERE TRUE`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to