Skip to main content

Module simplify

Module simplify 

Source
Expand description

Boolean and algebraic expression simplification Expression Simplification

This module provides boolean and expression simplification for SQL AST nodes. It applies various algebraic transformations to simplify expressions:

  • De Morgan’s laws (NOT (A AND B) -> NOT A OR NOT B)
  • Constant folding (1 + 2 -> 3)
  • Boolean absorption (A AND (A OR B) -> A)
  • Complement removal (A AND NOT A -> FALSE)
  • Connector flattening (A AND (B AND C) -> A AND B AND C)

Based on SQLGlot’s optimizer/simplify.py

Structs§

Simplifier
Expression simplifier

Functions§

absorb_and_eliminate_and
Apply Boolean absorption and elimination rules to an AND expression
absorb_and_eliminate_or
Apply Boolean absorption and elimination rules to an OR expression
always_false
Check if expression is always false
always_true
Check if expression is always true
bool_false
Create a FALSE boolean literal
bool_true
Create a TRUE boolean literal
eval_boolean_nums
Evaluate a boolean comparison between two numbers
eval_boolean_strings
Evaluate a boolean comparison between two strings
gen
Generate a simple string representation of an expression for sorting/deduping
is_boolean_false
Check if expression is a boolean FALSE literal (not just falsy)
is_boolean_true
Check if expression is a boolean TRUE literal (not just truthy)
is_complement
Check if b is the complement of a (i.e., b = NOT a)
is_false
Check if expression is boolean FALSE
is_null
Check if expression is NULL
is_zero
Check if expression is zero
null
Create a NULL expression
simplify
Main entry point for expression simplification