diff --git a/misc/python/materialize/mzcompose/__init__.py b/misc/python/materialize/mzcompose/__init__.py index 926c9f72d0122..a911be9cd955e 100644 --- a/misc/python/materialize/mzcompose/__init__.py +++ b/misc/python/materialize/mzcompose/__init__.py @@ -83,6 +83,7 @@ def get_minimal_system_parameters( "true" if version >= MzVersion.parse_mz("v0.132.0-dev") else "false" ), "enable_alter_swap": "true", + "enable_cast_elimination": "true", "enable_columnar_lgalloc": "false", "enable_columnation_lgalloc": "false", "enable_compute_correction_v2": "true", diff --git a/src/adapter/src/optimize.rs b/src/adapter/src/optimize.rs index 18b589f0fea4e..625d12d8d04d2 100644 --- a/src/adapter/src/optimize.rs +++ b/src/adapter/src/optimize.rs @@ -242,6 +242,7 @@ impl From<&OptimizerConfig> for mz_sql::plan::HirToMirConfig { enable_new_outer_join_lowering: config.features.enable_new_outer_join_lowering, enable_variadic_left_join_lowering: config.features.enable_variadic_left_join_lowering, enable_guard_subquery_tablefunc: config.features.enable_guard_subquery_tablefunc, + enable_cast_elimination: config.features.enable_cast_elimination, } } } diff --git a/src/repr/src/optimize.rs b/src/repr/src/optimize.rs index 3ad66e4482fb4..6471767cdf698 100644 --- a/src/repr/src/optimize.rs +++ b/src/repr/src/optimize.rs @@ -130,8 +130,12 @@ optimizer_feature_flags!({ enable_less_reduce_in_eqprop: bool, // See the feature flag of the same name. enable_dequadratic_eqprop_map: bool, + // See the feature flag of the same name. enable_fast_path_plan_insights: bool, + // See the feature flag of the same name. enable_repr_typecheck: bool, + // See the feature flag of the same name. + enable_cast_elimination: bool, }); /// A trait used to implement layered config construction. diff --git a/src/sql/src/plan/lowering.rs b/src/sql/src/plan/lowering.rs index 4ac8ec451674c..d97276d0658f6 100644 --- a/src/sql/src/plan/lowering.rs +++ b/src/sql/src/plan/lowering.rs @@ -139,6 +139,7 @@ pub struct Config { /// Enable outer join lowering implemented in database-issues#7561. pub enable_variadic_left_join_lowering: bool, pub enable_guard_subquery_tablefunc: bool, + pub enable_cast_elimination: bool, } impl From<&SystemVars> for Config { @@ -147,6 +148,7 @@ impl From<&SystemVars> for Config { enable_new_outer_join_lowering: vars.enable_new_outer_join_lowering(), enable_variadic_left_join_lowering: vars.enable_variadic_left_join_lowering(), enable_guard_subquery_tablefunc: vars.enable_guard_subquery_tablefunc(), + enable_cast_elimination: vars.enable_cast_elimination(), } } } @@ -969,6 +971,13 @@ impl HirScalarExpr { panic!("cannot decorrelate expression with unbound parameters") } CallUnmaterializable(func, _name) => SS::CallUnmaterializable(func), + CallUnary { + func: func::UnaryFunc::CastVarCharToString(_), + expr, + name: _, + } if context.config.enable_cast_elimination => { + expr.applied_to(id_gen, col_map, cte_map, inner, subquery_map, context)? + } CallUnary { func, expr, diff --git a/src/sql/src/plan/statement/ddl.rs b/src/sql/src/plan/statement/ddl.rs index e0c6309bc3cbf..b58f3b981d2ae 100644 --- a/src/sql/src/plan/statement/ddl.rs +++ b/src/sql/src/plan/statement/ddl.rs @@ -4914,6 +4914,7 @@ pub fn unplan_create_cluster( enable_eq_classes_withholding_errors: _, enable_fast_path_plan_insights: _, enable_repr_typecheck: _, + enable_cast_elimination: _, } = optimizer_feature_overrides; // The ones from above that don't occur below are not wired up to cluster features. let features_extracted = ClusterFeatureExtracted { diff --git a/src/sql/src/plan/statement/dml.rs b/src/sql/src/plan/statement/dml.rs index 88c72b07848d0..9fe474bd7f501 100644 --- a/src/sql/src/plan/statement/dml.rs +++ b/src/sql/src/plan/statement/dml.rs @@ -639,6 +639,7 @@ impl TryFrom for ExplainConfig { enable_eq_classes_withholding_errors: Default::default(), enable_fast_path_plan_insights: Default::default(), enable_repr_typecheck: Default::default(), + enable_cast_elimination: Default::default(), }, }) } diff --git a/src/sql/src/session/vars/definitions.rs b/src/sql/src/session/vars/definitions.rs index 84c83283e9a4c..9e7f450370169 100644 --- a/src/sql/src/session/vars/definitions.rs +++ b/src/sql/src/session/vars/definitions.rs @@ -2230,6 +2230,12 @@ feature_flags!( default: false, enable_for_item_parsing: false, }, + { + name: enable_cast_elimination, + desc: "Allow the optimizer to eliminate noop casts between values of equivalent representation types.", + default: false, + enable_for_item_parsing: false, + }, ); impl From<&super::SystemVars> for OptimizerFeatures { @@ -2254,6 +2260,7 @@ impl From<&super::SystemVars> for OptimizerFeatures { enable_eq_classes_withholding_errors: vars.enable_eq_classes_withholding_errors(), enable_fast_path_plan_insights: vars.enable_fast_path_plan_insights(), enable_repr_typecheck: vars.enable_repr_typecheck(), + enable_cast_elimination: vars.enable_cast_elimination(), } } } diff --git a/test/sqllogictest/freshmart.slt b/test/sqllogictest/freshmart.slt index 960bc53af8c54..f635cf5712232 100644 --- a/test/sqllogictest/freshmart.slt +++ b/test/sqllogictest/freshmart.slt @@ -291,7 +291,7 @@ Explained Query: Get l6 Return Project (#0{product_id}, #13, #11{last_update_time}) - Map (case when (#8) IS NULL then null else #7 end, (((((#2{base_price} * case when (#3{popularity_rank} <= 3) then 1.2 else case when ((#3{popularity_rank} <= 10) AND (#3{popularity_rank} >= 4)) then 1.1 else 0.9 end end) * coalesce((1 - (#5{promotion_discount} / 100)), 1)) * case when (#12{stock_rank} <= 3) then 1.1 else case when ((#12 <= 10) AND (#12 >= 4)) then 1.05 else 1 end end) * case when (#2{base_price} > #4{avg_price}) then (1 + ((#2{base_price} - #4{avg_price}) / #4{avg_price})) else (1 - ((#4{avg_price} - #2{base_price}) / #4{avg_price})) end) * case when ilike["%cheap%"](varchar_to_text(#1{product_name})) then 0.8 else 1 end)) + Map (case when (#8) IS NULL then null else #7 end, (((((#2{base_price} * case when (#3{popularity_rank} <= 3) then 1.2 else case when ((#3{popularity_rank} <= 10) AND (#3{popularity_rank} >= 4)) then 1.1 else 0.9 end end) * coalesce((1 - (#5{promotion_discount} / 100)), 1)) * case when (#12{stock_rank} <= 3) then 1.1 else case when ((#12 <= 10) AND (#12 >= 4)) then 1.05 else 1 end end) * case when (#2{base_price} > #4{avg_price}) then (1 + ((#2{base_price} - #4{avg_price}) / #4{avg_price})) else (1 - ((#4{avg_price} - #2{base_price}) / #4{avg_price})) end) * case when ilike["%cheap%"](#1{product_name}) then 0.8 else 1 end)) Join on=(#0{product_id} = #6{product_id} = #9{product_id} = #10{product_id}) type=delta ArrangeBy keys=[[#0{product_id}]] Get l6 diff --git a/test/sqllogictest/ldbc_bi.slt b/test/sqllogictest/ldbc_bi.slt index 6fdc8a0e0fdb2..173f08364289a 100644 --- a/test/sqllogictest/ldbc_bi.slt +++ b/test/sqllogictest/ldbc_bi.slt @@ -2018,7 +2018,7 @@ Explained Query: ArrangeBy keys=[[#0{rootpostlanguage}]] // { arity: 1 } Distinct project=[#0{rootpostlanguage}] // { arity: 1 } Project (#0{rootpostlanguage}) // { arity: 1 } - Filter (#0{rootpostlanguage} = varchar_to_text(#1{right_col0_0})) // { arity: 2 } + Filter (#0{rootpostlanguage} = #1{right_col0_0}) // { arity: 2 } FlatMap unnest_array({"es", "ta", "pt"}) // { arity: 2 } Distinct project=[#0{rootpostlanguage}] // { arity: 1 } Project (#13{rootpostlanguage}) // { arity: 1 } diff --git a/test/sqllogictest/ldbc_bi_eager.slt b/test/sqllogictest/ldbc_bi_eager.slt index 2afb95d8a1e4f..62af4458ceefc 100644 --- a/test/sqllogictest/ldbc_bi_eager.slt +++ b/test/sqllogictest/ldbc_bi_eager.slt @@ -2025,7 +2025,7 @@ Explained Query: ArrangeBy keys=[[#0{rootpostlanguage}]] // { arity: 1 } Distinct project=[#0{rootpostlanguage}] // { arity: 1 } Project (#0{rootpostlanguage}) // { arity: 1 } - Filter (#0{rootpostlanguage} = varchar_to_text(#1{right_col0_0})) // { arity: 2 } + Filter (#0{rootpostlanguage} = #1{right_col0_0}) // { arity: 2 } FlatMap unnest_array({"es", "ta", "pt"}) // { arity: 2 } Distinct project=[#0{rootpostlanguage}] // { arity: 1 } Project (#13{rootpostlanguage}) // { arity: 1 } diff --git a/test/sqllogictest/tpch_create_index.slt b/test/sqllogictest/tpch_create_index.slt index 9f1125e06b891..ef327ba31281b 100644 --- a/test/sqllogictest/tpch_create_index.slt +++ b/test/sqllogictest/tpch_create_index.slt @@ -282,7 +282,7 @@ materialize.public.q02: ReadIndex on=region pk_region_regionkey=[delta join lookup] // { arity: 3 } cte l4 = Project (#0{p_partkey}, #2{p_mfgr}, #10{s_name}, #11{s_address}, #13{s_phone}..=#15{s_comment}, #19{ps_supplycost}, #22{n_name}) // { arity: 9 } - Filter (#5{p_size} = 15) AND (#26{r_name} = "EUROPE") AND like["%BRASS"](varchar_to_text(#4{p_type})) // { arity: 28 } + Filter like["%BRASS"](#4{p_type}) AND (#5{p_size} = 15) AND (#26{r_name} = "EUROPE") // { arity: 28 } Join on=(#0{p_partkey} = #16{ps_partkey} AND #9{s_suppkey} = #17{ps_suppkey} AND #12{s_nationkey} = #21{n_nationkey} AND #23{n_regionkey} = #25{r_regionkey}) type=delta // { arity: 28 } implementation %0:part » %2:l1[#0{ps_partkey}]KA » %1:l0[#0{s_suppkey}]KA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef @@ -746,7 +746,7 @@ materialize.public.q08: Map ((#1{sum} / #2{sum})) // { arity: 4 } Reduce group_by=[extract_year_d(#2{o_orderdate})] aggregates=[sum(case when (#3{n_name} = "BRAZIL") then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 3 } Project (#21{l_extendedprice}, #22{l_discount}, #36{o_orderdate}, #54{n_name}) // { arity: 4 } - Filter (#58{r_name} = "AMERICA") AND (#36{o_orderdate} <= 1996-12-31) AND (#36{o_orderdate} >= 1995-01-01) AND ("ECONOMY ANODIZED STEEL" = varchar_to_text(#4{p_type})) // { arity: 60 } + Filter (#4{p_type} = "ECONOMY ANODIZED STEEL") AND (#58{r_name} = "AMERICA") AND (#36{o_orderdate} <= 1996-12-31) AND (#36{o_orderdate} >= 1995-01-01) // { arity: 60 } Join on=(#0{p_partkey} = #17{l_partkey} AND #9{s_suppkey} = #18{l_suppkey} AND #12{s_nationkey} = #53{n_nationkey} AND #16{l_orderkey} = #32{o_orderkey} AND #33{o_custkey} = #41{c_custkey} AND #44{c_nationkey} = #49{n_nationkey} AND #51{n_regionkey} = #57{r_regionkey}) type=delta // { arity: 60 } implementation %0:part » %2:lineitem[#1{l_partkey}]KA » %3:orders[#0{o_orderkey}]KAiif » %1:supplier[#0{s_suppkey}]KA » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA @@ -843,7 +843,7 @@ materialize.public.q09_primary_idx: materialize.public.q09: Reduce group_by=[#5{n_name}, extract_year_d(#4{o_orderdate})] aggregates=[sum(((#1{l_extendedprice} * (1 - #2{l_discount})) - (#3{ps_supplycost} * #0{l_quantity})))] // { arity: 3 } Project (#20{l_quantity}..=#22{l_discount}, #35{ps_supplycost}, #41{o_orderdate}, #47{n_name}) // { arity: 6 } - Filter like["%green%"](varchar_to_text(#1{p_name})) // { arity: 50 } + Filter like["%green%"](#1{p_name}) // { arity: 50 } Join on=(#0{p_partkey} = #17{l_partkey} = #32{ps_partkey} AND #9{s_suppkey} = #18{l_suppkey} = #33{ps_suppkey} AND #12{s_nationkey} = #46{n_nationkey} AND #16{l_orderkey} = #37{o_orderkey}) type=delta // { arity: 50 } implementation %0:part » %2:lineitem[#1{l_partkey}]KA » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %1:supplier[#0{s_suppkey}]KA » %4:orders[#0{o_orderkey}]KA » %5:nation[#0{n_nationkey}]KA @@ -1147,7 +1147,7 @@ materialize.public.q13: ReadIndex on=customer pk_customer_custkey=[differential join] // { arity: 8 } cte l1 = Project (#0{c_custkey}, #8{o_orderkey}) // { arity: 2 } - Filter NOT(like["%special%requests%"](varchar_to_text(#16{o_comment}))) // { arity: 17 } + Filter NOT(like["%special%requests%"](#16{o_comment})) // { arity: 17 } Join on=(#0{c_custkey} = #9{o_custkey}) type=differential // { arity: 17 } implementation %1:orders[#1{o_custkey}]KAf » %0:l0[#0{c_custkey}]KAf @@ -1214,7 +1214,7 @@ materialize.public.q14_primary_idx: materialize.public.q14: With cte l0 = - Reduce aggregates=[sum(case when like["PROMO%"](varchar_to_text(#2{p_type})) then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 } + Reduce aggregates=[sum(case when like["PROMO%"](#2{p_type}) then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 } Project (#5{l_extendedprice}, #6{l_discount}, #20{p_type}) // { arity: 3 } Filter (#10{l_shipdate} >= 1995-09-01) AND (date_to_timestamp(#10{l_shipdate}) < 1995-10-01 00:00:00) // { arity: 25 } Join on=(#1{l_partkey} = #16{p_partkey}) type=differential // { arity: 25 } @@ -1372,7 +1372,7 @@ materialize.public.q16: With cte l0 = Project (#1{ps_suppkey}, #8{p_brand}..=#10{p_size}) // { arity: 4 } - Filter (#8{p_brand} != "Brand#45") AND NOT(like["MEDIUM POLISHED%"](varchar_to_text(#9{p_type}))) AND ((#10{p_size} = 3) OR (#10{p_size} = 9) OR (#10{p_size} = 14) OR (#10{p_size} = 19) OR (#10{p_size} = 23) OR (#10{p_size} = 36) OR (#10{p_size} = 45) OR (#10{p_size} = 49)) // { arity: 14 } + Filter (#8{p_brand} != "Brand#45") AND NOT(like["MEDIUM POLISHED%"](#9{p_type})) AND ((#10{p_size} = 3) OR (#10{p_size} = 9) OR (#10{p_size} = 14) OR (#10{p_size} = 19) OR (#10{p_size} = 23) OR (#10{p_size} = 36) OR (#10{p_size} = 45) OR (#10{p_size} = 49)) // { arity: 14 } Join on=(#0{ps_partkey} = #5{p_partkey}) type=differential // { arity: 14 } implementation %1:part[#0{p_partkey}]KAef » %0:partsupp[#0{ps_partkey}]KAef @@ -1405,7 +1405,7 @@ materialize.public.q16: Get l1 // { arity: 1 } ArrangeBy keys=[[]] // { arity: 1 } Project (#0{s_suppkey}) // { arity: 1 } - Filter like["%Customer%Complaints%"](varchar_to_text(#6{s_comment})) // { arity: 7 } + Filter like["%Customer%Complaints%"](#6{s_comment}) // { arity: 7 } ReadIndex on=supplier pk_supplier_suppkey=[*** full scan ***] // { arity: 7 } Get l1 // { arity: 1 } @@ -1764,7 +1764,7 @@ materialize.public.q20: ArrangeBy keys=[[#0{p_partkey}]] // { arity: 1 } Distinct project=[#0{p_partkey}] // { arity: 1 } Project (#0{p_partkey}) // { arity: 1 } - Filter (#0{p_partkey}) IS NOT NULL AND like["forest%"](varchar_to_text(#1{p_name})) // { arity: 9 } + Filter like["forest%"](#1{p_name}) AND (#0{p_partkey}) IS NOT NULL // { arity: 9 } ReadIndex on=part pk_part_partkey=[*** full scan ***] // { arity: 9 } Return // { arity: 2 } Project (#1{s_name}, #2{s_address}) // { arity: 2 } diff --git a/test/sqllogictest/tpch_create_materialized_view.slt b/test/sqllogictest/tpch_create_materialized_view.slt index c757b7af4c2db..c20698e1cd679 100644 --- a/test/sqllogictest/tpch_create_materialized_view.slt +++ b/test/sqllogictest/tpch_create_materialized_view.slt @@ -261,7 +261,7 @@ materialize.public.q02: ReadIndex on=region pk_region_regionkey=[delta join lookup] // { arity: 3 } cte l4 = Project (#0{p_partkey}, #2{p_mfgr}, #10{s_name}, #11{s_address}, #13{s_phone}..=#15{s_comment}, #19{ps_supplycost}, #22{n_name}) // { arity: 9 } - Filter (#5{p_size} = 15) AND (#26{r_name} = "EUROPE") AND like["%BRASS"](varchar_to_text(#4{p_type})) // { arity: 28 } + Filter like["%BRASS"](#4{p_type}) AND (#5{p_size} = 15) AND (#26{r_name} = "EUROPE") // { arity: 28 } Join on=(#0{p_partkey} = #16{ps_partkey} AND #9{s_suppkey} = #17{ps_suppkey} AND #12{s_nationkey} = #21{n_nationkey} AND #23{n_regionkey} = #25{r_regionkey}) type=delta // { arity: 28 } implementation %0:part » %2:l1[#0{ps_partkey}]KA » %1:l0[#0{s_suppkey}]KA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef @@ -671,7 +671,7 @@ materialize.public.q08: Map ((#1{sum} / #2{sum})) // { arity: 4 } Reduce group_by=[extract_year_d(#2{o_orderdate})] aggregates=[sum(case when (#3{n_name} = "BRAZIL") then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 3 } Project (#21{l_extendedprice}, #22{l_discount}, #36{o_orderdate}, #54{n_name}) // { arity: 4 } - Filter (#58{r_name} = "AMERICA") AND (#36{o_orderdate} <= 1996-12-31) AND (#36{o_orderdate} >= 1995-01-01) AND ("ECONOMY ANODIZED STEEL" = varchar_to_text(#4{p_type})) // { arity: 60 } + Filter (#4{p_type} = "ECONOMY ANODIZED STEEL") AND (#58{r_name} = "AMERICA") AND (#36{o_orderdate} <= 1996-12-31) AND (#36{o_orderdate} >= 1995-01-01) // { arity: 60 } Join on=(#0{p_partkey} = #17{l_partkey} AND #9{s_suppkey} = #18{l_suppkey} AND #12{s_nationkey} = #53{n_nationkey} AND #16{l_orderkey} = #32{o_orderkey} AND #33{o_custkey} = #41{c_custkey} AND #44{c_nationkey} = #49{n_nationkey} AND #51{n_regionkey} = #57{r_regionkey}) type=delta // { arity: 60 } implementation %0:part » %2:lineitem[#1{l_partkey}]KA » %3:orders[#0{o_orderkey}]KAiif » %1:supplier[#0{s_suppkey}]KA » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA @@ -759,7 +759,7 @@ ORDER BY materialize.public.q09: Reduce group_by=[#5{n_name}, extract_year_d(#4{o_orderdate})] aggregates=[sum(((#1{l_extendedprice} * (1 - #2{l_discount})) - (#3{ps_supplycost} * #0{l_quantity})))] // { arity: 3 } Project (#20{l_quantity}..=#22{l_discount}, #35{ps_supplycost}, #41{o_orderdate}, #47{n_name}) // { arity: 6 } - Filter like["%green%"](varchar_to_text(#1{p_name})) // { arity: 50 } + Filter like["%green%"](#1{p_name}) // { arity: 50 } Join on=(#0{p_partkey} = #17{l_partkey} = #32{ps_partkey} AND #9{s_suppkey} = #18{l_suppkey} = #33{ps_suppkey} AND #12{s_nationkey} = #46{n_nationkey} AND #16{l_orderkey} = #37{o_orderkey}) type=delta // { arity: 50 } implementation %0:part » %2:lineitem[#1{l_partkey}]KA » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %1:supplier[#0{s_suppkey}]KA » %4:orders[#0{o_orderkey}]KA » %5:nation[#0{n_nationkey}]KA @@ -1027,7 +1027,7 @@ materialize.public.q13: ReadIndex on=customer pk_customer_custkey=[differential join] // { arity: 8 } cte l1 = Project (#0{c_custkey}, #8{o_orderkey}) // { arity: 2 } - Filter NOT(like["%special%requests%"](varchar_to_text(#16{o_comment}))) // { arity: 17 } + Filter NOT(like["%special%requests%"](#16{o_comment})) // { arity: 17 } Join on=(#0{c_custkey} = #9{o_custkey}) type=differential // { arity: 17 } implementation %1:orders[#1{o_custkey}]KAf » %0:l0[#0{c_custkey}]KAf @@ -1085,7 +1085,7 @@ WHERE materialize.public.q14: With cte l0 = - Reduce aggregates=[sum(case when like["PROMO%"](varchar_to_text(#2{p_type})) then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 } + Reduce aggregates=[sum(case when like["PROMO%"](#2{p_type}) then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 } Project (#5{l_extendedprice}, #6{l_discount}, #20{p_type}) // { arity: 3 } Filter (#10{l_shipdate} >= 1995-09-01) AND (date_to_timestamp(#10{l_shipdate}) < 1995-10-01 00:00:00) // { arity: 25 } Join on=(#1{l_partkey} = #16{p_partkey}) type=differential // { arity: 25 } @@ -1228,7 +1228,7 @@ materialize.public.q16: With cte l0 = Project (#1{ps_suppkey}, #8{p_brand}..=#10{p_size}) // { arity: 4 } - Filter (#8{p_brand} != "Brand#45") AND NOT(like["MEDIUM POLISHED%"](varchar_to_text(#9{p_type}))) AND ((#10{p_size} = 3) OR (#10{p_size} = 9) OR (#10{p_size} = 14) OR (#10{p_size} = 19) OR (#10{p_size} = 23) OR (#10{p_size} = 36) OR (#10{p_size} = 45) OR (#10{p_size} = 49)) // { arity: 14 } + Filter (#8{p_brand} != "Brand#45") AND NOT(like["MEDIUM POLISHED%"](#9{p_type})) AND ((#10{p_size} = 3) OR (#10{p_size} = 9) OR (#10{p_size} = 14) OR (#10{p_size} = 19) OR (#10{p_size} = 23) OR (#10{p_size} = 36) OR (#10{p_size} = 45) OR (#10{p_size} = 49)) // { arity: 14 } Join on=(#0{ps_partkey} = #5{p_partkey}) type=differential // { arity: 14 } implementation %1:part[#0{p_partkey}]KAef » %0:partsupp[#0{ps_partkey}]KAef @@ -1261,7 +1261,7 @@ materialize.public.q16: Get l1 // { arity: 1 } ArrangeBy keys=[[]] // { arity: 1 } Project (#0{s_suppkey}) // { arity: 1 } - Filter like["%Customer%Complaints%"](varchar_to_text(#6{s_comment})) // { arity: 7 } + Filter like["%Customer%Complaints%"](#6{s_comment}) // { arity: 7 } ReadIndex on=supplier pk_supplier_suppkey=[*** full scan ***] // { arity: 7 } Get l1 // { arity: 1 } @@ -1584,7 +1584,7 @@ materialize.public.q20: ArrangeBy keys=[[#0{p_partkey}]] // { arity: 1 } Distinct project=[#0{p_partkey}] // { arity: 1 } Project (#0{p_partkey}) // { arity: 1 } - Filter (#0{p_partkey}) IS NOT NULL AND like["forest%"](varchar_to_text(#1{p_name})) // { arity: 9 } + Filter like["forest%"](#1{p_name}) AND (#0{p_partkey}) IS NOT NULL // { arity: 9 } ReadIndex on=part pk_part_partkey=[*** full scan ***] // { arity: 9 } Return // { arity: 2 } Project (#1{s_name}, #2{s_address}) // { arity: 2 } diff --git a/test/sqllogictest/tpch_select.slt b/test/sqllogictest/tpch_select.slt index 41b15a34b9964..b63c5ed13f1eb 100644 --- a/test/sqllogictest/tpch_select.slt +++ b/test/sqllogictest/tpch_select.slt @@ -260,7 +260,7 @@ Explained Query: ReadIndex on=region pk_region_regionkey=[delta join lookup] // { arity: 3 } cte l4 = Project (#0{p_partkey}, #2{p_mfgr}, #10{s_name}, #11{s_address}, #13{s_phone}..=#15{s_comment}, #19{ps_supplycost}, #22{n_name}) // { arity: 9 } - Filter (#5{p_size} = 15) AND (#26{r_name} = "EUROPE") AND like["%BRASS"](varchar_to_text(#4{p_type})) // { arity: 28 } + Filter like["%BRASS"](#4{p_type}) AND (#5{p_size} = 15) AND (#26{r_name} = "EUROPE") // { arity: 28 } Join on=(#0{p_partkey} = #16{ps_partkey} AND #9{s_suppkey} = #17{ps_suppkey} AND #12{s_nationkey} = #21{n_nationkey} AND #23{n_regionkey} = #25{r_regionkey}) type=delta // { arity: 28 } implementation %0:part » %2:l1[#0{ps_partkey}]KA » %1:l0[#0{s_suppkey}]KA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef @@ -669,7 +669,7 @@ Explained Query: Map ((#1{sum} / #2{sum})) // { arity: 4 } Reduce group_by=[extract_year_d(#2{o_orderdate})] aggregates=[sum(case when (#3{n_name} = "BRAZIL") then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 3 } Project (#21{l_extendedprice}, #22{l_discount}, #36{o_orderdate}, #54{n_name}) // { arity: 4 } - Filter (#58{r_name} = "AMERICA") AND (#36{o_orderdate} <= 1996-12-31) AND (#36{o_orderdate} >= 1995-01-01) AND ("ECONOMY ANODIZED STEEL" = varchar_to_text(#4{p_type})) // { arity: 60 } + Filter (#4{p_type} = "ECONOMY ANODIZED STEEL") AND (#58{r_name} = "AMERICA") AND (#36{o_orderdate} <= 1996-12-31) AND (#36{o_orderdate} >= 1995-01-01) // { arity: 60 } Join on=(#0{p_partkey} = #17{l_partkey} AND #9{s_suppkey} = #18{l_suppkey} AND #12{s_nationkey} = #53{n_nationkey} AND #16{l_orderkey} = #32{o_orderkey} AND #33{o_custkey} = #41{c_custkey} AND #44{c_nationkey} = #49{n_nationkey} AND #51{n_regionkey} = #57{r_regionkey}) type=delta // { arity: 60 } implementation %0:part » %2:lineitem[#1{l_partkey}]KA » %3:orders[#0{o_orderkey}]KAiif » %1:supplier[#0{s_suppkey}]KA » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA @@ -757,7 +757,7 @@ Explained Query: Finish order_by=[#0{n_name} asc nulls_last, #1 desc nulls_first] output=[#0..=#2] Reduce group_by=[#5{n_name}, extract_year_d(#4{o_orderdate})] aggregates=[sum(((#1{l_extendedprice} * (1 - #2{l_discount})) - (#3{ps_supplycost} * #0{l_quantity})))] // { arity: 3 } Project (#20{l_quantity}..=#22{l_discount}, #35{ps_supplycost}, #41{o_orderdate}, #47{n_name}) // { arity: 6 } - Filter like["%green%"](varchar_to_text(#1{p_name})) // { arity: 50 } + Filter like["%green%"](#1{p_name}) // { arity: 50 } Join on=(#0{p_partkey} = #17{l_partkey} = #32{ps_partkey} AND #9{s_suppkey} = #18{l_suppkey} = #33{ps_suppkey} AND #12{s_nationkey} = #46{n_nationkey} AND #16{l_orderkey} = #37{o_orderkey}) type=delta // { arity: 50 } implementation %0:part » %2:lineitem[#1{l_partkey}]KA » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %1:supplier[#0{s_suppkey}]KA » %4:orders[#0{o_orderkey}]KA » %5:nation[#0{n_nationkey}]KA @@ -1025,7 +1025,7 @@ Explained Query: ReadIndex on=customer pk_customer_custkey=[differential join] // { arity: 8 } cte l1 = Project (#0{c_custkey}, #8{o_orderkey}) // { arity: 2 } - Filter NOT(like["%special%requests%"](varchar_to_text(#16{o_comment}))) // { arity: 17 } + Filter NOT(like["%special%requests%"](#16{o_comment})) // { arity: 17 } Join on=(#0{c_custkey} = #9{o_custkey}) type=differential // { arity: 17 } implementation %1:orders[#1{o_custkey}]KAf » %0:l0[#0{c_custkey}]KAf @@ -1082,7 +1082,7 @@ WHERE Explained Query: With cte l0 = - Reduce aggregates=[sum(case when like["PROMO%"](varchar_to_text(#2{p_type})) then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 } + Reduce aggregates=[sum(case when like["PROMO%"](#2{p_type}) then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 } Project (#5{l_extendedprice}, #6{l_discount}, #20{p_type}) // { arity: 3 } Filter (#10{l_shipdate} >= 1995-09-01) AND (date_to_timestamp(#10{l_shipdate}) < 1995-10-01 00:00:00) // { arity: 25 } Join on=(#1{l_partkey} = #16{p_partkey}) type=differential // { arity: 25 } @@ -1225,7 +1225,7 @@ Explained Query: With cte l0 = Project (#1{ps_suppkey}, #8{p_brand}..=#10{p_size}) // { arity: 4 } - Filter (#8{p_brand} != "Brand#45") AND NOT(like["MEDIUM POLISHED%"](varchar_to_text(#9{p_type}))) AND ((#10{p_size} = 3) OR (#10{p_size} = 9) OR (#10{p_size} = 14) OR (#10{p_size} = 19) OR (#10{p_size} = 23) OR (#10{p_size} = 36) OR (#10{p_size} = 45) OR (#10{p_size} = 49)) // { arity: 14 } + Filter (#8{p_brand} != "Brand#45") AND NOT(like["MEDIUM POLISHED%"](#9{p_type})) AND ((#10{p_size} = 3) OR (#10{p_size} = 9) OR (#10{p_size} = 14) OR (#10{p_size} = 19) OR (#10{p_size} = 23) OR (#10{p_size} = 36) OR (#10{p_size} = 45) OR (#10{p_size} = 49)) // { arity: 14 } Join on=(#0{ps_partkey} = #5{p_partkey}) type=differential // { arity: 14 } implementation %1:part[#0{p_partkey}]KAef » %0:partsupp[#0{ps_partkey}]KAef @@ -1258,7 +1258,7 @@ Explained Query: Get l1 // { arity: 1 } ArrangeBy keys=[[]] // { arity: 1 } Project (#0{s_suppkey}) // { arity: 1 } - Filter like["%Customer%Complaints%"](varchar_to_text(#6{s_comment})) // { arity: 7 } + Filter like["%Customer%Complaints%"](#6{s_comment}) // { arity: 7 } ReadIndex on=supplier pk_supplier_suppkey=[*** full scan ***] // { arity: 7 } Get l1 // { arity: 1 } @@ -1579,7 +1579,7 @@ Explained Query: ArrangeBy keys=[[#0{p_partkey}]] // { arity: 1 } Distinct project=[#0{p_partkey}] // { arity: 1 } Project (#0{p_partkey}) // { arity: 1 } - Filter (#0{p_partkey}) IS NOT NULL AND like["forest%"](varchar_to_text(#1{p_name})) // { arity: 9 } + Filter like["forest%"](#1{p_name}) AND (#0{p_partkey}) IS NOT NULL // { arity: 9 } ReadIndex on=part pk_part_partkey=[*** full scan ***] // { arity: 9 } Return // { arity: 2 } Project (#1{s_name}, #2{s_address}) // { arity: 2 } diff --git a/test/sqllogictest/transform/filter_index.slt b/test/sqllogictest/transform/filter_index.slt index ce253a50038b8..b59fd8c6ff78b 100644 --- a/test/sqllogictest/transform/filter_index.slt +++ b/test/sqllogictest/transform/filter_index.slt @@ -134,7 +134,7 @@ EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) ---- Explained Query (fast path): Project (#1{b}, #2{c}) - Filter ("this" = varchar_to_text(#1{b})) + Filter (#1{b} = "this") ReadIndex on=materialize.public.foo foo_idx=[lookup value=(5)] Used Indexes: