Skip to content

Commit 241b669

Browse files
authored
Improve Hash and Ord speed for dyn LogicalType (#17437)
`LogicalType::signature` is logical type's unique identifier. It is the method contract and is leveraged in `Eq` impl for `dyn LogicalType`. Leverage this in `Hash` and `Ord` too.
1 parent 8698d95 commit 241b669

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

datafusion/common/src/types/logical.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl std::fmt::Display for dyn LogicalType {
106106

107107
impl PartialEq for dyn LogicalType {
108108
fn eq(&self, other: &Self) -> bool {
109+
// Logical types with identical signatures are considered equal.
109110
self.signature().eq(&other.signature())
110111
}
111112
}
@@ -120,15 +121,14 @@ impl PartialOrd for dyn LogicalType {
120121

121122
impl Ord for dyn LogicalType {
122123
fn cmp(&self, other: &Self) -> Ordering {
123-
self.signature()
124-
.cmp(&other.signature())
125-
.then(self.native().cmp(other.native()))
124+
// Logical types with identical signatures are considered equal.
125+
self.signature().cmp(&other.signature())
126126
}
127127
}
128128

129129
impl Hash for dyn LogicalType {
130130
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
131+
// Logical types with identical signatures are considered equal.
131132
self.signature().hash(state);
132-
self.native().hash(state);
133133
}
134134
}

0 commit comments

Comments
 (0)