SynapCores

AI-Native Database Query Optimizer

By , Founder & CTO, SynapCores · Published · Updated

SynapCores Query Optimizer

Target Audience: Solution Architects, Technical Decision Makers, Database Engineers


Executive Summary

The SynapCores Query Optimizer represents a significant advancement in AI-native database performance optimization. Built entirely in Rust for maximum performance and safety, it picks an access path to fit each predicate: B-tree indexes serve equality and range filters, hash indexes serve equality lookups, HNSW indexes serve top-k similarity search, and BM25 full-text indexes serve MATCH ... AGAINST. EXPLAIN shows the plan it chose, and EXPLAIN ANALYZE measures that plan on your own data and hardware.

Key Value Propositions

  • Filters pushed into the scan: equality and range predicates run inside the index or table scan, so joins and vector scoring see only matching rows
  • HNSW top-k search: ORDER BY the similarity function that matches the index metric, then LIMIT k, and the plan reads the HNSW index
  • Zero-configuration deployment for immediate performance gains
  • Measured on your hardware: EXPLAIN ANALYZE runs the query and reports the plan with its actual time and rows

Unique Differentiators

Unlike traditional database optimizers that treat AI/ML as an afterthought, SynapCores' optimizer is purpose-built for AI-native workloads:

  1. Native Vector Operation Optimization: First-class support for vector similarity operations and semantic search
  2. ML Inside the Query: EMBED() computes embeddings in SQL, CREATE EXPERIMENT trains models and PREDICT scores rows, all next to the data
  3. Rust Performance: Zero-cost abstractions and memory safety without garbage collection overhead
  4. Unified Architecture: One planner covers relational filters, joins, BM25 full-text search and vector top-k, so a hybrid query runs as a single plan
  5. Plans You Can Inspect: EXPLAIN shows the operator tree and the index each scan uses, and EXPLAIN (FORMAT JSON) returns it for tooling

The AI-Native Database Challenge

Modern applications increasingly combine traditional relational operations with AI/ML workloads:

  • Semantic search over product catalogs using vector embeddings
  • Real-time fraud detection combining SQL aggregations with ML inference
  • Multimodal queries joining structured data with image/text similarity
  • Hybrid OLTP/OLAP workloads requiring both transaction and analytical performance

Traditional database optimizers, designed before widespread AI adoption, struggle with these workloads. They lack native understanding of:

  • Vector distance metrics and the indexes that serve them
  • Embedding generation as part of the query
  • ML model inference as query operators
  • Semantic similarity vs. keyword matching trade-offs

Optimization Architecture

Query Execution Pipeline

SQL Query Input
       |
       v
+------------------+
|   SQL Parser     |  Custom dialect with AI extensions
+------------------+  Parses: SQL + VECTOR ops + ML functions
       |
       v
+------------------+
|  AST -> Logical  |  Converts parse tree to executable plan
|      Plan        |  Handles: joins, filters, projections
+------------------+
       |
       v
+-----------------------------------------------------+
|           UNIFIED QUERY OPTIMIZER                   |
|                                                     |
|  +-----------------------------------------------+  |
|  |          Stage 1: Rewrite Rules               |  |
|  |  Fast, always-beneficial transformations      |  |
|  |  - Constant Folding (evaluate at compile)     |  |
|  |  - Predicate Pushdown (filters to scans)      |  |
|  |  - Projection Pushdown (named columns)        |  |
|  |  - Filter Merging (combine AND predicates)    |  |
|  |  See it: EXPLAIN lists scan predicates        |  |
|  +-----------------------------------------------+  |
|       |                                             |
|       v                                             |
|  +-----------------------------------------------+  |
|  |         Stage 2: Access Paths                 |  |
|  |  Each scan gets the index that fits it        |  |
|  |  - Primary key: point lookups                 |  |
|  |  - B-tree: equality and range filters         |  |
|  |  - Hash: equality lookups                     |  |
|  |  - HNSW: ORDER BY similarity ... LIMIT k      |  |
|  |  - BM25 full-text: MATCH ... AGAINST          |  |
|  |  See it: EXPLAIN names the chosen index       |  |
|  +-----------------------------------------------+  |
+-----------------------------------------------------+
       |
       v
+------------------+
| Optimized Plan   |  Ready for execution
|   Executor       |  EXPLAIN ANALYZE: actual time and rows
+------------------+

Core Optimization Techniques

Join Planning

Problem: Join order dramatically affects query performance. A poorly ordered 5-table join can produce far larger intermediate results than a well-ordered one.

SynapCores Approach: the plan joins tables in the order your FROM clause lists them, and pushes each table's filters into its own scan, so every join sees only the rows that match. You choose the join order, and EXPLAIN shows it:

