:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): raise the trino compilation budget to 50k nodes (#119780)
Jovan Sakovic9397edb9afb4
diff --git a/posthog/hogql/printer/test/test_trino_printer.py b/posthog/hogql/printer/test/test_trino_printer.pyindex 72510540f3e2..4fe30f699d43 100644--- a/posthog/hogql/printer/test/test_trino_printer.py+++ b/posthog/hogql/printer/test/test_trino_printer.py@@ -893,9 +893,9 @@ def test_scalar_cte_chains_preserve_results(depth: int) -> None:def test_rejects_excessive_scalar_cte_expansion() -> None:- ctes = ["1 AS c0", *[f"c{i - 1} + c{i - 1} AS c{i}" for i in range(1, 15)]]+ ctes = ["1 AS c0", *[f"c{i - 1} + c{i - 1} AS c{i}" for i in range(1, 18)]]with pytest.raises(TrinoLoweringError, match="TRINO_AST_EXPANSION_LIMIT"):- prepare_and_print_ast(parse_select(f"WITH {', '.join(ctes)} SELECT c14"), _context_with_trino_table(), "trino")+ prepare_and_print_ast(parse_select(f"WITH {', '.join(ctes)} SELECT c17"), _context_with_trino_table(), "trino")@pytest.mark.parametrize("length", ["", ", -1"])@@ -916,8 +916,16 @@ def test_scalar_ctes_do_not_replace_real_columns(projection: str) -> None:assert sql.startswith('SELECT "users"."id" FROM ')+def test_accepts_large_queries_without_expansion() -> None:+ projections = ", ".join(f"id + {i} AS c{i}" for i in range(1_500))+ sql, _ = prepare_and_print_ast(+ parse_select(f"SELECT {projections} FROM users"), _context_with_trino_table(), "trino"+ )+ assert '"c1499"' in sql++def test_rejects_excessive_select_alias_expansion() -> None:- projections = ["1 AS a0", *[f"a{i - 1} + a{i - 1} AS a{i}" for i in range(1, 15)]]+ projections = ["1 AS a0", *[f"a{i - 1} + a{i - 1} AS a{i}" for i in range(1, 18)]]with pytest.raises(TrinoLoweringError, match="TRINO_AST_EXPANSION_LIMIT"):prepare_and_print_ast(parse_select(f"SELECT {', '.join(projections)}"), _context_with_trino_table(), "trino")diff --git a/posthog/hogql/transforms/trino/limits.py b/posthog/hogql/transforms/trino/limits.pyindex c3887069eba6..e344885766a3 100644--- a/posthog/hogql/transforms/trino/limits.py+++ b/posthog/hogql/transforms/trino/limits.py@@ -3,11 +3,13 @@ from posthog.hogql.transforms.trino.errors import TrinoLoweringErrorfrom posthog.hogql.visitor import TraversingVisitorMAX_TRINO_SQL_LENGTH = 1_000_000+# Saved views are inlined before lowering, so ordinary models over a few views need tens of thousands of nodes.+MAX_TRINO_AST_NODES = 50_000class TrinoCompilationBudget(TraversingVisitor):def __init__(self) -> None:- self.remaining_nodes = 10_000+ self.remaining_nodes = MAX_TRINO_AST_NODESdef consume_node(self, node: ast.AST | None) -> None:if node is None: