Inside the Rewrite Engine

The rewrite engine is Isofold’s core logic layer. It takes an incoming SQL query, analyzes its structure and semantics, and emits a transformed version that:

  • Is semantically equivalent
  • Is cheaper to execute
  • Returns identical results

Optimization Passes

Isofold uses a series of transformation passes on incoming queries:

✅ Projection Pruning

Remove unused columns from SELECT * or overly wide result sets.

-- Original
SELECT * FROM events WHERE user_id = 'abc'

-- Rewritten
SELECT user_id, timestamp FROM events WHERE user_id = 'abc'

✅ Subquery Flattening

Flatten nested SELECTs or CTEs where they don’t affect semantics.

-- Original
SELECT * FROM (SELECT id, email FROM users) AS u

-- Rewritten
SELECT id, email FROM users

✅ Join Elision

Remove unnecessary joins (e.g. when a join is non-contributory to the result).

✅ Constant Folding & Simplification

Collapse constant expressions and simplify conditionals for better planning.

-- Original
WHERE created_at >= TIMESTAMP('2023-01-01') AND TRUE

-- Rewritten
WHERE created_at >= TIMESTAMP('2023-01-01')

Cost Awareness

Isofold tracks which rewrites reduce costs without increasing compute time or result size. It can optionally test:

  • Before/after query cost (e.g. using BigQuery dry-run mode)
  • Byte scan reduction
  • Slot time / compute usage

Rewrite Safety

All rewrites are:

  • Verified for structural equivalence where possible
  • Testable via the /verify API or dashboard
  • Auditable through logs and side-by-side comparisons

You can configure Isofold to apply:

  • Safe rewrites only (minimal risk)
  • Aggressive rewrites (more savings, potential caveats)

Custom Rules (Coming Soon)

Isofold will soon support user-defined rewrite policies to:

  • Enforce column projections
  • Rewrite expensive patterns
  • Apply warehouse-specific hints

Continue to the Topology Overview to understand how requests flow through the system.