EXPLAIN SELECT c.name, o.order_id, o.total_spend
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE c.region = 'east'
  AND o.order_date >= '2025-01-01'

With a B-tree index on orders (order_date), the plan joins customers to orders in that order (operator lines from EXPLAIN):

Projection
  InnerJoin
    TableScan
      table: customers
    IndexScan
      table: orders, index: idx_orders_order_date

Each scan also lists its scan predicates: region = 'east' on customers and the order_date filter on orders. List the most selective table first, index the filter columns, and compare the alternatives with EXPLAIN ANALYZE on your own data.

Performance Impact

Check the join plan on your own workload:

What to Check How
Join tree and join conditions EXPLAIN shows each InnerJoin with its on: condition
Filters applied in each table scan EXPLAIN lists them as scan predicates on the TableScan or IndexScan
Indexes used EXPLAIN names the index on each IndexScan
Actual time and rows EXPLAIN ANALYZE runs the query on your data and hardware

Projection Pushdown

Problem: Reading unnecessary columns wastes I/O bandwidth and memory.

Example: name the columns the query uses instead of SELECT *.

Before:

SELECT customer_id, total_spend
FROM (
    SELECT * FROM orders WHERE order_date > '2025-01-01'
) subquery
JOIN customers ON customers.id = subquery.customer_id

After:

SELECT customer_id, total_spend
FROM (
    SELECT customer_id, total_spend, order_date
    FROM orders WHERE order_date > '2025-01-01'
) subquery
JOIN customers ON customers.id = subquery.customer_id

Check it: EXPLAIN lists the columns each subquery projects, and EXPLAIN ANALYZE times both forms on your own data and hardware.

Primary-Key Point Lookups

Problem: OLTP workloads repeat small lookups by key, thousands of times with different values.

SynapCores Solution: an equality on the primary key reads the row through the table's primary-key index, with no table scan:

EXPLAIN SELECT product_id, name, price FROM products WHERE product_id = 42
Projection
  IndexScan
    table: products, index: products_pkey

On Your Workload: send repeated OLTP queries as one parameterized statement ($1 placeholders with a parameters array on POST /v1/query/execute), and track the execution_time_ms that each response reports.


AI/ML Workload Optimization

Vector Similarity Plans

SynapCores natively understands vector similarity operations:

SELECT product_id, name,
       COSINE_SIMILARITY(embedding, EMBED('wireless headphones')) AS score
FROM products
ORDER BY score DESC
LIMIT 10

Performance Comparison

Scenario: a products table whose embedding VECTOR(384) column is filled by EMBED(). Compare the two plans with EXPLAIN, then time them with EXPLAIN ANALYZE on your own data and hardware.

Sequential Scan: without a vector index, the plan scores every row, then sorts (operator lines from EXPLAIN):

Limit
  Sort
    Projection
      TableScan
        table: products

HNSW Vector Index: create an index whose metric matches the similarity function:

CREATE INDEX idx_products_embedding ON products (embedding)
    USING HNSW WITH (metric = 'cosine', m = 16, ef_construction = 200, ef_search = 64);

The same EXPLAIN now reads the index:

Limit
  Sort
    Projection
      HNSW IndexScan
        table: products, index: idx_products_embedding
  • EXPLAIN ANALYZE runs the query and reports the plan with its actual time and rows under Actual Execution Metrics
  • Top-k queries read the index when they ORDER BY the function that matches its metric (COSINE_SIMILARITY for 'cosine') and LIMIT k
  • A similarity threshold in WHERE makes the query an exact, filtered scan: EXPLAIN shows a Filter above the table or index scan

Hybrid Query Optimization

Query: Combine traditional SQL filtering with semantic search

SELECT product_id, name, price,
       COSINE_SIMILARITY(embedding, EMBED('wireless headphones')) AS semantic_score
FROM products
WHERE
    price BETWEEN 50 AND 200
    AND category = 'electronics'
    AND in_stock = true
    AND COSINE_SIMILARITY(embedding, EMBED('wireless headphones')) > 0.7
ORDER BY semantic_score DESC
LIMIT 20

Optimization Strategy: with a B-tree index on category (CREATE INDEX idx_products_category ON products (category)), EXPLAIN shows this plan:

Step Operator What It Does
1 IndexScan on idx_products_category Reads the 'electronics' rows through the index and applies the price range and in_stock = true in the same scan
2 Filter Computes COSINE_SIMILARITY for those rows only and keeps scores above 0.7
3 Projection Builds the output columns
4 Sort Ranks the matching rows exactly by semantic_score
5 Limit Returns the top 20

Measure it: EXPLAIN ANALYZE runs this plan on your own data and hardware and reports its actual time and rows.

Key Insight: Apply cheap filters before expensive vector operations


Performance Benchmarks

Benchmark Your Own Workload

Query times depend on your hardware, data size, schema, indexes and configuration, so benchmark SynapCores on your own workload:

  1. Load a representative sample of your data, and index the columns your queries filter and rank on
  2. Run EXPLAIN on each query to confirm the access path: IndexScan for B-tree and hash lookups, HNSW IndexScan for top-k similarity, FULLTEXT IndexScan (BM25) for MATCH ... AGAINST
  3. Run EXPLAIN ANALYZE to time each query: it runs the query and reports the plan with its actual time and rows
  4. Under concurrent load, check GET /v1/query/admission: the engine runs up to max_concurrent_queries SQL statements at once (32 in the shipped configuration) and queues further requests (a queue_capacity of 128 with that setting)

E-Commerce Workload

Product Search (OLTP - High Frequency):

EXPLAIN ANALYZE
SELECT p.product_id, p.name, p.price,
       COSINE_SIMILARITY(p.embedding, EMBED('wireless headphones')) AS score
FROM products p
WHERE p.category = 'electronics'
  AND p.price BETWEEN 100 AND 500
  AND COSINE_SIMILARITY(p.embedding, EMBED('wireless headphones')) > 0.8
ORDER BY score DESC LIMIT 20
  • The plan reads idx_products_category, applies the price range in the same scan, then filters and ranks the matching rows exactly
  • EXPLAIN ANALYZE runs the query on your data and hardware and reports the plan with its actual time and rows under Actual Execution Metrics

Sales Analytics (OLAP - Low Frequency):

  • Run your reporting queries with EXPLAIN ANALYZE before and after you index the columns they filter on, and compare the actual times

Competitive Advantages

vs Traditional Databases

Feature PostgreSQL SynapCores Advantage
Vector Search pgvector extension Built-in VECTOR(n) columns, with HNSW IndexScan for top-k No extension to install
Embeddings Computed outside the database EMBED() inside SQL, with the model in-process No embedding service
Full-Text Search tsvector with GIN indexes and ts_rank FULLTEXT IndexScan (BM25) for MATCH ... AGAINST BM25 ranking built in
ML Integration External services CREATE EXPERIMENT, PREDICT and AUTOML.PREDICT() in SQL Training and scoring next to the data

vs Specialized Vector Databases

Feature Vector DBs SynapCores Advantage
Vector Search Excellent Excellent Tie
Hybrid Queries Limited SQL Full SQL + vectors True hybrid
OLTP Support No Yes Unified platform
ACID Transactions Limited Full Data consistency

Best Practices

Index Maintenance

Index what your queries filter and rank on, then confirm the access path with EXPLAIN:

-- B-tree (the default): equality and range filters
CREATE INDEX idx_orders_order_date ON orders (order_date);

-- Hash: equality lookups
CREATE INDEX idx_orders_status ON orders (status) USING HASH;

-- BM25 full-text: MATCH ... AGAINST
CREATE INDEX idx_products_description ON products (description) USING FULLTEXT;

-- List a table's indexes and their types
SHOW INDEXES FROM products;

Recommendations:

  • After you add an index, run EXPLAIN on the queries it should serve: each IndexScan line names the index it reads
  • After a bulk load, re-run EXPLAIN ANALYZE on your hot queries and compare their actual time and rows

Query Optimization Tips

Use Explicit Predicates:

-- GOOD: Optimizer can use index
SELECT * FROM orders
WHERE order_date >= '2025-01-01'
  AND order_date < '2025-02-01';

-- BAD: Function prevents index use
SELECT * FROM orders
WHERE EXTRACT(YEAR FROM order_date) = 2025;

Use Parameterized Queries:

-- Bind the values as $1 and $2 with a "parameters" array on POST /v1/query/execute:
-- one statement text for every value, with the values sent separately from the SQL
SELECT * FROM products WHERE category = $1 AND price > $2;

Conclusion

The SynapCores Query Optimizer delivers:

Performance You Can Verify:

  • Index-aware plans: B-tree, hash, HNSW and BM25 full-text access paths, each chosen to fit its predicate
  • Filters applied inside the scan, before joins and vector scoring
  • EXPLAIN ANALYZE timings on your own data and hardware

AI-Native Advantages:

  • HNSW top-k plans: ORDER BY the function that matches the index metric, then LIMIT k
  • Embeddings, model training and scoring inside SQL (EMBED(), CREATE EXPERIMENT, PREDICT)
  • Optimized hybrid query execution (SQL + semantic search)
  • BM25 full-text and vector similarity search in one SQL engine

For organizations building AI-native applications, SynapCores' optimizer provides enterprise-grade performance optimization with none of the complexity typically associated with database tuning.


Document Version: 1.0 Last Updated: November 2026 Website: https://synapcores.com