sql_optimize: Optimize SQL

View source: R/analysis.R

sql_optimizeR Documentation

Optimize SQL

Description

Applies the upstream optimizer rule set (predicate pushdown, join reordering, CTE and subquery elimination, expression simplification, etc.) and returns the rewritten SQL.

Usage

sql_optimize(sql, dialect = "generic", schema = NULL)

Arguments

sql

A single character string with one or more SQL statements (separated by ⁠;⁠).

dialect

Dialect used for parsing.

schema

Optional schema specification (see as_polyglot_schema()); improves resolution of unqualified or ambiguous columns.

Value

A character vector with one optimized statement per input statement.

Examples

sql_optimize("SELECT * FROM (SELECT a FROM t) AS sub WHERE sub.a > 1")

polyglotSQL documentation built on Sept. 27, 2026, 5:06 p.m.