This is an automated email from the ASF dual-hosted git repository.
morrySnow 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 7216a090d8d [fix](topn) Resolve topn lazy materialization column
indexes for aliases (#65759)
7216a090d8d is described below
commit 7216a090d8d9ab93e4127a2ffd960c0029ba3c55
Author: daidai <[email protected]>
AuthorDate: Tue Jul 21 14:26:03 2026 +0800
[fix](topn) Resolve topn lazy materialization column indexes for aliases
(#65759)
### What problem does this PR solve?
Related pr #52114
Problem Summary:
Problem Summary: TopN lazy materialization resolved deferred column
indexes with output slot names. Queries that renamed Hive columns
therefore produced -1 indexes, and external row-id fetch could fill
those columns with NULL when positional reading was used. Resolve the
index from the already traced original base column so the descriptor and
index share one column identity. Add a focused planner unit test and a
Hive ORC Explain regression for the alias path.
Fix incorrect NULL values from aliased external-table columns when TopN
lazy materialization is used.
---
.../plans/physical/PhysicalLazyMaterialize.java | 2 +-
.../postprocess/TopnLazyMaterializeTest.java | 25 ++++++++++++++++++++++
.../hive/test_hive_topn_lazy_mat.groovy | 9 ++++++++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalLazyMaterialize.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalLazyMaterialize.java
index e3be64e577c..2eb9bc0a07d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalLazyMaterialize.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalLazyMaterialize.java
@@ -180,7 +180,7 @@ public class PhysicalLazyMaterialize<CHILD_TYPE extends
Plan> extends PhysicalUn
}
outputBuilder.add(outputSlot);
lazyColumnForRel.add(originalColumn);
-
lazyBaseColumnIdxForRel.add(relationTable.getBaseColumnIdxByName(lazySlot.getName()));
+
lazyBaseColumnIdxForRel.add(relationTable.getBaseColumnIdxByName(originalColumn.getName()));
lazySlotLocationForRel.add(loc);
loc++;
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopnLazyMaterializeTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopnLazyMaterializeTest.java
index cb5045ad76d..ee0942c3071 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopnLazyMaterializeTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopnLazyMaterializeTest.java
@@ -24,6 +24,8 @@ import org.apache.doris.nereids.datasets.ssb.SSBTestBase;
import org.apache.doris.nereids.glue.translator.PhysicalPlanTranslator;
import org.apache.doris.nereids.glue.translator.PlanTranslatorContext;
import org.apache.doris.nereids.processor.post.PlanPostProcessors;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalLazyMaterialize;
import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan;
import org.apache.doris.nereids.util.PlanChecker;
import org.apache.doris.planner.MaterializationNode;
@@ -117,6 +119,29 @@ public class TopnLazyMaterializeTest extends SSBTestBase {
ColumnAccessPath.data(ImmutableList.of("user_profile",
"professional", "skills"))));
}
+ @Test
+ public void testLazyBaseColumnIndexUsesOriginalColumnNameForAlias() throws
Exception {
+ this.createTable("create table lazy_materialize_alias_tbl("
+ + "sort_col int, lazy_col int) "
+ + "duplicate key(sort_col) distributed by hash(sort_col)
buckets 1 "
+ + "properties('replication_num' = '1')");
+ String sql = "select lazy_col as lazy_alias from
lazy_materialize_alias_tbl "
+ + "order by sort_col limit 1";
+
+ PlanChecker checker = PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .implement();
+ PhysicalPlan plan = checker.getPhysicalPlan();
+ plan = new
PlanPostProcessors(checker.getCascadesContext()).process(plan);
+
+ List<PhysicalLazyMaterialize<? extends Plan>> materializeNodes =
plan.collectToList(
+ node -> node instanceof PhysicalLazyMaterialize);
+ Assertions.assertEquals(1, materializeNodes.size(), plan.treeString());
+ Assertions.assertEquals(ImmutableList.of(ImmutableList.of(1)),
+ materializeNodes.get(0).getLazyBaseColumnIndices());
+ }
+
@Test
public void testLightSchemaChangeFalse() throws Exception {
this.createTable("create table tm_lsc_false (k int, v int) duplicate
key(k) "
diff --git
a/regression-test/suites/external_table_p0/hive/test_hive_topn_lazy_mat.groovy
b/regression-test/suites/external_table_p0/hive/test_hive_topn_lazy_mat.groovy
index ce0890fbccc..2ef76dc8bd0 100644
---
a/regression-test/suites/external_table_p0/hive/test_hive_topn_lazy_mat.groovy
+++
b/regression-test/suites/external_table_p0/hive/test_hive_topn_lazy_mat.groovy
@@ -223,6 +223,15 @@ suite("test_hive_topn_lazy_mat", "p0,external") {
contains("row_ids:
[__DORIS_GLOBAL_ROWID_COL__orc_topn_lazy_mat_table]")
}
+ // Output aliases must not be used to resolve physical Hive column
indices.
+ explain {
+ sql "select name as lazy_alias from orc_topn_lazy_mat_table order
by id limit 10;"
+ contains("VMaterializeNode")
+ contains("column_descs_lists[[`name` text NULL]]")
+ contains("column_idxs_lists: [[1]]")
+ contains("row_ids:
[__DORIS_GLOBAL_ROWID_COL__orc_topn_lazy_mat_table]")
+ }
+
explain {
sql """ select a.name,length(a.name),a.value,b.*,a.* from
parquet_topn_lazy_mat_table as a
join orc_topn_lazy_mat_table as b on a.id = b.id order by a.name
limit 10 """
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]