Skip to content

Commit 0831f60

Browse files
committed
Split physical_eq from base_eq
1 parent b58d6d2 commit 0831f60

File tree

9 files changed

+30
-19
lines changed

9 files changed

+30
-19
lines changed

src/expr/src/relation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ impl MirRelationExpr {
17071707
.column_types
17081708
.iter()
17091709
.zip_eq(typ.column_types.iter())
1710-
.all(|(t1, t2)| t1.scalar_type.base_eq(&t2.scalar_type)));
1710+
.all(|(t1, t2)| t1.scalar_type.physical_eq(&t2.scalar_type)));
17111711
}
17121712
let mut typ = typ.unwrap_or_else(|| self.typ());
17131713
typ.keys = vec![vec![]];

src/expr/src/scalar/func.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use mz_ore::fmt::FormatBuffer;
3333
use mz_ore::lex::LexBuf;
3434
use mz_ore::option::OptionExt;
3535
use mz_ore::result::ResultExt;
36-
use mz_ore::{soft_assert_eq_or_log, soft_assert_or_log};
3736
use mz_ore::str::StrExt;
37+
use mz_ore::{soft_assert_eq_or_log, soft_assert_or_log};
3838
use mz_pgrepr::Type;
3939
use mz_pgtz::timezone::{Timezone, TimezoneSpec};
4040
use mz_proto::chrono::any_naive_datetime;
@@ -8034,7 +8034,9 @@ impl VariadicFunc {
80348034
.nullable(true),
80358035
ArrayCreate { elem_type } => {
80368036
soft_assert_or_log!(
8037-
input_types.iter().all(|t| t.scalar_type.base_eq(elem_type)),
8037+
input_types
8038+
.iter()
8039+
.all(|t| t.scalar_type.physical_eq(elem_type)),
80388040
"Args to ArrayCreate should have types that are compatible with the elem_type"
80398041
);
80408042
match elem_type {

src/repr/src/relation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl ColumnType {
6969
nullable: self.nullable || other.nullable,
7070
})
7171
}
72-
(scalar_type, other_scalar_type) if scalar_type.base_eq(&other_scalar_type) => {
72+
(scalar_type, other_scalar_type) if scalar_type.physical_eq(&other_scalar_type) => {
7373
Ok(ColumnType {
7474
scalar_type: scalar_type.without_modifiers(),
7575
nullable: self.nullable || other.nullable,

src/repr/src/scalar.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,12 +2908,25 @@ impl ScalarType {
29082908
self.eq_inner(other, false)
29092909
}
29102910

2911-
// Determines equality among scalar types that ignores any custom OIDs or
2912-
// embedded values.
2911+
/// Determines equality among scalar types that ignores any custom OIDs or
2912+
/// embedded values.
29132913
pub fn structural_eq(&self, other: &ScalarType) -> bool {
29142914
self.eq_inner(other, true)
29152915
}
29162916

2917+
/// //////////// todo: comment
2918+
pub fn physical_eq(&self, other: &ScalarType) -> bool {
2919+
use ScalarType::*;
2920+
if self.base_eq(other) {
2921+
return true;
2922+
}
2923+
match (self, other) {
2924+
(String, VarChar { max_length: None }) => true,
2925+
(VarChar { max_length: None }, String) => true,
2926+
_ => false,
2927+
}
2928+
}
2929+
29172930
pub fn eq_inner(&self, other: &ScalarType, structure_only: bool) -> bool {
29182931
use ScalarType::*;
29192932
match (self, other) {
@@ -2961,9 +2974,6 @@ impl ScalarType {
29612974
&& a.1.scalar_type.eq_inner(&b.1.scalar_type, structure_only)
29622975
})
29632976
}
2964-
//////////////// todo: comment
2965-
(String, VarChar { max_length: None }) => true,
2966-
(VarChar { max_length: None }, String) => true,
29672977
(s, o) => ScalarBaseType::from(s) == ScalarBaseType::from(o),
29682978
}
29692979
}

src/transform/src/column_knowledge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl DatumKnowledge {
635635
unreachable!();
636636
};
637637

638-
if !s_typ.base_eq(o_typ) {
638+
if !s_typ.physical_eq(o_typ) {
639639
::tracing::error!("Undefined join of non-equal base types {s_typ:?} != {o_typ:?}");
640640
*self = Self::top();
641641
} else if s_val != o_val {
@@ -735,7 +735,7 @@ impl DatumKnowledge {
735735
unreachable!();
736736
};
737737

738-
if !s_typ.base_eq(o_typ) {
738+
if !s_typ.physical_eq(o_typ) {
739739
soft_panic_or_log!("Undefined meet of non-equal base types {s_typ:?} != {o_typ:?}");
740740
*self = Self::top(); // this really should be Nothing
741741
} else if s_val != o_val {

src/transform/src/normalize_lets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ mod support {
318318
.column_types
319319
.iter()
320320
.zip(typ.column_types.iter())
321-
.all(|(t1, t2)| t1.scalar_type.base_eq(&t2.scalar_type))
321+
.all(|(t1, t2)| t1.scalar_type.physical_eq(&t2.scalar_type))
322322
{
323323
Err(crate::TransformError::Internal(format!(
324324
"scalar types do not match: {:?} v {:?}",

src/transform/src/typecheck.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ pub fn scalar_subtype_difference(sub: &ScalarType, sup: &ScalarType) -> Vec<Colu
397397
}
398398
}
399399
(_, _) => {
400-
// TODO(mgree) confirm that we don't want to allow numeric subtyping
401-
if ScalarBaseType::from(sub) != ScalarBaseType::from(sup) {
400+
if !sub.physical_eq(sup) {
402401
diffs.push(ColumnTypeDifference::NotSubtype {
403402
sub: sub.clone(),
404403
sup: sup.clone(),

test/sqllogictest/github-5536.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ Explained Query:
4444
Filter (#0 <= #0) AND (#0 >= #0)
4545
ReadStorage materialize.public.t5
4646
ArrangeBy keys=[[]]
47-
Filter (text_to_varchar(boolean_to_text(like["0.31161855206970124"](padchar(#1)))) = char_to_text(#1))
47+
Filter (#1 = text_to_char(text_to_varchar(boolean_to_text(like["0.31161855206970124"](padchar(#1))))))
4848
ReadStorage materialize.public.t3
4949
ArrangeBy keys=[[]]
5050
ReadStorage materialize.public.t5
5151

5252
Source materialize.public.t0
5353
Source materialize.public.t3
54-
filter=((text_to_varchar(boolean_to_text(like["0.31161855206970124"](padchar(#1)))) = char_to_text(#1)))
54+
filter=((#1 = text_to_char(text_to_varchar(boolean_to_text(like["0.31161855206970124"](padchar(#1)))))))
5555
Source materialize.public.t5
5656

5757
Target cluster: quickstart

test/sqllogictest/type-promotion.slt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ query T multiline
317317
EXPLAIN RAW PLAN FOR
318318
SELECT 'a'::"char" < 'a'::varchar;
319319
----
320-
Map (("char"_to_text(text_to_"char"("a")) < text_to_varchar("a")))
320+
Map (("char"_to_text(text_to_"char"("a")) < varchar_to_text(text_to_varchar("a"))))
321321
Constant
322322
- ()
323323

@@ -343,7 +343,7 @@ query T multiline
343343
EXPLAIN RAW PLAN FOR
344344
SELECT 'a'::char < 'a'::varchar;
345345
----
346-
Map ((char_to_text(text_to_char(text_to_char("a"))) < text_to_varchar("a")))
346+
Map ((text_to_char(text_to_char("a")) < text_to_char(text_to_varchar("a"))))
347347
Constant
348348
- ()
349349

@@ -369,7 +369,7 @@ query T multiline
369369
EXPLAIN RAW PLAN FOR
370370
SELECT 'a'::varchar < 'a'::text;
371371
----
372-
Map ((text_to_varchar("a") < "a"))
372+
Map ((varchar_to_text(text_to_varchar("a")) < "a"))
373373
Constant
374374
- ()
375375

0 commit comments

Comments
 (0)