Skip to content

Commit 5d6c906

Browse files
cetra3claude
andcommitted
refactor: share the DFSchema name index only through Clone
Qualifier rewrites now start with an empty index. Their callers are outside the planning paths the index targets and rarely see a probed schema, so sharing saved nothing and widened the invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FmZ3Fcw2tCfc7VGTQ8UnVB
1 parent 9fcd011 commit 5d6c906

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎datafusion/common/src/dfschema.rs‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ pub struct DFSchema {
123123
/// Lazily built lookup from field name to positions in `inner`, only used
124124
/// for schemas with more than [`LINEAR_NAME_SCAN_MAX`] fields.
125125
///
126-
/// Derived from the field names alone, so it is shared by clones and by
127-
/// schemas that only change qualifiers, and must be reset whenever `inner`
128-
/// changes. It takes no part in equality, hashing or `Debug` output.
126+
/// Derived from the field names alone, so it is shared by clones and must
127+
/// be reset whenever `inner` changes. It takes no part in equality,
128+
/// hashing or `Debug` output.
129129
name_index: OnceLock<Arc<NameIndex>>,
130130
}
131131

@@ -248,7 +248,7 @@ impl DFSchema {
248248
inner: Arc::clone(&self.inner),
249249
field_qualifiers: qualifiers,
250250
functional_dependencies: self.functional_dependencies.clone(),
251-
name_index: self.name_index.clone(),
251+
name_index: OnceLock::new(),
252252
})
253253
}
254254

@@ -894,7 +894,7 @@ impl DFSchema {
894894
field_qualifiers: vec![None; self.inner.fields.len()],
895895
inner: self.inner,
896896
functional_dependencies: self.functional_dependencies,
897-
name_index: self.name_index,
897+
name_index: OnceLock::new(),
898898
}
899899
}
900900

@@ -905,7 +905,7 @@ impl DFSchema {
905905
field_qualifiers: vec![Some(qualifier); self.inner.fields.len()],
906906
inner: self.inner,
907907
functional_dependencies: self.functional_dependencies,
908-
name_index: self.name_index,
908+
name_index: OnceLock::new(),
909909
}
910910
}
911911

@@ -2055,13 +2055,11 @@ mod tests {
20552055
assert_eq!(schema, unprobed);
20562056
assert_eq!(format!("{schema:?}"), format!("{unprobed:?}"));
20572057

2058-
// Clones and qualifier rewrites keep the fields, so they share the index.
2058+
// Clones keep the fields, so they share the index.
20592059
assert!(Arc::ptr_eq(
20602060
schema.clone().name_index.get().unwrap(),
20612061
&index
20622062
));
2063-
let stripped = schema.clone().strip_qualifiers();
2064-
assert!(Arc::ptr_eq(stripped.name_index.get().unwrap(), &index));
20652063
let replaced = schema.clone().replace_qualifier("t");
20662064
assert_eq!(
20672065
replaced.index_of_column_by_name(Some(&TableReference::bare("t")), "a"),

0 commit comments

Comments
 (0)