Skip to content

internal: remove dead code from the SQL backend - #6190

Merged
max-sixty merged 2 commits into
mainfrom
internal/sql-dead-code
Aug 13, 2026
Merged

internal: remove dead code from the SQL backend#6190
max-sixty merged 2 commits into
mainfrom
internal/sql-dead-code

Conversation

@prql-bot

@prql-bot prql-bot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Three dead-code removals in prqlc/src/sql, found during the nightly rolling survey. No behavior change — each removal is either a comment, a no-op override, or a redundant wrapper.

1. Stale commented-out WITH RECURSIVE nesting in translate_cte. ~30 commented-out lines sketched an alternative that wraps a non-first recursive CTE in a nested WITH. It has drifted well past compiling: it builds sql_ast::With without with_token, sql_ast::Cte without materialized/closing_paren_token, TableFactor::Table without with_ordinality/version/partitions/json_path/sample/index_hints, and sql_ast::ObjectName(vec![ident]) from before the ObjectNamePart change — compare the live constructions a few lines above and below it. Anyone who did need this would be rewriting it against today's sqlparser rather than uncommenting it. The four lines of prose explaining why the alternative exists are the part worth keeping, so those stay, with a pointer to git history for the sketch.

2. RedshiftDialect::ident_quoting_style and RedshiftDialect::supports_distinct_on restate the trait defaults. DialectHandler::ident_quoting_style already returns ConditionallyQuoted and supports_distinct_on already returns false. The ident_quoting_style override also carried a comment about "dialect-specific keywords". That behavior is real — dialect_keywords() in sql/keywords.rs gives Redshift its own keyword set, and the ConditionallyQuoted branch of translate_ident_part consults it via keywords::is_keyword(&ident, &ctx.dialect_enum) — but it lives in keywords.rs (covered by test_sql_keywords) and doesn't depend on this override, which returns the trait default either way.

3. Some(&x).and_then(|x| map.get(x)) in translate_relation_expr is just map.get(&x).

Verification
cargo build -p prqlc                    # clean
cargo test -p prqlc --lib               # 80 passed, 1 ignored
cargo test -p prqlc --test integration  # 489 passed, 5 ignored
cargo clippy -p prqlc --all-targets     # clean
cargo fmt --check -p prqlc              # clean

No new test: all three changes are deletions of code that never executed (a comment, two overrides returning the value the trait already returns, and an identity wrapper). The existing suite — in particular the compileall snapshots, which diff every dialect's output against generic, and test_loop / the recursive-CTE snapshots — covers the paths touched. A test asserting "Redshift quotes identifiers conditionally" would pass identically before and after, so it wouldn't be a regression test for anything.

task prqlc:pull-request couldn't run here — cargo-insta isn't on the tend sandbox's PATH (that's what #6144 is for), so the plain cargo test runs above stand in. CI runs the full suite.

@prql-bot prql-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own PR, so this is a COMMENT rather than an approval.

All three removals are behavior-neutral, verified locally on the merge commit: cargo test -p prqlc --lib (80 passed, 1 ignored) and --test integration (489 passed, 5 ignored) are green, compile --target sql.redshift on select {time = amount} still emits AS "time" (Redshift-only keyword still quoted), and group customer_id (take 1) still lowers to ROW_NUMBER() rather than DISTINCT ON.

One correction to the description, which I've already amended: the claim that the deleted ident_quoting_style comment described "behavior that isn't there" was wrong. Redshift is precisely the one dialect that has a per-dialect keyword set — dialect_keywords() in prqlc/prqlc/src/sql/keywords.rs matches Dialect::Redshift => redshift_keywords(), and the ConditionallyQuoted arm of translate_ident_part in sql/gen_expr.rs consults it through keywords::is_keyword(&ident, &ctx.dialect_enum); test_sql_keywords pins the distinction with is_keyword("time", &Dialect::Redshift) vs !is_keyword("time", &Dialect::Postgres). The override is still redundant — it returns the trait default, and the keyword behavior lives in keywords.rs regardless — so the deletion stands, but the reason is redundancy, not inaccuracy. The diff is unchanged; only the description was corrected.

Comment thread prqlc/prqlc/src/sql/gen_query.rs Outdated
@max-sixty
max-sixty merged commit 1fd3197 into main Aug 13, 2026
38 checks passed
@max-sixty
max-sixty deleted the internal/sql-dead-code branch August 13, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants