-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: remove hand-optimizations from queries #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,21 +42,24 @@ def query() -> pd.DataFrame: | |
supplier_ds = supplier_ds() | ||
|
||
rsel = region_ds.r_name == "ASIA" | ||
osel = (orders_ds.o_orderdate >= date1) & (orders_ds.o_orderdate < date2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filters before the join is not a direct translation from SQL. The optimizer has to determine which predicates can pass which joins. |
||
forders = orders_ds[osel] | ||
fregion = region_ds[rsel] | ||
jn1 = fregion.merge(nation_ds, left_on="r_regionkey", right_on="n_regionkey") | ||
jn1 = region_ds.merge(nation_ds, left_on="r_regionkey", right_on="n_regionkey") | ||
jn2 = jn1.merge(customer_ds, left_on="n_nationkey", right_on="c_nationkey") | ||
jn3 = jn2.merge(forders, left_on="c_custkey", right_on="o_custkey") | ||
jn3 = jn2.merge(orders_ds, left_on="c_custkey", right_on="o_custkey") | ||
jn4 = jn3.merge(line_item_ds, left_on="o_orderkey", right_on="l_orderkey") | ||
jn5 = supplier_ds.merge( | ||
jn4, | ||
left_on=["s_suppkey", "s_nationkey"], | ||
right_on=["l_suppkey", "n_nationkey"], | ||
) | ||
jn5["revenue"] = jn5.l_extendedprice * (1.0 - jn5.l_discount) | ||
jn5 = jn5[ | ||
(jn5.o_orderdate >= date1) | ||
& (jn5.o_orderdate < date2) | ||
& (jn5.r_name == rsel) | ||
] | ||
gb = jn5.groupby("n_name", as_index=False)["revenue"].sum() | ||
result_df = gb.sort_values("revenue", ascending=False) | ||
|
||
return result_df # type: ignore[no-any-return] | ||
|
||
utils.run_query(Q_NUM, query) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ def q() -> None: | |
.filter(pl.col("p_size") == var_1) | ||
.filter(pl.col("p_type").str.ends_with(var_2)) | ||
.filter(pl.col("r_name") == var_3) | ||
).cache() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The optimizer has to find common subplans. |
||
) | ||
|
||
final_cols = [ | ||
"s_acctbal", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hand written projection pushdown.