Skip to content

Move large Statement arms out of SqlToRel::sql_statement_to_plan_with_context_impl #26301

Open

Description

@andygrove

Is your feature request related to a problem or challenge?

SqlToRel::sql_statement_to_plan_with_context_impl (sql/src/statement.rs#L267-L1649) is a 1,307-line match over ast::Statement, with cognitive complexity 357 and cyclomatic complexity 217. statement.rs has had 39 commits in the last 12 months.

Many arms are already thin dispatchers (explain_to_plan, set_statement_to_plan, describe_table_to_plan, ...), but about a dozen inline large bodies:

  • CreateTable (about L312-L652, ~340 lines), mostly destructuring ~70 sqlparser fields followed by a long run of if x { return not_impl_err!(..) }.
  • CreateView, Drop, Prepare/Execute, ShowTables/ShowColumns, Insert, StartTransaction (L1268-L1344), CreateFunction (L1372-L1524) and Truncate.

Every sqlparser upgrade that adds a field to CreateTable has to touch this destructuring pattern, which makes the function a recurring merge-conflict and review burden.

Describe the solution you'd like

  • Make the match a pure dispatcher where each large arm calls a method on SqlToRel, following the existing describe_table_to_plan pattern: create_table_to_plan, create_view_to_plan, drop_to_plan, prepare_to_plan, execute_to_plan, show_tables_to_plan, start_transaction_to_plan, create_function_to_plan, truncate_to_plan, ...
  • For CreateTable, bind the struct by name (Statement::CreateTable(create_table)) and move the unsupported-option checks into a helper such as reject_unsupported_create_table_options(&create_table), so new sqlparser fields don't require editing the match pattern.
  • Optionally split statement.rs into submodules by statement family (DDL, DML, utility).

Describe alternatives you've considered

Leave it as is.

Additional context

Line references are pinned to commit 0d79252.

Activity

  1. added
    enhancementNew feature or request
    help wantedExtra attention is needed
    sqlSQL Planner
    tech debtCode complexity, duplication or structure that makes the codebase harder to change
    on Oct 14, 2026
  2. Theodus commented on Oct 15, 2026

    @Theodus
    Contributor

    take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is neededsqlSQL Plannertech debtCode complexity, duplication or structure that makes the codebase harder to change

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions