How a Database Optimizer Proves It Can Rewrite Your LEFT JOIN into an Inner Join
A database that silently rewrites join semantics can introduce subtle data bugs during a platform migration. KES's conservative, provably correct approach to outer join elimination means teams can trust that migrated SQL will not produce different results just because the optimizer got more aggressive.
When a WHERE clause filters on the nullable side of a LEFT JOIN with a null-rejecting predicate, the optimizer can safely rewrite the outer join to an inner join. This transformation is backed by a theorem-level proof in relational algebra, not a rule of thumb. Kingbase KES enforces this strictly, checking two prerequisites before acting: the predicate must reference only nullable-side columns, and it must reject NULLs.
The rewrite flows through five stages inside KES — parsing, normalization, pattern matching, predicate pushdown, and physical operator selection. The optimizer splits AND conditions and checks each predicate individually; a single matching null-rejecting predicate is enough to trigger elimination. Once the join type changes, filters can be pushed down to the scan layer, often cutting query time by an order of magnitude on large tables.
KES distinguishes itself with cascading elimination across nested joins, transparent handling of views so that wrapped and raw SQL produce identical plans, and faithful translation of Oracle's legacy `(+)` syntax. Its design philosophy prioritizes semantic safety over speculative speed, which reduces migration risk when moving legacy workloads onto a domestic database.
KES's decision to split AND predicates and evaluate them individually, rather than treating the WHERE clause as a monolithic block, is a practical engineering choice that increases the optimizer's chances of finding an elimination opportunity without sacrificing correctness.
The cascading elimination across nested joins relies on a chain of nullability inferences — once an inner join guarantees a key is not-null, that property propagates upward and can justify eliminating the outer join above it. This is a subtle but powerful compositional reasoning step.
View transparency is an underappreciated optimizer property. When a view and its inline equivalent produce different execution plans, developers lose the ability to reason about performance through abstraction layers. KES treating them identically preserves that predictability.
The handling of Oracle's `(+)` syntax is not just syntactic sugar; it requires the optimizer to map legacy outer-join semantics onto the same null-rejection framework used for standard JOIN ON clauses, which is a non-trivial semantic alignment problem.