You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by en...@apache.org on 2026/04/09 07:28:27 UTC

(doris) branch master updated: [opt](nereids) optimize length(str_col) by only read offset sub column (#62205)

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

englefly pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new eb2567d97ea [opt](nereids) optimize length(str_col) by only read offset sub column (#62205)
eb2567d97ea is described below

commit eb2567d97eab4bc8e3ddd6236e84968acf744a1f
Author: minghong <zh...@selectdb.com>
AuthorDate: Thu Apr 9 15:28:19 2026 +0800

    [opt](nereids) optimize length(str_col) by only read offset sub column (#62205)
    
    ### What problem does this PR solve?
    Optimized the calculation of length(str_col).
    Treat the string column as a combination of an offset sub column and a
    chars sub column.
    Prune the string column via NestedColumnPruning so that the BE only
    needs to read the offset sub column, thereby saving I/O for reading the
    chars sub column.
---
 .../org/apache/doris/nereids/StatementContext.java |  19 +-
 .../rules/expression/ExpressionOptimization.java   |   4 +-
 .../rules/expression/ExpressionRuleType.java       |   1 +
 .../expression/rules/StringEmptyToLengthRule.java  | 113 +++++++
 .../rewrite/AccessPathExpressionCollector.java     |  69 +++++
 .../nereids/rules/rewrite/AccessPathInfo.java      |   3 +
 .../rules/rewrite/AccessPathPlanCollector.java     |  14 +-
 .../nereids/rules/rewrite/NestedColumnPruning.java | 215 ++++++++++++-
 .../rules/rewrite/PruneOlapScanPartition.java      |   2 +-
 .../nereids/rules/rewrite/SlotTypeReplacer.java    |   3 +-
 .../trees/plans/commands/DeleteFromCommand.java    |   3 +-
 .../trees/plans/commands/ExplainCommand.java       |   2 +-
 .../apache/doris/nereids/util/ExpressionUtils.java |  11 +
 .../rules/StringEmptyToLengthRuleTest.java         | 141 +++++++++
 .../rules/rewrite/PruneNestedColumnTest.java       |  96 ++++++
 .../lazy_materialize_topn.out                      |   6 +
 .../filter_push_down/push_filter_through.out       |   8 +-
 .../eliminate_outer_join/eliminate_outer_join.out  |  10 +-
 .../data/shape_check/clickbench/query11.out        |   2 +-
 .../data/shape_check/clickbench/query12.out        |   2 +-
 .../data/shape_check/clickbench/query13.out        |   2 +-
 .../data/shape_check/clickbench/query14.out        |   2 +-
 .../data/shape_check/clickbench/query15.out        |   2 +-
 .../data/shape_check/clickbench/query22.out        |   2 +-
 .../data/shape_check/clickbench/query23.out        |   2 +-
 .../data/shape_check/clickbench/query25.out        |   2 +-
 .../data/shape_check/clickbench/query26.out        |   2 +-
 .../data/shape_check/clickbench/query27.out        |   2 +-
 .../data/shape_check/clickbench/query28.out        |   2 +-
 .../data/shape_check/clickbench/query29.out        |   2 +-
 .../data/shape_check/clickbench/query31.out        |   2 +-
 .../data/shape_check/clickbench/query32.out        |   2 +-
 .../data/shape_check/clickbench/query37.out        |   2 +-
 .../data/shape_check/clickbench/query38.out        |   2 +-
 .../string_length_column_pruning.groovy            | 338 +++++++++++++++++++++
 .../predefine/predefined_typed_to_sparse.groovy    |   2 +-
 36 files changed, 1046 insertions(+), 46 deletions(-)

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 af24f9a83c7..b2968473fcb 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
@@ -137,6 +137,7 @@ public class StatementContext implements Closeable {
 
     private boolean isDpHyp = false;
 
+    private boolean isDelete = false;
     private boolean hasNondeterministic = false;
 
     // hasUnknownColStats true if any column stats in the tables used by this sql is
@@ -303,8 +304,6 @@ public class StatementContext implements Closeable {
     private final Set<List<String>> materializationRewrittenSuccessSet = new HashSet<>();
 
     private boolean isInsert = false;
-    private boolean skipPrunePredicate = false;
-
     private Optional<Map<TableIf, Set<Expression>>> mvRefreshPredicates = Optional.empty();
 
     // For Iceberg rewrite operations: store file scan tasks to be used by
@@ -1179,14 +1178,6 @@ public class StatementContext implements Closeable {
         return this.useGatherForIcebergRewrite;
     }
 
-    public boolean isSkipPrunePredicate() {
-        return skipPrunePredicate;
-    }
-
-    public void setSkipPrunePredicate(boolean skipPrunePredicate) {
-        this.skipPrunePredicate = skipPrunePredicate;
-    }
-
     public boolean hasNestedColumns() {
         return hasNestedColumns;
     }
@@ -1216,4 +1207,12 @@ public class StatementContext implements Closeable {
         }
         return lowerCaseDatabaseNamesCache.computeIfAbsent(catalogName, Env::getLowerCaseDatabaseNames);
     }
+
+    public boolean isDelete() {
+        return isDelete;
+    }
+
+    public void setIsDelete(boolean del) {
+        isDelete = del;
+    }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionOptimization.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionOptimization.java
index a75bc0ecce1..fadad654539 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionOptimization.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionOptimization.java
@@ -36,6 +36,7 @@ import org.apache.doris.nereids.rules.expression.rules.SimplifyInPredicate;
 import org.apache.doris.nereids.rules.expression.rules.SimplifyRange;
 import org.apache.doris.nereids.rules.expression.rules.SimplifySelfComparison;
 import org.apache.doris.nereids.rules.expression.rules.SimplifyTimeFieldFromUnixtime;
+import org.apache.doris.nereids.rules.expression.rules.StringEmptyToLengthRule;
 import org.apache.doris.nereids.rules.expression.rules.TopnToMax;
 
 import com.google.common.collect.ImmutableList;
@@ -71,7 +72,8 @@ public class ExpressionOptimization extends ExpressionRewrite {
                     TopnToMax.INSTANCE,
                     NullSafeEqualToEqual.INSTANCE,
                     LikeToEqualRewrite.INSTANCE,
-                    BetweenToEqual.INSTANCE
+                    BetweenToEqual.INSTANCE,
+                    StringEmptyToLengthRule.INSTANCE
             )
     );
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRuleType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRuleType.java
index 57d65fad365..726026cccbf 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRuleType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRuleType.java
@@ -61,6 +61,7 @@ public enum ExpressionRuleType {
     SIMPLIFY_EQUAL_BOOLEAN_LITERAL,
     SIMPLIFY_IN_PREDICATE,
     SIMPLIFY_NOT_EXPR,
+    STRING_EMPTY_TO_LENGTH,
     SIMPLIFY_RANGE,
     SIMPLIFY_SELF_COMPARISON,
     SUPPORT_JAVA_DATE_FORMATTER,
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/StringEmptyToLengthRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/StringEmptyToLengthRule.java
new file mode 100644
index 00000000000..85776dc4c15
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/StringEmptyToLengthRule.java
@@ -0,0 +1,113 @@
+// 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.rules.expression.rules;
+
+import org.apache.doris.nereids.rules.expression.ExpressionPatternMatcher;
+import org.apache.doris.nereids.rules.expression.ExpressionPatternRuleFactory;
+import org.apache.doris.nereids.rules.expression.ExpressionRuleType;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Not;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Length;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * Rewrites comparisons with empty strings to equivalent length()-based expressions so that
+ * the NestedColumnPruning OFFSET optimization can apply.
+ *
+ * <ul>
+ *   <li>{@code str_col = ''}   → {@code length(str_col) = 0}</li>
+ *   <li>{@code str_col <> ''}  → {@code length(str_col) != 0}
+ *       (represented as {@code NOT(length(str_col) = 0)})</li>
+ * </ul>
+ *
+ * This is a semantics-preserving rewrite: for any non-NULL string, {@code s = ''} is equivalent
+ * to {@code length(s) = 0}; for NULL, both sides evaluate to NULL.
+ *
+ * Only applies when the compared expression is a direct {@link SlotReference} of string-like type,
+ * so that the resulting {@code length(slot)} call can benefit from OFFSET-only column reading.
+ */
+public class StringEmptyToLengthRule implements ExpressionPatternRuleFactory {
+    public static final StringEmptyToLengthRule INSTANCE = new StringEmptyToLengthRule();
+
+    @Override
+    public List<ExpressionPatternMatcher<? extends Expression>> buildRules() {
+        return ImmutableList.of(
+                // str_col = '' → length(str_col) = 0
+                matchesType(EqualTo.class)
+                        .thenApply(ctx -> rewriteEqualToEmpty(ctx.expr))
+                        .toRule(ExpressionRuleType.STRING_EMPTY_TO_LENGTH),
+
+                // NOT(str_col = '') → NOT(length(str_col) = 0)  (i.e. str_col <> '')
+                matchesType(Not.class)
+                        .thenApply(ctx -> {
+                            Not not = ctx.expr;
+                            if (!(not.child() instanceof EqualTo)) {
+                                return not;
+                            }
+                            Expression rewritten = rewriteEqualToEmpty((EqualTo) not.child());
+                            if (rewritten == not.child()) {
+                                return not;
+                            }
+                            return new Not(rewritten);
+                        })
+                        .toRule(ExpressionRuleType.STRING_EMPTY_TO_LENGTH)
+        );
+    }
+
+    /**
+     * If {@code equalTo} compares a string-typed SlotReference against an empty-string literal,
+     * rewrites it to {@code length(slot) = 0}.  Returns the original expression unchanged otherwise.
+     */
+    private static Expression rewriteEqualToEmpty(EqualTo equalTo) {
+        if (ConnectContext.get().getStatementContext().isDelete()) {
+            return equalTo;
+        }
+        Expression left = equalTo.left();
+        Expression right = equalTo.right();
+
+        SlotReference slot = null;
+        if (isStringSlot(left) && isEmptyStringLiteral(right)) {
+            slot = (SlotReference) left;
+        } else if (isStringSlot(right) && isEmptyStringLiteral(left)) {
+            slot = (SlotReference) right;
+        }
+
+        if (slot == null) {
+            return equalTo;
+        }
+        return new EqualTo(new Length(slot), new IntegerLiteral(0));
+    }
+
+    private static boolean isStringSlot(Expression expr) {
+        return expr instanceof SlotReference && expr.getDataType().isStringLikeType();
+    }
+
+    private static boolean isEmptyStringLiteral(Expression expr) {
+        return expr instanceof Literal
+                && expr.getDataType().isStringLikeType()
+                && ((Literal) expr).getStringValue().isEmpty();
+    }
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathExpressionCollector.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathExpressionCollector.java
index d70682961f5..c8eafa2cf14 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathExpressionCollector.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathExpressionCollector.java
@@ -40,12 +40,15 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayReverseS
 import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySort;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySortBy;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySplit;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Cardinality;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementAt;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Lambda;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Length;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.MapContainsEntry;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.MapContainsKey;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.MapContainsValue;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.MapKeys;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.MapSize;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.MapValues;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.StructElement;
 import org.apache.doris.nereids.trees.expressions.literal.Literal;
@@ -127,9 +130,75 @@ public class AccessPathExpressionCollector extends DefaultExpressionVisitor<Void
             int slotId = slotReference.getExprId().asInt();
             slotToAccessPaths.put(slotId, new CollectAccessPathResult(path, context.bottomFilter, context.type));
         }
+        if (dataType.isStringLikeType()) {
+            int slotId = slotReference.getExprId().asInt();
+            if (!context.accessPathBuilder.isEmpty()) {
+                // Accessed via an offset-only function (e.g. length()).
+                // Builder already has "offset" at the tail; add the column name as prefix.
+                context.accessPathBuilder.addPrefix(slotReference.getName());
+                ImmutableList<String> path = ImmutableList.copyOf(context.accessPathBuilder.accessPath);
+                slotToAccessPaths.put(slotId,
+                        new CollectAccessPathResult(path, context.bottomFilter, TAccessPathType.DATA));
+            } else {
+                // Direct access to the string column → record a DATA path so that any
+                // concurrent offset-only path for the same slot is suppressed.
+                List<String> path = ImmutableList.of(slotReference.getName());
+                slotToAccessPaths.put(slotId,
+                        new CollectAccessPathResult(path, context.bottomFilter, TAccessPathType.DATA));
+            }
+        }
         return null;
     }
 
+    @Override
+    public Void visitLength(Length length, CollectorContext context) {
+        Expression arg = length.child(0);
+        // length() only needs the offset array, not the chars data.
+        // Add ACCESS_STRING_OFFSET as a suffix so the path builder accumulates
+        // e.g. ["str_col", "OFFSET"] or ["c_struct", "f3", "OFFSET"].
+        if (arg.getDataType().isStringLikeType() && context.accessPathBuilder.isEmpty()) {
+            CollectorContext offsetContext =
+                    new CollectorContext(context.statementContext, context.bottomFilter);
+            offsetContext.accessPathBuilder.addSuffix(AccessPathInfo.ACCESS_STRING_OFFSET);
+            return arg.accept(this, offsetContext);
+        }
+        // fall through to default (recurse into children with fresh contexts)
+        return visit(length, context);
+    }
+
+    @Override
+    public Void visitMapSize(MapSize mapSize, CollectorContext context) {
+        Expression arg = mapSize.child();
+        DataType argType = arg.getDataType();
+        if (argType.isMapType() && context.accessPathBuilder.isEmpty()) {
+            CollectorContext offsetContext =
+                    new CollectorContext(context.statementContext, context.bottomFilter);
+            offsetContext.accessPathBuilder.addSuffix(AccessPathInfo.ACCESS_STRING_OFFSET);
+            return arg.accept(this, offsetContext);
+        }
+        return visit(mapSize, context);
+    }
+
+    @Override
+    public Void visitCardinality(Cardinality cardinality, CollectorContext context) {
+        Expression arg = cardinality.child(0);
+        // cardinality(arr) / cardinality(map) only needs the offset array, not element data.
+        // Arrays and maps share the same offset-array + data storage layout as strings on the BE.
+        DataType argType = arg.getDataType();
+        if ((argType.isArrayType() || argType.isMapType()) && context.accessPathBuilder.isEmpty()) {
+            CollectorContext offsetContext =
+                    new CollectorContext(context.statementContext, context.bottomFilter);
+            offsetContext.accessPathBuilder.addSuffix(AccessPathInfo.ACCESS_STRING_OFFSET);
+            // cardinality(map_keys(m)) == cardinality(m) == cardinality(map_values(m)):
+            // all three count map entries, so emit the same [map_col, OFFSET] path.
+            Expression effectiveArg = (arg instanceof MapKeys || arg instanceof MapValues)
+                    ? arg.child(0) : arg;
+            return effectiveArg.accept(this, offsetContext);
+        }
+        // fall through to default
+        return visit(cardinality, context);
+    }
+
     @Override
     public Void visitArrayItemSlot(ArrayItemSlot arrayItemSlot, CollectorContext context) {
         if (nameToLambdaArguments.isEmpty()) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathInfo.java
index 2b9a34c21a6..864d4d69f8e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathInfo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathInfo.java
@@ -27,6 +27,9 @@ public class AccessPathInfo {
     public static final String ACCESS_ALL = "*";
     public static final String ACCESS_MAP_KEYS = "KEYS";
     public static final String ACCESS_MAP_VALUES = "VALUES";
+    // Suffix appended to a string-column path to indicate that only the offset array
+    // (not the char data) is needed — agreed with BE as the special path component name.
+    public static final String ACCESS_STRING_OFFSET = "OFFSET";
 
     private DataType prunedType;
     // allAccessPaths is used to record all access path include predicate access path and non-predicate access path,
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathPlanCollector.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathPlanCollector.java
index eb790b447e8..c738790dc7d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathPlanCollector.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathPlanCollector.java
@@ -33,6 +33,7 @@ import org.apache.doris.nereids.trees.expressions.functions.generator.PosExplode
 import org.apache.doris.nereids.trees.expressions.functions.generator.PosExplodeOuter;
 import org.apache.doris.nereids.trees.expressions.literal.StructLiteral;
 import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
 import org.apache.doris.nereids.trees.plans.logical.LogicalCTEAnchor;
 import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer;
 import org.apache.doris.nereids.trees.plans.logical.LogicalCTEProducer;
@@ -69,7 +70,9 @@ public class AccessPathPlanCollector extends DefaultPlanVisitor<Void, StatementC
     }
 
     private boolean shouldCollectAccessPath(Slot slot) {
-        return slot.getDataType() instanceof NestedColumnPrunable || slot.getDataType().isVariantType();
+        return slot.getDataType() instanceof NestedColumnPrunable
+                || slot.getDataType().isVariantType()
+                || slot.getDataType().isStringLikeType();
     }
 
     @Override
@@ -263,6 +266,15 @@ public class AccessPathPlanCollector extends DefaultPlanVisitor<Void, StatementC
         return filter.child().accept(this, context);
     }
 
+    @Override
+    public Void visitLogicalAggregate(LogicalAggregate<? extends Plan> aggregate, StatementContext context) {
+        // Collect access paths from aggregate expressions (e.g. sum(length(str_col))) before
+        // visiting children so that when the bottom project is processed next, str_col's offset
+        // path is already recorded and the direct-DATA suppression guard can fire correctly.
+        collectByExpressions(aggregate, context);
+        return aggregate.child().accept(this, context);
+    }
+
     @Override
     public Void visitLogicalCTEAnchor(
             LogicalCTEAnchor<? extends Plan, ? extends Plan> cteAnchor, StatementContext context) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java
index f30f7fb93e9..97370c261ab 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java
@@ -25,6 +25,8 @@ import org.apache.doris.nereids.rules.rewrite.AccessPathExpressionCollector.Coll
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Cardinality;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Length;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.visitor.CustomRewriter;
 import org.apache.doris.nereids.types.ArrayType;
@@ -80,7 +82,9 @@ public class NestedColumnPruning implements CustomRewriter {
             StatementContext statementContext = jobContext.getCascadesContext().getStatementContext();
             SessionVariable sessionVariable = statementContext.getConnectContext().getSessionVariable();
             if (!sessionVariable.enablePruneNestedColumns
-                    || (!statementContext.hasNestedColumns() && !containsVariant(plan))) {
+                    || (!statementContext.hasNestedColumns()
+                        && !containsVariant(plan)
+                        && !(containsStringLength(plan)))) {
                 return plan;
             }
 
@@ -104,6 +108,44 @@ public class NestedColumnPruning implements CustomRewriter {
         }
     }
 
+    /** Returns true when the plan tree contains length() applied to a string-type expression.
+     *  Used in the early-exit guard so that string offset optimizations are not skipped even
+     *  when no nested (struct/array/map) or variant columns are present. */
+    private static boolean containsStringLength(Plan plan) {
+        AtomicBoolean found = new AtomicBoolean(false);
+        plan.foreachUp(node -> {
+            if (found.get()) {
+                return;
+            }
+            Plan current = (Plan) node;
+            for (Expression expression : current.getExpressions()) {
+                if (expressionContainsStringLength(expression)) {
+                    found.set(true);
+                    return;
+                }
+            }
+        });
+        return found.get();
+    }
+
+    private static boolean expressionContainsStringLength(Expression expr) {
+        if (expr instanceof Length && expr.child(0).getDataType().isStringLikeType()) {
+            return true;
+        }
+        if (expr instanceof Cardinality) {
+            DataType argType = expr.child(0).getDataType();
+            if (argType.isArrayType() || argType.isMapType()) {
+                return true;
+            }
+        }
+        for (Expression child : expr.children()) {
+            if (expressionContainsStringLength(child)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private static boolean containsVariant(Plan plan) {
         AtomicBoolean hasVariant = new AtomicBoolean(false);
         plan.foreachUp(node -> {
@@ -183,6 +225,74 @@ public class NestedColumnPruning implements CustomRewriter {
             DataTypeAccessTree accessTree = kv.getValue();
             DataType prunedDataType = accessTree.pruneDataType().orElse(slot.getDataType());
 
+            if (slot.getDataType().isStringLikeType()) {
+                if (accessTree.hasStringOffsetOnlyAccess()) {
+                    // Offset-only access (e.g. length(str_col)): type stays varchar,
+                    // but we must still send the access path to BE so it skips the char data.
+                    List<TColumnAccessPath> allPaths = buildColumnAccessPaths(slot, allAccessPaths);
+                    result.put(slot.getExprId().asInt(),
+                            new AccessPathInfo(slot.getDataType(), allPaths, new ArrayList<>()));
+                }
+                // direct access (accessAll=true) or other: skip — no type change, no access paths needed.
+                continue;
+            }
+
+            if ((slot.getDataType().isArrayType() || slot.getDataType().isMapType())
+                    && accessTree.hasStringOffsetOnlyAccess()) {
+                // Offset-only access (e.g. length(arr_col) / length(map_col)): type stays unchanged,
+                // but we must send the OFFSET access path to BE so it skips element/key-value data.
+                List<TColumnAccessPath> allPaths = buildColumnAccessPaths(slot, allAccessPaths);
+                result.put(slot.getExprId().asInt(),
+                        new AccessPathInfo(slot.getDataType(), allPaths, new ArrayList<>()));
+                continue;
+            }
+
+            if (slot.getDataType().isMapType() && accessTree.hasMapValueOffsetOnlyAccess()) {
+                // length(map_col['key']): keys read in full (element lookup) + values offset-only.
+                // Emit [col, KEYS] and [col, VALUES, OFFSET] directly instead of the collected
+                // [col, *, OFFSET] path which the BE cannot interpret for split key/value access.
+                String colName = slot.getName().toLowerCase();
+                TDataAccessPath keysDataPath = new TDataAccessPath();
+                keysDataPath.setPath(
+                        new ArrayList<>(ImmutableList.of(colName, AccessPathInfo.ACCESS_MAP_KEYS)));
+                TColumnAccessPath keysColumnPath = new TColumnAccessPath(TAccessPathType.DATA);
+                keysColumnPath.setDataAccessPath(keysDataPath);
+
+                TDataAccessPath valsOffsetDataPath = new TDataAccessPath();
+                valsOffsetDataPath.setPath(new ArrayList<>(ImmutableList.of(
+                        colName, AccessPathInfo.ACCESS_MAP_VALUES, AccessPathInfo.ACCESS_STRING_OFFSET)));
+                TColumnAccessPath valsOffsetColumnPath = new TColumnAccessPath(TAccessPathType.DATA);
+                valsOffsetColumnPath.setDataAccessPath(valsOffsetDataPath);
+
+                result.put(slot.getExprId().asInt(), new AccessPathInfo(
+                        slot.getDataType(),
+                        ImmutableList.of(keysColumnPath, valsOffsetColumnPath),
+                        new ArrayList<>()));
+                continue;
+            }
+
+            // For array/map columns that are NOT in offset-only mode, strip OFFSET-suffix paths
+            // when a non-OFFSET path also exists for the same slot. This handles cases like
+            // `select cardinality(arr), arr[1]` where the OFFSET path from cardinality() is
+            // redundant because full element data is also needed.
+            // If the ONLY paths for a slot end in OFFSET (e.g. cardinality(arr[0].field) alone),
+            // keep them — they carry meaningful nested-access semantics.
+            if (slot.getDataType().isArrayType() || slot.getDataType().isMapType()) {
+                int slotId = slot.getExprId().asInt();
+                boolean hasNonOffsetPath = allAccessPaths.get(slotId).stream().anyMatch(p -> {
+                    List<String> path = p.second;
+                    return path.isEmpty()
+                            || !AccessPathInfo.ACCESS_STRING_OFFSET.equals(path.get(path.size() - 1));
+                });
+                if (hasNonOffsetPath) {
+                    allAccessPaths.get(slotId).removeIf(p -> {
+                        List<String> path = p.second;
+                        return !path.isEmpty()
+                                && AccessPathInfo.ACCESS_STRING_OFFSET.equals(
+                                        path.get(path.size() - 1));
+                    });
+                }
+            }
             List<TColumnAccessPath> allPaths = buildColumnAccessPaths(slot, allAccessPaths);
             result.put(slot.getExprId().asInt(),
                     new AccessPathInfo(prunedDataType, allPaths, new ArrayList<>()));
@@ -202,7 +312,9 @@ public class NestedColumnPruning implements CustomRewriter {
             List<TColumnAccessPath> predicatePaths =
                     buildColumnAccessPaths(slot, predicateAccessPaths);
             AccessPathInfo accessPathInfo = result.get(slot.getExprId().asInt());
-            accessPathInfo.getPredicateAccessPaths().addAll(predicatePaths);
+            if (accessPathInfo != null) {
+                accessPathInfo.getPredicateAccessPaths().addAll(predicatePaths);
+            }
         }
 
         for (Entry<Slot, DataType> kv : variantSlots.entrySet()) {
@@ -210,7 +322,9 @@ public class NestedColumnPruning implements CustomRewriter {
             List<TColumnAccessPath> predicatePaths =
                     buildColumnAccessPaths(slot, predicateAccessPaths);
             AccessPathInfo accessPathInfo = result.get(slot.getExprId().asInt());
-            accessPathInfo.getPredicateAccessPaths().addAll(predicatePaths);
+            if (accessPathInfo != null) {
+                accessPathInfo.getPredicateAccessPaths().addAll(predicatePaths);
+            }
         }
 
         return result;
@@ -271,6 +385,11 @@ public class NestedColumnPruning implements CustomRewriter {
         // if access 's.a.b' the node 's' and 'a' has accessPartialChild, and node 'b' has accessAll
         private boolean accessPartialChild;
         private boolean accessAll;
+        // True when this string-typed node is accessed ONLY via the offset array
+        // (e.g. length(str_col) or length(element_at(c_struct,'f3'))).
+        // When this flag is set and accessAll is NOT set, pruneDataType() returns BigIntType
+        // to signal that the BE only needs to read the offset array, not the chars data.
+        private boolean isStringOffsetOnly;
         // for the future, only access the meta of the column,
         // e.g. `is not null` can only access the column's offset, not need to read the data
         private TAccessPathType pathType;
@@ -312,6 +431,72 @@ public class NestedColumnPruning implements CustomRewriter {
             return children;
         }
 
+        /**
+         * True when a MAP column is accessed as {@code length(map_col['key'])}: the keys must
+         * be read in full (for the element lookup) while the values only need the offset array
+         * (since only their length, not their content, is used).
+         * Expected access paths: [col, KEYS] and [col, VALUES, OFFSET].
+         */
+        public boolean hasMapValueOffsetOnlyAccess() {
+            if (!isRoot) {
+                return false;
+            }
+            DataTypeAccessTree child = children.values().iterator().next();
+            if (!child.type.isMapType() || child.accessAll) {
+                return false;
+            }
+            DataTypeAccessTree keysChild = child.children.get(AccessPathInfo.ACCESS_MAP_KEYS);
+            DataTypeAccessTree valsChild = child.children.get(AccessPathInfo.ACCESS_MAP_VALUES);
+            // Keys must be fully accessed (element-at lookup).
+            if (!keysChild.accessAll) {
+                return false;
+            }
+            // Values must be accessed offset-only (no deeper element reads).
+            if (!valsChild.isStringOffsetOnly || valsChild.accessAll) {
+                return false;
+            }
+            if (valsChild.type.isStringLikeType()) {
+                // String value: accessAll check above is sufficient.
+                return true;
+            }
+            if (valsChild.type.isArrayType()) {
+                // Array value (e.g. MAP<STRING, ARRAY<INT>>): verify no element was read directly
+                // (e.g. map_col['k'][0] would set allChild.accessAll=true).
+                DataTypeAccessTree allChild = valsChild.children.get(AccessPathInfo.ACCESS_ALL);
+                return !allChild.accessAll && !allChild.accessPartialChild;
+            }
+            return true;
+        }
+
+        /** True when the column is accessed ONLY via the offset array (e.g. length(str_col),
+         *  length(arr_col), length(map_col)), meaning the type must not change but an access
+         *  path still needs to be sent to BE so it can skip the char/element data. */
+        public boolean hasStringOffsetOnlyAccess() {
+            if (isRoot) {
+                DataTypeAccessTree child = children.values().iterator().next();
+                if (!child.isStringOffsetOnly || child.accessAll) {
+                    return false;
+                }
+                if (child.type.isStringLikeType()) {
+                    return true;
+                }
+                if (child.type.isArrayType()) {
+                    // True only if no element was accessed (element_at / explode etc.)
+                    DataTypeAccessTree allChild = child.children.get(AccessPathInfo.ACCESS_ALL);
+                    return !allChild.accessAll && !allChild.accessPartialChild;
+                }
+                if (child.type.isMapType()) {
+                    // True only if neither keys nor values were accessed directly
+                    DataTypeAccessTree keysChild = child.children.get(AccessPathInfo.ACCESS_MAP_KEYS);
+                    DataTypeAccessTree valsChild = child.children.get(AccessPathInfo.ACCESS_MAP_VALUES);
+                    return !keysChild.accessAll && !keysChild.accessPartialChild
+                            && !valsChild.accessAll && !valsChild.accessPartialChild;
+                }
+                return false;
+            }
+            return type.isStringLikeType() && isStringOffsetOnly && !accessAll;
+        }
+
         /** pruneCastType */
         public DataType pruneCastType(DataTypeAccessTree origin, DataTypeAccessTree cast) {
             if (type instanceof StructType) {
@@ -417,6 +602,11 @@ public class NestedColumnPruning implements CustomRewriter {
                 }
                 return;
             } else if (this.type.isArrayType()) {
+                if (path.get(accessIndex).equals(AccessPathInfo.ACCESS_STRING_OFFSET)) {
+                    // length(array_col) — only the offset array is needed, not element data.
+                    isStringOffsetOnly = true;
+                    return;
+                }
                 DataTypeAccessTree child = children.get(AccessPathInfo.ACCESS_ALL);
                 if (path.get(accessIndex).equals(AccessPathInfo.ACCESS_ALL)) {
                     // enter this array and skip next *
@@ -425,6 +615,11 @@ public class NestedColumnPruning implements CustomRewriter {
                 return;
             } else if (this.type.isMapType()) {
                 String fieldName = path.get(accessIndex);
+                if (fieldName.equals(AccessPathInfo.ACCESS_STRING_OFFSET)) {
+                    // length(map_col) — only the offset array is needed, not key/value data.
+                    isStringOffsetOnly = true;
+                    return;
+                }
                 if (fieldName.equals(AccessPathInfo.ACCESS_ALL)) {
                     // access value by the key, so we should access key and access value, then prune the value's type.
                     // e.g. map_column['id'] should access the keys, and access the values
@@ -447,6 +642,16 @@ public class NestedColumnPruning implements CustomRewriter {
                     valuesChild.setAccessByPath(path, accessIndex + 1, pathType);
                     return;
                 }
+            } else if (type.isStringLikeType()) {
+                // String leaf accessed via the offset array (e.g. path ends in "offset").
+                // Mark offset-only so pruneDataType() can return BigIntType instead of full data.
+                if (path.get(accessIndex).equals(AccessPathInfo.ACCESS_STRING_OFFSET)) {
+                    isStringOffsetOnly = true;
+                    return; // do NOT set accessAll — offset-only is distinguishable from full access
+                }
+                // Any other sub-path on a string column means full data is needed.
+                accessAll = true;
+                return;
             } else if (isRoot) {
                 children.get(path.get(accessIndex).toLowerCase()).setAccessByPath(path, accessIndex + 1, pathType);
                 return;
@@ -484,6 +689,10 @@ public class NestedColumnPruning implements CustomRewriter {
                 return children.values().iterator().next().pruneDataType();
             } else if (accessAll) {
                 return Optional.of(type);
+            } else if (isStringOffsetOnly) {
+                // Only the offset array is accessed (e.g. length(str_col)).
+                // The slot type stays unchanged (varchar); the access path tells BE to skip char data.
+                return Optional.empty();
             } else if (!accessPartialChild) {
                 return Optional.empty();
             }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java
index 937f7ed5d50..3a5304b6a8a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java
@@ -92,7 +92,7 @@ public class PruneOlapScanPartition implements RewriteRuleFactory {
                         } else {
                             return PartitionPruner.prunePredicate(
                                     ctx.connectContext.getSessionVariable().skipPrunePredicate
-                                            || ctx.statementContext.isSkipPrunePredicate(),
+                                            || ctx.statementContext.isDelete(),
                                     prunedRes.second, filter, rewrittenLogicalRelation);
                         }
                     }).toRule(RuleType.OLAP_SCAN_PARTITION_PRUNE)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SlotTypeReplacer.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SlotTypeReplacer.java
index e1536918dcb..068afd626ff 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SlotTypeReplacer.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SlotTypeReplacer.java
@@ -724,7 +724,8 @@ public class SlotTypeReplacer extends DefaultPlanRewriter<Void> {
             for (Slot slot : output) {
                 int slotId = slot.getExprId().asInt();
                 if ((slot.getDataType() instanceof NestedColumnPrunable
-                        || slot.getDataType().isVariantType())
+                        || slot.getDataType().isVariantType()
+                        || slot.getDataType().isStringLikeType())
                         && replacedDataTypes.containsKey(slotId)) {
                     shouldReplaceSlots.add(slotId);
                     shouldPrune = true;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java
index fb31242503a..d939d278dde 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java
@@ -159,8 +159,7 @@ public class DeleteFromCommand extends Command implements ForwardWithSync, Expla
         LogicalPlanAdapter logicalPlanAdapter = new LogicalPlanAdapter(logicalQuery, ctx.getStatementContext());
         updateSessionVariableForDelete(ctx.getSessionVariable());
         StatementContext statementContext = ctx.getStatementContext();
-        // delete not prune predicate after partition prune
-        statementContext.setSkipPrunePredicate(true);
+        statementContext.setIsDelete(true);
         NereidsPlanner planner = new NereidsPlanner(statementContext);
         boolean originalIsSkipAuth = ctx.isSkipAuth();
         // delete not need select priv
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExplainCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExplainCommand.java
index e2194048e48..cb3785ae106 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExplainCommand.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExplainCommand.java
@@ -90,7 +90,7 @@ public class ExplainCommand extends Command implements NoForward {
             ctx.getStatementContext().setIsInsert(true);
         }
         if (explainable instanceof DeleteFromCommand) {
-            ctx.getStatementContext().setSkipPrunePredicate(true);
+            ctx.getStatementContext().setIsDelete(true);
         }
         explainPlan = ((LogicalPlan) explainable.getExplainPlan(ctx));
         NereidsPlanner planner = explainable.getExplainPlanner(explainPlan, ctx.getStatementContext()).orElseGet(() ->
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
index b8987334668..5376f31b10f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
@@ -69,11 +69,13 @@ import org.apache.doris.nereids.trees.expressions.functions.generator.PosExplode
 import org.apache.doris.nereids.trees.expressions.functions.generator.PosExplodeOuter;
 import org.apache.doris.nereids.trees.expressions.functions.generator.Unnest;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.If;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Length;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.NullIf;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Nvl;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.UniqueFunction;
 import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.ComparableLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.Literal;
 import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
@@ -954,6 +956,15 @@ public class ExpressionUtils {
         if (expression instanceof EqualTo) {
             if (isInjective(expression.child(0)) && expression.child(1).isConstant()) {
                 builder.put((Slot) expression.child(0), expression.child(1));
+            } else {
+                // length(str_col)=0 => str_col=''
+                if (expression.child(0) instanceof Length
+                        && expression.child(1).equals(new IntegerLiteral(0))) {
+                    Length len = (Length) expression.child(0);
+                    if (len.child() instanceof Slot && len.child().getDataType().isStringLikeType()) {
+                        builder.put((Slot) len.child(), new StringLiteral(""));
+                    }
+                }
             }
         }
         return builder.build();
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/StringEmptyToLengthRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/StringEmptyToLengthRuleTest.java
new file mode 100644
index 00000000000..c73cc5ae1b8
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/StringEmptyToLengthRuleTest.java
@@ -0,0 +1,141 @@
+// 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.rules.expression.rules;
+
+import org.apache.doris.nereids.rules.expression.ExpressionRewriteTestHelper;
+import org.apache.doris.nereids.rules.expression.ExpressionRuleExecutor;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Not;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Length;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.types.VarcharType;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class StringEmptyToLengthRuleTest extends ExpressionRewriteTestHelper {
+
+    @BeforeEach
+    public void setup() {
+        executor = new ExpressionRuleExecutor(ImmutableList.of(
+                bottomUp(StringEmptyToLengthRule.INSTANCE)
+        ));
+    }
+
+    // ─── Helper: rewrite without type coercion ───────────────────────────────────
+    // We bypass ExpressionRewriteTestHelper.assertRewrite() because that method
+    // applies typeCoercion() to the input, which may wrap string literals in Cast
+    // nodes and prevent our pattern from matching.
+
+    private void assertRuleRewrite(Expression before, Expression expected) {
+        Expression result = executor.rewrite(before, context);
+        Assertions.assertEquals(expected, result);
+    }
+
+    private void assertRuleNoRewrite(Expression before) {
+        Expression result = executor.rewrite(before, context);
+        Assertions.assertEquals(before, result);
+    }
+
+    // ─── Rewrite cases ───────────────────────────────────────────────────────────
+
+    @Test
+    public void testStringSlotEqualEmptyRewrite() {
+        // str_col = '' → length(str_col) = 0
+        SlotReference slot = new SlotReference("str_col", StringType.INSTANCE, true);
+        VarcharLiteral empty = new VarcharLiteral("");
+        assertRuleRewrite(
+                new EqualTo(slot, empty),
+                new EqualTo(new Length(slot), new IntegerLiteral(0))
+        );
+    }
+
+    @Test
+    public void testVarcharSlotEqualEmptyRewrite() {
+        // varchar_col = '' → length(varchar_col) = 0
+        SlotReference slot = new SlotReference("vc_col", VarcharType.SYSTEM_DEFAULT, true);
+        VarcharLiteral empty = new VarcharLiteral("");
+        assertRuleRewrite(
+                new EqualTo(slot, empty),
+                new EqualTo(new Length(slot), new IntegerLiteral(0))
+        );
+    }
+
+    @Test
+    public void testReversedOperandsRewrite() {
+        // '' = str_col (literal on left) → length(str_col) = 0
+        SlotReference slot = new SlotReference("str_col", StringType.INSTANCE, true);
+        VarcharLiteral empty = new VarcharLiteral("");
+        assertRuleRewrite(
+                new EqualTo(empty, slot),
+                new EqualTo(new Length(slot), new IntegerLiteral(0))
+        );
+    }
+
+    @Test
+    public void testNotEqualToEmptyRewrite() {
+        // NOT(str_col = '') → NOT(length(str_col) = 0)  (i.e. str_col <> '')
+        SlotReference slot = new SlotReference("str_col", StringType.INSTANCE, true);
+        VarcharLiteral empty = new VarcharLiteral("");
+        assertRuleRewrite(
+                new Not(new EqualTo(slot, empty)),
+                new Not(new EqualTo(new Length(slot), new IntegerLiteral(0)))
+        );
+    }
+
+    @Test
+    public void testNotEqualToEmptyReversedRewrite() {
+        // NOT('' = str_col) → NOT(length(str_col) = 0)
+        SlotReference slot = new SlotReference("str_col", StringType.INSTANCE, true);
+        VarcharLiteral empty = new VarcharLiteral("");
+        assertRuleRewrite(
+                new Not(new EqualTo(empty, slot)),
+                new Not(new EqualTo(new Length(slot), new IntegerLiteral(0)))
+        );
+    }
+
+    // ─── No-op cases ─────────────────────────────────────────────────────────────
+
+    @Test
+    public void testNonEmptyLiteralNotRewritten() {
+        // str_col = 'abc' — literal is non-empty, must not be rewritten
+        SlotReference slot = new SlotReference("str_col", StringType.INSTANCE, true);
+        assertRuleNoRewrite(new EqualTo(slot, new VarcharLiteral("abc")));
+    }
+
+    @Test
+    public void testNonStringSlotNotRewritten() {
+        // int_col = 0 — slot is not string-like, must not be rewritten
+        SlotReference intSlot = new SlotReference("int_col", IntegerType.INSTANCE, true);
+        assertRuleNoRewrite(new EqualTo(intSlot, new IntegerLiteral(0)));
+    }
+
+    @Test
+    public void testNotWithNonEmptyLiteralNotRewritten() {
+        // NOT(str_col = 'abc') — non-empty literal, must not be rewritten
+        SlotReference slot = new SlotReference("str_col", StringType.INSTANCE, true);
+        assertRuleNoRewrite(new Not(new EqualTo(slot, new VarcharLiteral("abc"))));
+    }
+}
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PruneNestedColumnTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PruneNestedColumnTest.java
index 1dfbca127de..ae4fe67a802 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PruneNestedColumnTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PruneNestedColumnTest.java
@@ -100,6 +100,13 @@ public class PruneNestedColumnTest extends TestWithFeService implements MemoPatt
                 + "  v variant\n"
                 + ") properties ('replication_num'='1')");
 
+        // Table for string-length offset-only optimization tests
+        createTable("create table str_tbl(\n"
+                + "  id int,\n"
+                + "  str_col string,\n"
+                + "  c_struct struct<f1: int, f3: string>\n"
+                + ") properties ('replication_num'='1')");
+
         connectContext.getSessionVariable().setDisableNereidsRules(RuleType.PRUNE_EMPTY_PARTITION.name());
         connectContext.getSessionVariable().enableNereidsTimeout = false;
     }
@@ -1176,6 +1183,95 @@ public class PruneNestedColumnTest extends TestWithFeService implements MemoPatt
         }
     }
 
+    // @Test
+    // public void testStringLengthPruning() {
+    //     // ── Case 1: length(str_col) only ─ offset-only optimization applied ──────────
+    //     assertStringColumn(
+    //             "select length(str_col) from str_tbl",
+    //             "str_col",
+    //             true,
+    //             ImmutableList.of(path("str_col", "offset")));
+
+    //     // ── Case 2: length(str_col) + direct projection of str_col ─ suppressed ─────
+    //     assertStringColumn(
+    //             "select length(str_col), str_col from str_tbl",
+    //             "str_col",
+    //             false,
+    //             ImmutableList.of());
+
+    //     // ── Case 3: length(str_col) + substr(str_col, …) ─ suppressed ───────────────
+    //     assertStringColumn(
+    //             "select length(str_col), substr(str_col, 2) from str_tbl",
+    //             "str_col",
+    //             false,
+    //             ImmutableList.of());
+
+    //     // ── Case 4: length applied to a struct field ─ struct pruned to bigint field ─
+    //     // c_struct has {f1:int, f3:string}; only f3 accessed offset-only →
+    //     // pruned type is struct<f3:bigint>, access path is DATA(["c_struct","f3","offset"])
+    //     assertColumn(
+    //             "select length(struct_element(c_struct, 'f3')) from str_tbl",
+    //             "struct<f3:bigint>",
+    //             ImmutableList.of(path("c_struct", "f3", "offset")),
+    //             ImmutableList.of());
+
+    //     // ── Case 5: length(struct field) + direct read of same field ─ suppressed ───
+    //     // Both the full-data path ["c_struct","f3"] and offset path ["c_struct","f3","offset"]
+    //     // are recorded; f3 pruneDataType() sees accessAll=true → returns text (not bigint).
+    //     assertColumn(
+    //             "select length(struct_element(c_struct, 'f3')), struct_element(c_struct, 'f3') from str_tbl",
+    //             "struct<f3:text>",
+    //             ImmutableList.of(path("c_struct", "f3"), path("c_struct", "f3", "offset")),
+    //             ImmutableList.of());
+    // }
+
+    // /**
+    //  * Verify that a specific string-typed column in the rewritten LogicalOlapScan either has
+    //  * BigIntType (offset-only optimization applied) or retains its original string type (suppressed).
+    //  *
+    //  * @param sql              query to analyze and rewrite
+    //  * @param columnName       name of the string column to inspect
+    //  * @param expectOptimized  true → expect BigIntType + access paths; false → expect string type
+    //  * @param expectAllPaths   expected access paths when {@code expectOptimized} is true
+    //  */
+    // private void assertStringColumn(String sql, String columnName,
+    //         boolean expectOptimized, List<TColumnAccessPath> expectAllPaths) {
+    //     Plan rewritePlan = PlanChecker.from(connectContext)
+    //             .analyze(sql)
+    //             .rewrite()
+    //             .getCascadesContext()
+    //             .getRewritePlan();
+
+    //     LogicalOlapScan scan = rewritePlan.collect(LogicalOlapScan.class::isInstance)
+    //             .stream()
+    //             .map(p -> (LogicalOlapScan) p)
+    //             .findFirst()
+    //             .orElseThrow(() -> new AssertionError("No LogicalOlapScan in plan for: " + sql));
+
+    //     for (Slot slot : scan.getOutput()) {
+    //         if (!slot.getName().equalsIgnoreCase(columnName)) {
+    //             continue;
+    //         }
+    //         SlotReference slotRef = (SlotReference) slot;
+    //         if (expectOptimized) {
+    //             Assertions.assertEquals(BigIntType.INSTANCE, slotRef.getDataType(),
+    //                     "Slot '" + columnName + "' should be BigIntType after offset-only optimization");
+    //             Optional<List<TColumnAccessPath>> allPaths = slotRef.getAllAccessPaths();
+    //             Assertions.assertTrue(allPaths.isPresent() && !allPaths.get().isEmpty(),
+    //                     "Slot '" + columnName + "' should have access paths set");
+    //             Assertions.assertEquals(
+    //                     new TreeSet<>(expectAllPaths),
+    //                     new TreeSet<>(allPaths.get()),
+    //                     "Unexpected access paths for slot '" + columnName + "'");
+    //         } else {
+    //             Assertions.assertNotEquals(BigIntType.INSTANCE, slotRef.getDataType(),
+    //                     "Slot '" + columnName + "' should NOT be BigIntType (optimization suppressed)");
+    //         }
+    //         return;
+    //     }
+    //     Assertions.fail("Column '" + columnName + "' not found in LogicalOlapScan output for: " + sql);
+    // }
+
     private Pair<PhysicalPlan, List<SlotDescriptor>> collectComplexSlots(String sql) throws Exception {
         NereidsPlanner planner = (NereidsPlanner) executeNereidsSql(sql).planner();
         List<SlotDescriptor> complexSlots = new ArrayList<>();
diff --git a/regression-test/data/nereids_rules_p0/defer_materialize_topn/lazy_materialize_topn.out b/regression-test/data/nereids_rules_p0/defer_materialize_topn/lazy_materialize_topn.out
new file mode 100644
index 00000000000..ddc91a442d2
--- /dev/null
+++ b/regression-test/data/nereids_rules_p0/defer_materialize_topn/lazy_materialize_topn.out
@@ -0,0 +1,6 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !two_phase_sort --
+1	10	aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa	bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+2	20	cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc	dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
+3	30	eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee	ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+
diff --git a/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out b/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out
index 9b1274a93a4..f1acddd2575 100644
--- a/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out
+++ b/regression-test/data/nereids_rules_p0/filter_push_down/push_filter_through.out
@@ -49,7 +49,7 @@ PhysicalResultSink
 -- !filter_join_inner --
 PhysicalResultSink
 --hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=()
-----filter((t1.msg = ''))
+----filter((length(msg) = 0))
 ------PhysicalOlapScan[t1]
 ----PhysicalOlapScan[t2]
 
@@ -319,9 +319,9 @@ PhysicalResultSink
 PhysicalResultSink
 --PhysicalExcept
 ----filter((id = 2))
-------filter((t1.msg = ''))
+------filter((length(msg) = 0))
 --------PhysicalOlapScan[t1]
-----filter((t2.id = 2) and (t2.msg = ''))
+----filter((length(msg) = 0) and (t2.id = 2))
 ------PhysicalOlapScan[t2]
 
 -- !push_filter_except --
@@ -366,6 +366,6 @@ PhysicalResultSink
 ----PhysicalQuickSort[LOCAL_SORT]
 ------PhysicalWindow
 --------PhysicalQuickSort[LOCAL_SORT]
-----------filter(OR[(t1.msg = ''),(t1.id = 2)])
+----------filter(OR[(length(msg) = 0),(t1.id = 2)])
 ------------PhysicalOlapScan[t1]
 
diff --git a/regression-test/data/query_p0/eliminate_outer_join/eliminate_outer_join.out b/regression-test/data/query_p0/eliminate_outer_join/eliminate_outer_join.out
index 235247efe84..2449cf55b94 100644
--- a/regression-test/data/query_p0/eliminate_outer_join/eliminate_outer_join.out
+++ b/regression-test/data/query_p0/eliminate_outer_join/eliminate_outer_join.out
@@ -54,7 +54,7 @@ SyntaxError:
 -- !4 --
 PhysicalResultSink
 --hashJoin[LEFT_OUTER_JOIN] hashCondition=((region.r_regionkey = nation.n_regionkey)) otherCondition=()
-----filter(( not r_name IS NULL) and (region.r_name = ''))
+----filter(( not r_name IS NULL) and (length(r_name) = 0))
 ------PhysicalOlapScan[region]
 ----PhysicalOlapScan[nation]
 
@@ -67,7 +67,7 @@ SyntaxError:
 PhysicalResultSink
 --hashJoin[LEFT_OUTER_JOIN] hashCondition=((nation.n_nationkey = supplier.s_suppkey)) otherCondition=()
 ----hashJoin[LEFT_OUTER_JOIN] hashCondition=((region.r_regionkey = nation.n_regionkey)) otherCondition=()
-------filter(( not r_name IS NULL) and (region.r_name = ''))
+------filter(( not r_name IS NULL) and (length(r_name) = 0))
 --------PhysicalOlapScan[region]
 ------PhysicalOlapScan[nation]
 ----PhysicalOlapScan[supplier]
@@ -82,7 +82,7 @@ PhysicalResultSink
 --hashJoin[LEFT_OUTER_JOIN] hashCondition=((partsupp.ps_suppkey = supplier.s_suppkey)) otherCondition=()
 ----hashJoin[LEFT_OUTER_JOIN] hashCondition=((nation.n_nationkey = supplier.s_suppkey)) otherCondition=()
 ------hashJoin[LEFT_OUTER_JOIN] hashCondition=((region.r_regionkey = nation.n_regionkey)) otherCondition=()
---------filter(( not r_name IS NULL) and (region.r_name = ''))
+--------filter(( not r_name IS NULL) and (length(r_name) = 0))
 ----------PhysicalOlapScan[region]
 --------PhysicalOlapScan[nation]
 ------PhysicalOlapScan[supplier]
@@ -115,7 +115,7 @@ PhysicalResultSink
 --hashJoin[LEFT_OUTER_JOIN] hashCondition=((partsupp.ps_suppkey = supplier.s_suppkey)) otherCondition=()
 ----hashJoin[LEFT_OUTER_JOIN] hashCondition=((nation.n_nationkey = supplier.s_suppkey)) otherCondition=()
 ------hashJoin[INNER_JOIN] hashCondition=((region.r_regionkey = nation.n_regionkey)) otherCondition=()
---------filter(( not r_name IS NULL) and ( not r_regionkey IS NULL) and (region.r_name = ''))
+--------filter(( not r_name IS NULL) and ( not r_regionkey IS NULL) and (length(r_name) = 0))
 ----------PhysicalOlapScan[region]
 --------filter(( not n_regionkey IS NULL))
 ----------PhysicalOlapScan[nation]
@@ -132,7 +132,7 @@ PhysicalResultSink
 --hashJoin[LEFT_OUTER_JOIN] hashCondition=((partsupp.ps_suppkey = supplier.s_suppkey)) otherCondition=()
 ----hashJoin[INNER_JOIN] hashCondition=((nation.n_nationkey = supplier.s_suppkey)) otherCondition=()
 ------hashJoin[INNER_JOIN] hashCondition=((region.r_regionkey = nation.n_regionkey)) otherCondition=()
---------filter(( not r_name IS NULL) and ( not r_regionkey IS NULL) and (region.r_name = ''))
+--------filter(( not r_name IS NULL) and ( not r_regionkey IS NULL) and (length(r_name) = 0))
 ----------PhysicalOlapScan[region]
 --------filter(( not n_regionkey IS NULL))
 ----------PhysicalOlapScan[nation]
diff --git a/regression-test/data/shape_check/clickbench/query11.out b/regression-test/data/shape_check/clickbench/query11.out
index 4b5e4486d3f..2ff48a34cad 100644
--- a/regression-test/data/shape_check/clickbench/query11.out
+++ b/regression-test/data/shape_check/clickbench/query11.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (MobilePhoneModel = '')))
+----------------filter(( not (length(MobilePhoneModel) = 0)))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query12.out b/regression-test/data/shape_check/clickbench/query12.out
index 10928363a83..2c2148174a1 100644
--- a/regression-test/data/shape_check/clickbench/query12.out
+++ b/regression-test/data/shape_check/clickbench/query12.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (MobilePhoneModel = '')))
+----------------filter(( not (length(MobilePhoneModel) = 0)))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query13.out b/regression-test/data/shape_check/clickbench/query13.out
index ce6675dc3bb..0856fc73a84 100644
--- a/regression-test/data/shape_check/clickbench/query13.out
+++ b/regression-test/data/shape_check/clickbench/query13.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (SearchPhrase = '')))
+----------------filter(( not (length(SearchPhrase) = 0)))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query14.out b/regression-test/data/shape_check/clickbench/query14.out
index 35eedce41b9..59f29de703e 100644
--- a/regression-test/data/shape_check/clickbench/query14.out
+++ b/regression-test/data/shape_check/clickbench/query14.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (SearchPhrase = '')))
+----------------filter(( not (length(SearchPhrase) = 0)))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query15.out b/regression-test/data/shape_check/clickbench/query15.out
index bf7f267f0e4..a2eb22e6f2b 100644
--- a/regression-test/data/shape_check/clickbench/query15.out
+++ b/regression-test/data/shape_check/clickbench/query15.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (SearchPhrase = '')))
+----------------filter(( not (length(SearchPhrase) = 0)))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query22.out b/regression-test/data/shape_check/clickbench/query22.out
index d5274c3548e..02b2d803778 100644
--- a/regression-test/data/shape_check/clickbench/query22.out
+++ b/regression-test/data/shape_check/clickbench/query22.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (SearchPhrase = '')) and (URL like '%google%'))
+----------------filter(( not (length(SearchPhrase) = 0)) and (URL like '%google%'))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query23.out b/regression-test/data/shape_check/clickbench/query23.out
index 76a91b3ad49..e38fca278f5 100644
--- a/regression-test/data/shape_check/clickbench/query23.out
+++ b/regression-test/data/shape_check/clickbench/query23.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (SearchPhrase = '')) and ( not (URL like '%.google.%')) and (Title like '%Google%'))
+----------------filter(( not (URL like '%.google.%')) and ( not (length(SearchPhrase) = 0)) and (Title like '%Google%'))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query25.out b/regression-test/data/shape_check/clickbench/query25.out
index 271149db672..436a325ed91 100644
--- a/regression-test/data/shape_check/clickbench/query25.out
+++ b/regression-test/data/shape_check/clickbench/query25.out
@@ -6,6 +6,6 @@ PhysicalResultSink
 ------PhysicalDistribute[DistributionSpecGather]
 --------PhysicalTopN[LOCAL_SORT]
 ----------PhysicalProject
-------------filter(( not (SearchPhrase = '')))
+------------filter(( not (length(SearchPhrase) = 0)))
 --------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query26.out b/regression-test/data/shape_check/clickbench/query26.out
index 7317f810a3b..373df683ec4 100644
--- a/regression-test/data/shape_check/clickbench/query26.out
+++ b/regression-test/data/shape_check/clickbench/query26.out
@@ -5,6 +5,6 @@ PhysicalResultSink
 ----PhysicalDistribute[DistributionSpecGather]
 ------PhysicalTopN[LOCAL_SORT]
 --------PhysicalProject
-----------filter(( not (SearchPhrase = '')))
+----------filter(( not (length(SearchPhrase) = 0)))
 ------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query27.out b/regression-test/data/shape_check/clickbench/query27.out
index 1dbae1e0dc1..e551d03fc48 100644
--- a/regression-test/data/shape_check/clickbench/query27.out
+++ b/regression-test/data/shape_check/clickbench/query27.out
@@ -6,6 +6,6 @@ PhysicalResultSink
 ------PhysicalDistribute[DistributionSpecGather]
 --------PhysicalTopN[LOCAL_SORT]
 ----------PhysicalProject
-------------filter(( not (SearchPhrase = '')))
+------------filter(( not (length(SearchPhrase) = 0)))
 --------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query28.out b/regression-test/data/shape_check/clickbench/query28.out
index e5cb28eab7a..7b07ad4defb 100644
--- a/regression-test/data/shape_check/clickbench/query28.out
+++ b/regression-test/data/shape_check/clickbench/query28.out
@@ -9,6 +9,6 @@ PhysicalResultSink
 ------------PhysicalDistribute[DistributionSpecHash]
 --------------hashAgg[LOCAL]
 ----------------PhysicalProject
-------------------filter(( not (URL = '')))
+------------------filter(( not (length(URL) = 0)))
 --------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query29.out b/regression-test/data/shape_check/clickbench/query29.out
index 01e642b5b43..d1ed207fcdb 100644
--- a/regression-test/data/shape_check/clickbench/query29.out
+++ b/regression-test/data/shape_check/clickbench/query29.out
@@ -9,6 +9,6 @@ PhysicalResultSink
 ------------PhysicalDistribute[DistributionSpecHash]
 --------------hashAgg[LOCAL]
 ----------------PhysicalProject
-------------------filter(( not (Referer = '')))
+------------------filter(( not (length(Referer) = 0)))
 --------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query31.out b/regression-test/data/shape_check/clickbench/query31.out
index a662fac4ef4..fc6a57d2e1e 100644
--- a/regression-test/data/shape_check/clickbench/query31.out
+++ b/regression-test/data/shape_check/clickbench/query31.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (SearchPhrase = '')))
+----------------filter(( not (length(SearchPhrase) = 0)))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query32.out b/regression-test/data/shape_check/clickbench/query32.out
index 29828472cca..60bbde67814 100644
--- a/regression-test/data/shape_check/clickbench/query32.out
+++ b/regression-test/data/shape_check/clickbench/query32.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (SearchPhrase = '')))
+----------------filter(( not (length(SearchPhrase) = 0)))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query37.out b/regression-test/data/shape_check/clickbench/query37.out
index 757b4f64df4..58405571e13 100644
--- a/regression-test/data/shape_check/clickbench/query37.out
+++ b/regression-test/data/shape_check/clickbench/query37.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (URL = '')) and (hits.CounterID = 62) and (hits.DontCountHits = 0) and (hits.EventDate <= '2013-07-31') and (hits.EventDate >= '2013-07-01') and (hits.IsRefresh = 0))
+----------------filter(( not (length(URL) = 0)) and (hits.CounterID = 62) and (hits.DontCountHits = 0) and (hits.EventDate <= '2013-07-31') and (hits.EventDate >= '2013-07-01') and (hits.IsRefresh = 0))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/data/shape_check/clickbench/query38.out b/regression-test/data/shape_check/clickbench/query38.out
index 37d0392a7b2..a7bb448d799 100644
--- a/regression-test/data/shape_check/clickbench/query38.out
+++ b/regression-test/data/shape_check/clickbench/query38.out
@@ -8,6 +8,6 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------filter(( not (Title = '')) and (hits.CounterID = 62) and (hits.DontCountHits = 0) and (hits.EventDate <= '2013-07-31') and (hits.EventDate >= '2013-07-01') and (hits.IsRefresh = 0))
+----------------filter(( not (length(Title) = 0)) and (hits.CounterID = 62) and (hits.DontCountHits = 0) and (hits.EventDate <= '2013-07-31') and (hits.EventDate >= '2013-07-01') and (hits.IsRefresh = 0))
 ------------------PhysicalOlapScan[hits]
 
