Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions misc/python/materialize/mzcompose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/adapter/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/repr/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/sql/src/plan/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/sql/src/plan/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/sql/src/plan/statement/dml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ impl TryFrom<ExplainPlanOptionExtracted> 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(),
},
})
}
Expand Down
7 changes: 7 additions & 0 deletions src/sql/src/session/vars/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
2 changes: 1 addition & 1 deletion test/sqllogictest/freshmart.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sqllogictest/ldbc_bi.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion test/sqllogictest/ldbc_bi_eager.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
16 changes: 8 additions & 8 deletions test/sqllogictest/tpch_create_index.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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 }
Expand Down
Loading