[ExoBench server version: 1.4.30]
## ⚠️ EPHEMERAL DATABASE — READ THIS FIRST ⚠️
Each call (and each scalePoint) provisions a fresh database from `schemaTemplate`
and DESTROYS it. Tables, data, indexes, and settings from previous calls are GONE.
`correlationId` is for tracking only — it does NOT preserve DB state. Pass the
FULL `schemaTemplate` (CREATE TABLE + INSERT + INDEX + VACUUM ANALYZE) in EVERY
call. If the user expects persistence, tell them ExoBench has none.
ExoBench: Benchmark SQL query performance using native data generation (Postgres, SQL Server, or MySQL).
Supports Postgres, SQL Server, and MySQL via the `databaseType` parameter (default: POSTGRES).
Postgres and SQL Server support GENERATE_SERIES for native data generation.
## ⚠️ MYSQL: the examples below are POSTGRES/SQL-SERVER ONLY.
MySQL uses recursive CTEs (NOT generate_series). Its EXTENSIVE patterns + a full multi-table example
live in getMcpDocs('benchmark-sql'). Writing a MySQL benchmark? Call getMcpDocs('benchmark-sql') FIRST —
do NOT guess MySQL syntax from the Postgres examples below.
Generates test data directly inside the database, which is:
- 100x faster than benchmarkSqlGeneric (no network round-trips for INSERT statements)
- More realistic performance measurements (tests actual database performance, not network+database)
- Better for large-scale benchmarks (can handle millions of rows without network bottleneck)
IMPORTANT: The server enforces a maximum of 5 scale points per request, and a hard limit of 3 million total
rows per scale point (sum of all variable values). Requests exceeding these limits will be rejected with an error.
**Cumulative compute budget:** Each request is also bounded by total execution time across all scale points.
Scale points at 1M+ rows should generally be run as separate requests. A sweep like
`[{"SCALE": 10000}, {"SCALE": 100000}, {"SCALE": 1000000}]` is safe;
`[{"SCALE": 1000000}, {"SCALE": 2000000}]` will likely time out and should be split into two calls.
If a request fails with a generic execution error, the first thing to try is splitting large scale points into
separate calls before assuming a server or schema issue.
Additionally, this tool gives you full control over data generation using native SQL, unlike benchmarkSqlGeneric
which auto-generates random data. Use this when you need:
- Realistic data distributions (skewed, correlated, time-series)
- Precise control over foreign key relationships
- Complex data patterns that columnConstraints can't express
- ANY Postgres or SQL Server benchmarking (it's simply better in every way)
CRITICAL (Postgres only): Always end schemaTemplate with VACUUM ANALYZE after INSERTs.
For SQL Server: Use UPDATE STATISTICS after INSERTs instead.
SQL SERVER EXECUTION PLANS (AUTOMATIC — NO USER ACTION NEEDED):
The server automatically prepends SET STATISTICS XML ON to every SQL Server benchmark query.
You do NOT need to include it yourself — just write your SELECT. The XML execution plan
(equivalent of Postgres's EXPLAIN ANALYZE) is captured automatically and returned in the
response's `additions` array with kind="sqlServerPlanXml". Including SET STATISTICS XML ON
in your query is harmless (it's idempotent) but unnecessary.
You MAY optionally also add SET STATISTICS IO ON and/or SET STATISTICS TIME ON to capture
logical-read counts and CPU/elapsed time breakdowns. These surface as additional messages
in the response's `additions` array with type="additionalMessage". Example:
SET STATISTICS IO ON; SET STATISTICS TIME ON; SELECT * FROM users WHERE created_at > DATEADD(DAY, -30, GETDATE());
Postgres Index Only Scans need an up-to-date visibility map. After bulk INSERTs, the visibility map
is empty, forcing heap fetches even with covering indexes (2-4x slower). VACUUM updates the visibility
map to mark all rows visible, enabling true index-only scans with zero heap fetches.
Production autovacuum maintains this continuously, so VACUUM'd benchmarks represent production reality.
Without VACUUM, you're measuring a transient post-bulk-load state. VACUUM ANALYZE adds minimal overhead
(1-3 seconds for millions of rows) compared to the INSERT time, and is essential for accurate Index Only Scan benchmarks.
ANALYZE updates statistics but NOT the visibility map. Use VACUUM ANALYZE, not just ANALYZE.
HOW IT WORKS:
1. Your schemaTemplate contains ${VARIABLE} placeholders
2. Each scalePoint is a map of variable names to values
3. For each scalePoint, the tool substitutes variables, runs the schema, then benchmarks the query
SIMPLE EXAMPLE (single variable):
schemaTemplate:
```sql
CREATE TABLE users (id INT PRIMARY KEY, name TEXT, created_at TIMESTAMP);
INSERT INTO users SELECT i, 'user_' || i, NOW() - (i || ' days')::interval
FROM generate_series(1, ${SCALE}) i;
VACUUM ANALYZE;
```
scalePoints: [{"SCALE": 1000}, {"SCALE": 10000}, {"SCALE": 100000}]
query: "EXPLAIN ANALYZE SELECT * FROM users WHERE created_at > NOW() - interval '30 days'"
MULTI-TABLE EXAMPLE (multiple variables):
schemaTemplate:
```sql
CREATE TABLE customers (id INT PRIMARY KEY, tier TEXT);
INSERT INTO customers SELECT i, CASE WHEN random() < 0.1 THEN 'gold' ELSE 'regular' END
FROM generate_series(1, ${CUSTOMERS}) i;
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, total NUMERIC);
INSERT INTO orders SELECT i, (random() * ${CUSTOMERS})::int + 1, random() * 1000
FROM generate_series(1, ${ORDERS}) i;
VACUUM ANALYZE;
```
scalePoints: [
{"CUSTOMERS": 1000, "ORDERS": 5000},
{"CUSTOMERS": 10000, "ORDERS": 50000},
{"CUSTOMERS": 100000, "ORDERS": 500000}
]
SKEWED DATA EXAMPLE (reproducing "slow user" scenarios):
schemaTemplate:
```sql
CREATE TABLE large (key INT PRIMARY KEY, x_key INT, tags TEXT[]);
-- 95% of rows have x_key = 1 (extreme skew)
INSERT INTO large SELECT i,
CASE WHEN i <= (${SCALE} * 0.95)::int THEN 1 ELSE (i % 999) + 2 END,
CASE WHEN i % 3 = 0 THEN ARRAY['blah'] ELSE ARRAY['foo'] END
FROM generate_series(1, ${SCALE}) i;
CREATE INDEX idx_x_key ON large(x_key);
VACUUM ANALYZE;
```
SQL SERVER EXAMPLES:
SQL Server supports GENERATE_SERIES natively. Do NOT use recursive CTEs for row generation.
IMPORTANT SYNTAX DIFFERENCE: SQL Server uses `FROM GENERATE_SERIES(1, N) gs` (table alias only),
NOT `FROM GENERATE_SERIES(1, N) AS s(value)` (Postgres-style column aliasing is INVALID).
The output column is always named `value` — reference it as `gs.value` or just `value`.
SIMPLE SQL SERVER EXAMPLE:
schemaTemplate:
```sql
CREATE TABLE users (id INT PRIMARY KEY, name NVARCHAR(100), created_at DATETIME2);
INSERT INTO users (id, name, created_at)
SELECT gs.value, CONCAT('user_', gs.value), DATEADD(DAY, -gs.value, GETDATE())
FROM GENERATE_SERIES(1, ${SCALE}) gs;
UPDATE STATISTICS users;
```
scalePoints: [{"SCALE": 1000}, {"SCALE": 10000}, {"SCALE": 100000}]
query: "SELECT * FROM users WHERE created_at > DATEADD(DAY, -30, GETDATE())"
MULTI-TABLE SQL SERVER EXAMPLE:
schemaTemplate:
```sql
CREATE TABLE customers (id INT PRIMARY KEY, tier NVARCHAR(20));
INSERT INTO customers (id, tier)
SELECT gs.value, CASE WHEN ABS(CHECKSUM(NEWID())) % 10 < 1 THEN 'gold' ELSE 'regular' END
FROM GENERATE_SERIES(1, ${CUSTOMERS}) gs;
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, total DECIMAL(10,2));
INSERT INTO orders (id, customer_id, total)
SELECT gs.value, ABS(CHECKSUM(NEWID())) % ${CUSTOMERS} + 1, RAND(CHECKSUM(NEWID())) * 1000
FROM GENERATE_SERIES(1, ${ORDERS}) gs;
UPDATE STATISTICS customers;
UPDATE STATISTICS orders;
```
scalePoints: [
{"CUSTOMERS": 1000, "ORDERS": 5000},
{"CUSTOMERS": 10000, "ORDERS": 50000},
{"CUSTOMERS": 100000, "ORDERS": 500000}
]
⚠️ FOR MYSQL EXAMPLES (recursive CTEs, cte_max_recursion_depth, ANALYZE TABLE): see getMcpDocs('benchmark-sql').
OUTPUT FORMAT:
Returns JSON objects, one per scalePoint:
{"scalePoint": {"SCALE": 1000}, "sql": "EXPLAIN ANALYZE...", "output": [...], "runtimeDurationMs": 5}
{"scalePoint": {"SCALE": 10000}, "sql": "EXPLAIN ANALYZE...", "output": [...], "runtimeDurationMs": 12}
⚠️ `runtimeDurationMs` includes compile + network + serialization — NOT pure execution time.
NEVER compare it across Postgres vs SQL Server vs MySQL. For true query time use:
- Postgres: root operator `actual time` in EXPLAIN ANALYZE (e.g. `..59.060` = 59ms)
- SQL Server: `QueryTimeStats.ElapsedTime` in plan XML additions (excludes compile)
- MySQL: `actual time` in EXPLAIN ANALYZE tree output
Use `runtimeDurationMs` only for same-engine scale-point comparisons.
WHEN TO USE THIS vs benchmarkSqlGeneric:
- ALWAYS use benchmarkSql for Postgres and SQL Server (faster, cheaper, more realistic)
- Use benchmarkSqlGeneric ONLY for SQLite (which doesn't support native data generation)
- Use benchmarkSql when you need precise control over data distribution
- Use benchmarkSql when debugging performance issues that depend on data skew
IF THIS TIMES OUT: you get a workerId and a "still running" status — that is NOT a result. You MUST
then call the matching results tool (benchmarkSqlResults / benchmarkSqlGenericResults / runSqlResults)
with that workerId, repeatedly, until it returns a terminal result. Do NOT end your turn, summarize,
or report any findings while a worker is still running.
PARTIAL RESULTS: If this call times out (returns a "still running" error with a workerId),
the error's `data` field MAY contain partial results (scale points completed so far).
These are best-effort and NOT guaranteed — do not depend on their presence.