From 37bf3de9cf7babe29fa7ceb45583e71239dd537f Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Mon, 10 Aug 2026 11:07:58 +0100 Subject: [PATCH] Avoid expanding unreferenced struct plan fields Signed-off-by: Joe Isaacs --- vortex-layout/src/plan/plans/pack.rs | 23 ++++------ vortex-layout/src/plan/tests.rs | 68 ++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/vortex-layout/src/plan/plans/pack.rs b/vortex-layout/src/plan/plans/pack.rs index 939965bc3c6..f721aa26233 100644 --- a/vortex-layout/src/plan/plans/pack.rs +++ b/vortex-layout/src/plan/plans/pack.rs @@ -264,8 +264,7 @@ impl PlanParentReduceRule for ExpressionPackRule { .get(&ExactBoundExpr(expression.clone())) .vortex_expect("Bound expression missing free-field annotations") .clone(); - let expanded_root = expanded_struct_root(child.dtype(), fields)?; - let expanded = expand_struct_root(expression.clone(), &expanded_root, fields)?; + let expanded = expand_struct_root(expression.clone(), fields)?; let partitioned = partition_bound(expanded.clone(), make_bound_free_field_annotator(fields))?; @@ -381,14 +380,13 @@ fn expanded_struct_root( fn expand_struct_root( expression: BoundExpression, - expanded_root: &BoundExpression, fields: &StructFields, ) -> VortexResult { Ok(expression .transform_down(|node| { if node.is_root() { return Ok(Transformed { - value: expanded_root.clone(), + value: expanded_struct_root(node.dtype(), fields)?, changed: true, order: TraversalOrder::Skip, }); @@ -405,28 +403,23 @@ fn expand_struct_root( return Ok(Transformed::no(node)); } - if let Some(field_name) = scalar_fn.as_opt::() { - let index = fields.find(field_name).ok_or_else(|| { - vortex_err!("Field {field_name} not found while expanding struct root") - })?; + if scalar_fn.is::() { return Ok(Transformed { - value: expanded_root.children()[index].clone(), - changed: true, + value: node, + changed: false, order: TraversalOrder::Skip, }); } if let Some(selection) = scalar_fn.as_opt::