Skip to content

Commit cbe710d

Browse files
authored
perf: pin polyglot with faster column qualification (#923)
* perf(compile): bump polyglot for linear column qualification and commented set operations Bump polyglot-sql to a revision that borrows source column sets during schema-aware column qualification, so wide relations and SELECT * over derived tables qualify in linear time, and that builds scopes for set-operation chains with comments before the operators in linear time. Analysis results are unchanged. Extend the long UNION ALL fixture guard with an input fixture whose rows are separated by a comment before each UNION ALL; 200-row commented fixtures previously took about 17 times as long as 50-row fixtures. * build: pin polyglot to the merged column-set and comment-scope changes
1 parent 9311dda commit cbe710d

5 files changed

Lines changed: 40 additions & 14 deletions

File tree

‎Cargo.lock‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ globset = "0.4"
1717
mimalloc = { version = "0.1", default-features = false, features = ["local_dynamic_tls"] }
1818
proc-macro2 = { version = "1", features = ["span-locations"] }
1919
pyo3 = { version = "0.26", features = ["abi3-py312"] }
20-
polyglot-sql = { git = "https://github.com/chio-labs/polyglot.git", rev = "a7413439c520d7949924149b7ea02fa3817463fc", default-features = false, features = [
20+
polyglot-sql = { git = "https://github.com/chio-labs/polyglot.git", rev = "9ff0af282829d92efeeb36b6a820be2271e1da49", default-features = false, features = [
2121
"ast-tools",
2222
"builder",
2323
"dialect-bigquery",
@@ -29,7 +29,7 @@ polyglot-sql = { git = "https://github.com/chio-labs/polyglot.git", rev = "a7413
2929
"semantic",
3030
"stacker",
3131
] }
32-
polyglot-sql-function-catalogs = { git = "https://github.com/chio-labs/polyglot.git", rev = "a7413439c520d7949924149b7ea02fa3817463fc", default-features = false, features = [
32+
polyglot-sql-function-catalogs = { git = "https://github.com/chio-labs/polyglot.git", rev = "9ff0af282829d92efeeb36b6a820be2271e1da49", default-features = false, features = [
3333
"dialect-duckdb",
3434
] }
3535
quote = "1"

‎tests/e2e/src/sqlbuild/cli/commands/main/compile/_test_types.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ class UnionFixtureCompileScalingTestCase:
496496
expected_sql_tests: int
497497
expected_errors: int
498498
expected_max_scaling_ratio: float
499+
input_fixture_row_separator: str = " UNION ALL\n"
499500

500501

501502
@dataclass(frozen=True)

‎tests/e2e/src/sqlbuild/cli/commands/main/compile/helpers.py‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,17 +2771,25 @@ class UnionFixtureCompileMeasurement(NamedTuple):
27712771
errors: int
27722772

27732773

2774-
def _union_all_fixture_rows(*, row_count: int, status: str) -> str:
2775-
return " UNION ALL\n".join(
2774+
def _union_all_fixture_rows(*, row_count: int, status: str, separator: str) -> str:
2775+
return separator.join(
27762776
f" SELECT {row} AS order_id, CAST({row} AS DOUBLE) AS amount, '{status}' AS status"
27772777
for row in range(row_count)
27782778
)
27792779

27802780

27812781
def write_union_fixture_test_project(
2782-
*, project_dir: Path, sql_test_count: int, fixture_row_count: int
2782+
*,
2783+
project_dir: Path,
2784+
sql_test_count: int,
2785+
fixture_row_count: int,
2786+
input_fixture_row_separator: str,
27832787
) -> None:
2784-
"""Write a DuckDB project whose SQL tests use long UNION ALL fixture chains."""
2788+
"""Write a DuckDB project whose SQL tests use long UNION ALL fixture chains.
2789+
2790+
`input_fixture_row_separator` joins the rows of the mocked input fixture; the
2791+
expected fixture always uses plain `UNION ALL`.
2792+
"""
27852793

27862794
files: dict[str, str] = {
27872795
"sqlbuild_project.toml": (
@@ -2798,13 +2806,17 @@ def write_union_fixture_test_project(
27982806
),
27992807
}
28002808
for index in range(sql_test_count):
2801-
fixture_rows: str = _union_all_fixture_rows(
2802-
row_count=fixture_row_count, status=f"status_{index:02d}"
2809+
status: str = f"status_{index:02d}"
2810+
input_rows: str = _union_all_fixture_rows(
2811+
row_count=fixture_row_count, status=status, separator=input_fixture_row_separator
2812+
)
2813+
expected_rows: str = _union_all_fixture_rows(
2814+
row_count=fixture_row_count, status=status, separator=" UNION ALL\n"
28032815
)
28042816
files[f"tests/unit/orders_case_{index:02d}.sql"] = (
28052817
f'TEST (name "orders_case_{index:02d}");\n\n'
2806-
f"WITH\n__ref__base_orders AS (\n{fixture_rows}\n),\n"
2807-
f"__expected__orders AS (\n{fixture_rows}\n)\nSELECT 1\n"
2818+
f"WITH\n__ref__base_orders AS (\n{input_rows}\n),\n"
2819+
f"__expected__orders AS (\n{expected_rows}\n)\nSELECT 1\n"
28082820
)
28092821
prepare_inline_project(
28102822
tmp_path=project_dir.parent, project_name=project_dir.name, repo_files=files

‎tests/e2e/src/sqlbuild/cli/commands/main/compile/test_compile_performance.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,18 @@ def test_given_wide_scan_heavy_projects_when_doubling_sql_size_then_compile_scal
140140
expected_sql_tests=4,
141141
expected_errors=0,
142142
expected_max_scaling_ratio=6.0,
143-
)
143+
),
144+
UnionFixtureCompileScalingTestCase(
145+
description="quadrupling commented UNION ALL input fixture rows keeps SQL test analysis linear",
146+
sql_test_count=4,
147+
small_fixture_rows=50,
148+
large_fixture_rows=200,
149+
measured_runs=3,
150+
expected_sql_tests=4,
151+
expected_errors=0,
152+
expected_max_scaling_ratio=6.0,
153+
input_fixture_row_separator="\n -- fixture row\n UNION ALL\n",
154+
),
144155
],
145156
ids=lambda case: case.description,
146157
)
@@ -154,11 +165,13 @@ def test_given_sql_tests_with_union_all_fixtures_when_quadrupling_rows_then_anal
154165
project_dir=small_project_dir,
155166
sql_test_count=test_case.sql_test_count,
156167
fixture_row_count=test_case.small_fixture_rows,
168+
input_fixture_row_separator=test_case.input_fixture_row_separator,
157169
)
158170
write_union_fixture_test_project(
159171
project_dir=large_project_dir,
160172
sql_test_count=test_case.sql_test_count,
161173
fixture_row_count=test_case.large_fixture_rows,
174+
input_fixture_row_separator=test_case.input_fixture_row_separator,
162175
)
163176
small: UnionFixtureCompileMeasurement = measure_union_fixture_compile(
164177
project_dir=small_project_dir, runs=test_case.measured_runs

0 commit comments

Comments
 (0)