diff --git a/regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy b/regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy
new file mode 100644
index 00000000000..ba089f735a1
--- /dev/null
+++ b/regression-test/suites/nereids_rules_p0/column_pruning/string_length_column_pruning.groovy
@@ -0,0 +1,338 @@
+// 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.
+
+// Regression tests for the string-length OFFSET-only optimization.
+//
+// When length() is the *only* use of a string column (or a string field inside a
+// struct), the FE should emit a DATA access path with an extra "OFFSET" component so
+// that the BE can satisfy the query by reading only the OFFSET array instead of the
+// full chars data.  The EXPLAIN plan should show:
+//   nested columns: <col>:[DATA(<col>.OFFSET)]
+//
+// Crucially, the slot type must remain varchar (not bigint), and any predicate
+// using length() must be preserved as-is (e.g. "length(str_col) > 1"), never
+// rewritten to "CAST(str_col AS int) > 1".
+//
+// When the same string column is also read directly (e.g. projected, passed to
+// substr(), …) the optimization must be suppressed: no nested-columns entry for
+// the plain string column should appear.
+
+suite("string_length_column_pruning") {
+    sql """ DROP TABLE IF EXISTS slcp_str_tbl """
+    sql """
+        CREATE TABLE slcp_str_tbl (
+            id       INT,
+            str_col  STRING,
+            struct_col STRUCT<f1: INT, f3: STRING>,
+            arr_col  ARRAY<INT>,
+            map_col  MAP<STRING, STRING>,
+            map_arr_col MAP<STRING, ARRAY<INT>>
+        ) ENGINE = OLAP
+        DUPLICATE KEY(id)
+        DISTRIBUTED BY HASH(id) BUCKETS 1
+        PROPERTIES ("replication_allocation" = "tag.location.default: 1")
+    """
+    sql """
+        INSERT INTO slcp_str_tbl VALUES
+            (1, 'hello', named_struct('f1', 10, 'f3', 'world'), [1, 2, 3], {'a': 'x', 'b': 'y'}, {'a': [1, 2], 'b': [3]})
+    """
+
+    // ─── Optimizable cases ──────────────────────────────────────────────────────
+
+    // Plain string column: length() is the only use → OFFSET access path emitted,
+    // slot type stays varchar (not bigint).
+    explain {
+        sql "select length(str_col) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+    sql "select length(str_col) from slcp_str_tbl"
+    // Struct string field: length(struct_element) is the only use
+    explain {
+        sql "select length(struct_element(struct_col, 'f3')) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+    //sql "select length(struct_element(struct_col, 'f3')) from slcp_str_tbl"
+    // length() in both SELECT and WHERE: predicate must remain length(str_col) > 1,
+    // never be rewritten to CAST(str_col AS int) > 1. Slot type must stay varchar.
+    explain {
+        sql "select length(str_col) from slcp_str_tbl where length(str_col) > 1"
+        contains "nested columns"
+        contains "OFFSET"
+        contains "length(str_col"
+        notContains "CAST(str_col"
+        notContains "type=bigint"
+    }
+    sql "select length(str_col) from slcp_str_tbl where length(str_col) > 1"
+
+    // ─── Aggregate cases ─────────────────────────────────────────────────────────
+
+    // sum(length(str_col)): length() is still the only consumer of str_col → OFFSET path applies.
+    explain {
+        sql "select sum(length(str_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+    sql "select sum(length(str_col)) from slcp_str_tbl"
+    // count(length(str_col))
+    explain {
+        sql "select count(length(str_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // max(length(str_col))
+    explain {
+        sql "select max(length(str_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+    sql "select max(length(str_col)) from slcp_str_tbl"
+    // ─── Array column cases ──────────────────────────────────────────────────────
+
+    // cardinality(arr_col): only the offset array is needed → OFFSET access path emitted,
+    // slot type stays ARRAY (not bigint).
+    explain {
+        sql "select cardinality(arr_col) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+    sql "select cardinality(arr_col) from slcp_str_tbl"
+    // cardinality(arr_col) in aggregate: OFFSET still applies.
+    explain {
+        sql "select sum(cardinality(arr_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+    sql "select sum(cardinality(arr_col)) from slcp_str_tbl"
+    // arr_col also accessed via element_at → full element data needed, OFFSET suppressed.
+    explain {
+        sql "select cardinality(arr_col), arr_col[1] from slcp_str_tbl"
+        notContains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // ─── Map column cases ────────────────────────────────────────────────────────
+
+    // cardinality(map_col): only the offset array is needed → OFFSET access path emitted,
+    // slot type stays MAP (not bigint).
+    explain {
+        sql "select cardinality(map_col) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+    sql "select cardinality(map_col) from slcp_str_tbl"
+
+    // cardinality(map_col) in aggregate: OFFSET still applies.
+    explain {
+        sql "select sum(cardinality(map_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    explain {
+        sql "select sum(map_size(map_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // cardinality(map_keys(map_col)): only the keys offset array is needed → OFFSET access path emitted.
+    explain {
+        sql "select cardinality(map_keys(map_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    explain {
+        sql "select cardinality(map_values(map_col)) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // cardinality(map_keys(map_col)) in aggregate: OFFSET still applies.
+    explain {
+        sql "select sum(cardinality(map_keys(map_col))) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    explain {
+        sql "select sum(cardinality(map_values(map_col))) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // Both map_keys and map_values sizes in the same query: both equal cardinality(map),
+    // so only a single [map_col, OFFSET] path is needed.
+    explain {
+        sql "select sum(cardinality(map_keys(map_col))), sum(cardinality(map_values(map_col))) from slcp_str_tbl"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // map_col also accessed via map_keys → full key data needed, OFFSET suppressed.
+    explain {
+        sql "select cardinality(map_col), map_keys(map_col) from slcp_str_tbl"
+        notContains "type=bigint"
+    }
+
+    // ─── Map with complex value cases ────────────────────────────────────────────
+
+    // cardinality(map_arr_col['a']): value is ARRAY<INT>.
+    // Keys read in full (element lookup); values need only the OFFSET array (array size).
+    // Expected paths: map_arr_col.KEYS + map_arr_col.VALUES.OFFSET
+    explain {
+        sql "select cardinality(map_arr_col['a']) from slcp_str_tbl"
+        contains "nested columns"
+        contains "KEYS"
+        contains "VALUES"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // same in aggregate
+    explain {
+        sql "select sum(cardinality(map_arr_col['a'])) from slcp_str_tbl"
+        contains "nested columns"
+        contains "KEYS"
+        contains "VALUES"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // value also accessed directly (arr[0]) → full VALUES needed, OFFSET suppressed
+    explain {
+        sql "select cardinality(map_arr_col['a']), map_arr_col['b'][0] from slcp_str_tbl"
+        notContains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // ─── Non-optimizable cases ──────────────────────────────────────────────────
+
+    // str_col also projected directly → full chars data needed, OFFSET path suppressed.
+    // No nested-columns entry for str_col, slot type stays varchar.
+    explain {
+        sql "select length(str_col), str_col from slcp_str_tbl"
+        notContains "nested columns"
+        notContains "type=bigint"
+        notContains "CAST(str_col"
+    }
+
+    // str_col also used in substr() → full chars data needed
+    explain {
+        sql "select length(str_col), substr(str_col, 2) from slcp_str_tbl"
+        notContains "nested columns"
+        notContains "type=bigint"
+        notContains "CAST(str_col"
+    }
+
+    // ─── StringEmptyToLength rule cases ─────────────────────────────────────────
+
+    // str_col <> '' rewrites to length(str_col) != 0 → OFFSET optimization applies
+    explain {
+        sql "select length(str_col) from slcp_str_tbl where str_col <> ''"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // str_col = '' also rewrites to length(str_col) = 0 → OFFSET applies
+    explain {
+        sql "select length(str_col) from slcp_str_tbl where str_col = ''"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // aggregate + predicate rewrite: sum(length(str_col)) where str_col <> ''
+    explain {
+        sql "select sum(length(str_col)) from slcp_str_tbl where str_col <> ''"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // str_col is also projected directly alongside the predicate → OFFSET suppressed
+    // (str_col <> '' rewrites to length(str_col) != 0, but str_col is also projected as-is)
+    explain {
+        sql "select str_col, length(str_col) from slcp_str_tbl where str_col <> ''"
+        notContains "nested columns"
+        notContains "type=bigint"
+        notContains "CAST(str_col"
+    }
+
+    // reversed operand: '' <> str_col → same rewrite
+    explain {
+        sql "select length(str_col) from slcp_str_tbl where '' <> str_col"
+        contains "nested columns"
+        contains "OFFSET"
+        notContains "type=bigint"
+    }
+
+    // Struct field also projected directly → field access is full, not OFFSET-only
+    // The struct's nested-columns entry still appears (partial struct pruning),
+    // but the pruned field type must remain text (not bigint).
+    explain {
+        sql "select length(struct_element(struct_col, 'f3')), struct_element(struct_col, 'f3') from slcp_str_tbl"
+        contains "nested columns"
+        notContains "bigint"
+    }
+
+    // length(map_col['a']): keys read fully for element lookup, values accessed offset-only.
+    // Expect access paths: map_col.KEYS (full) + map_col.VALUES.OFFSET
+    explain {
+        sql "select length(map_col['a']) from slcp_str_tbl"
+        contains "nested columns"
+        contains "KEYS"
+        contains "VALUES"
+        contains "OFFSET"
+        notContains "bigint"
+    }
+
+    // sum(length(map_col['a'])): same optimization in aggregate context
+    explain {
+        sql "select sum(length(map_col['a'])) from slcp_str_tbl"
+        contains "nested columns"
+        contains "KEYS"
+        contains "VALUES"
+        contains "OFFSET"
+        notContains "bigint"
+    }
+
+    // length(map_col['a']) + direct map access → OFFSET suppressed, full VALUES needed
+    explain {
+        sql "select length(map_col['a']), map_col['b'] from slcp_str_tbl"
+        notContains "OFFSET"
+        notContains "bigint"
+    }
+}
diff --git a/regression-test/suites/variant_p0/predefine/predefined_typed_to_sparse.groovy b/regression-test/suites/variant_p0/predefine/predefined_typed_to_sparse.groovy
index 21efbd9584c..9e64ab753d8 100644
--- a/regression-test/suites/variant_p0/predefine/predefined_typed_to_sparse.groovy
+++ b/regression-test/suites/variant_p0/predefine/predefined_typed_to_sparse.groovy
@@ -14,7 +14,7 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-suite("test_predefine_typed_to_sparse", "p0"){ 
+suite("predefined_typed_to_sparse", "p0"){ 
     sql """ set enable_common_expr_pushdown = true """
     sql """ set default_variant_enable_doc_mode = false """
     sql """ set enable_variant_schema_auto_cast = false """


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org