Skip to content

Commit c832db8

Browse files
z3z1matobymao
andauthored
Perf: use table name reference directly instead of select * subquery … (#3991)
Co-authored-by: Toby Mao <toby.mao@gmail.com>
1 parent 4d2e632 commit c832db8

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

sqlmesh/core/model/definition.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ def render_audit_query(
527527
deployability_index=deployability_index,
528528
**{
529529
**audit.defaults,
530-
"this_model": exp.select("*").from_(quoted_model_name).where(where).subquery(),
530+
"this_model": exp.select("*").from_(quoted_model_name).where(where).subquery()
531+
if where is not None
532+
else quoted_model_name,
531533
**kwargs,
532534
}, # type: ignore
533535
)

tests/core/test_audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def test_audit_query_normalization():
901901
)
902902
assert (
903903
rendered_audit_query.sql("snowflake")
904-
== """SELECT * FROM (SELECT * FROM "DB"."TEST_MODEL" AS "TEST_MODEL") AS "_Q_0" WHERE "A" IS NULL AND TRUE"""
904+
== """SELECT * FROM "DB"."TEST_MODEL" AS "TEST_MODEL" WHERE "A" IS NULL AND TRUE"""
905905
)
906906

907907

tests/core/test_snapshot_evaluator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,7 @@ def test_audit_wap(adapter_mock, make_snapshot):
27102710
not_null_query = call_args[0][0][0]
27112711
assert (
27122712
not_null_query.sql(dialect="spark")
2713-
== "SELECT COUNT(*) FROM (SELECT * FROM (SELECT * FROM `spark_catalog`.`test_schema`.`test_table`.`branch_wap_test_wap_id` AS `branch_wap_test_wap_id`) AS `_q_0` WHERE `a` IS NULL AND TRUE) AS audit"
2713+
== "SELECT COUNT(*) FROM (SELECT * FROM `spark_catalog`.`test_schema`.`test_table`.`branch_wap_test_wap_id` AS `branch_wap_test_wap_id` WHERE `a` IS NULL AND TRUE) AS audit"
27142714
)
27152715

27162716
custom_audit_query = call_args[1][0][0]
@@ -2752,7 +2752,7 @@ def test_audit_with_datetime_macros(adapter_mock, make_snapshot):
27522752
unique_combination_of_columns_query = call_args[0][0][0]
27532753
assert (
27542754
unique_combination_of_columns_query.sql(dialect="duckdb")
2755-
== """SELECT COUNT(*) FROM (SELECT "a" AS "a" FROM (SELECT * FROM "test_schema"."test_table" AS "test_table") AS "_q_0" WHERE '2020-01-01' <> '2020-01-01' GROUP BY "a" HAVING COUNT(*) > 1) AS audit"""
2755+
== """SELECT COUNT(*) FROM (SELECT "a" AS "a" FROM "test_schema"."test_table" AS "test_table" WHERE '2020-01-01' <> '2020-01-01' GROUP BY "a" HAVING COUNT(*) > 1) AS audit"""
27562756
)
27572757

27582758

0 commit comments

Comments
 (0)