SpitfireLoad Testing & APMWhat's new

SQL: query suggestions from the schema

Suggest from schema reads a connection's schema (tables, columns, primary keys, indexes, foreign keys) and suggests realistic read queries for the tables you choose: lookup by primary key, lookup by an indexed column, a join over a foreign key, child rows, an ordered page and a range count. Each suggestion is checked with EXPLAIN, and those that would scan a whole table are flagged. Without pg_stat_statements this is the fastest way to a meaningful read load.

Everything runs on your own Spitfire installation: queries go from your Spitfire server to your database, nothing is sent anywhere else, and no external or AI service is used.

Who can use it

Installation admins only. The API refuses workspace admins and users at every step (403); it needs a browser session and does not work with an API token. The button appears on PostgreSQL, MySQL / MariaDB, SQL Server, Oracle and MongoDB connections.

Warning

Using this feature on a production database is strongly discouraged. Catalog reads and EXPLAIN put a light load on the database. You are responsible for the account you provide.

Create a separate, least-privilege, read-only user for this (on MongoDB the read role only); never use root, a superuser or an admin. If the connection goes to production, tick Production database; Spitfire then shows a strong warning and asks for an extra confirmation.

How to get suggestions

1 Check

Privilege checkPrivilege check

  1. In the Connections group of All integrations In Spitfire: /admin/integrations#connections click the light bulb icon (Suggest from schema) on the connection's row. The same dialog also opens from a SQL step via Bulk add / import → Suggest from schema.

    Suggestions dialog opened from a SQL stepSuggestions dialog opened from a SQL step

  2. The 1. Check tab reads the connected user's privileges read-only (PostgreSQL role and table privileges, MySQL SHOW GRANTS, SQL Server sysadmin / db_owner / db_datawriter membership, Oracle roles and SESSION_PRIVS). The result: read-only (ideal), has write privileges (you can go on, a separate user is recommended), superuser / admin (needs an extra confirmation) or could not be checked.

  3. The A dedicated read-only user section shows the ready-made script for your database:

    • Required: schema reading and EXPLAIN: PostgreSQL a LOGIN role with CONNECT, USAGE, SELECT and default privileges; MySQL SELECT, SHOW VIEW; SQL Server db_datareader, VIEW DEFINITION, SHOWPLAN; Oracle CREATE SESSION, SELECT on the schema's tables, SELECT_CATALOG_ROLE.
    • Optional: statement statistics: PostgreSQL pg_read_all_stats; MySQL PROCESS and performance_schema; SQL Server VIEW SERVER STATE.
  4. Take the script with Copy, replace <CHANGE_ME_STRONG_PASSWORD> with a strong password of your own and run it on the database (Spitfire does not generate passwords). Put the user into the connection and click Check again. You should see a green read-only.

  5. Click Continue to the consent.

Consent screenConsent screen

  1. Pick the Scope: Schema only (no table data) reads catalog metadata only; Schema and sample values may also read sample values from columns you choose.
  2. Read the consent text. It is versioned and exists in TR and EN; it says what is read, that a separate least-privilege read-only user is required, that a production database is strongly discouraged, that catalog reads and EXPLAIN add a light load, and that the customer is responsible for the account.
  3. Tick I have read the text above and accept it for this connection.
  4. If the user is a superuser / admin, or Production database is ticked, you must tick the second, red checkbox too: I understand the warning in red (production database or superuser/admin account) and want to continue anyway.
  5. Give consent and continue.

The consent is stored verbatim and written to the audit log: your username and e-mail, the time, IP, browser, text version and language, the scope, the privilege check result and the warnings shown. A fingerprint of the connection is stored too: type, host, port, database, user, SSH host and user, production flag. Secrets never enter the fingerprint. When the fingerprint, the scope or the text version changes, the consent no longer applies and is asked again; without a valid consent, reads are refused.

3 Tables

TablesTables

  1. With a valid consent the dialog opens straight on 3. Tables. Optionally write comma-separated schema names in Only these schemas and Leave out schemas; left empty, every schema except the system ones is read.
  2. Read schema: schemas, tables, columns, keys, indexes and the catalog's row estimates are read, inside a read-only transaction where supported and with a timeout; at most 2000 tables. Table data is never read. The result is kept per connection; if the schema changed, Read again.
  3. Select tables (in a schema of up to 20 tables all start selected) or tick From all tables (N).
  4. Number of suggestions (10–100): default 20. Suggestions are spread at random over tables and kinds, big tables come up more often; Reshuffle makes a new pick.
  5. Click Suggest N queries (M tables).

4 Suggestions

SuggestionsSuggestions

Name, Weight, Query and Parameters can be edited. Each row shows its kind (primary key, index lookup, join, children, page, count), the EXPLAIN result (index, caution: full table scan, caution: full scan, high cost, EXPLAIN failed) and a rationale, e.g. Lookup by the index idx_orders_customer (customer_id).

EXPLAIN only asks for the plan and never runs the query: EXPLAIN on PostgreSQL/MySQL (never EXPLAIN ANALYZE), SHOWPLAN_XML on SQL Server, EXPLAIN PLAN on Oracle. Every suggestion has a row limit (LIMIT, TOP or FETCH FIRST) and passes the write guard as a read. The most common case: on small test tables the planner picks a scan and the full table scan badge appears; at production size the plan may differ.

  1. Untick the rows you don't want, edit as needed.
  2. Output: One query mix step or One step per statement.
  3. If you opened the dialog from All integrations, pick a test or a new test in Add to. From a SQL step, the suggestions go into that step.
  4. Add (N). Use Open in the editor in the Added to …. message to go to the test and save it.

MongoDB

The steps are the same. Differences: reading uses read-only commands only (listCollections, listIndexes, collStats and sample documents; the schema is inferred from them), and there is no EXPLAIN. Kinds: findOne by _id, index lookup, range + sort on an indexed field, page, countDocuments and aggregate with $match/$group. Each suggestion becomes its own MongoDB step (no query mix).

Sample values

  1. On the suggestions screen click Use sample values (separate consent). The dialog goes back to 1. Check for the Schema and sample values scope; give the consent again for that scope.
  2. Click Read sample values for this column into a data file next to a parameter.
  3. Spitfire reads, read-only, at most 1,000 distinct values from a bounded sample of the table (TABLESAMPLE / SAMPLE where supported) and saves them as a data file on the Spitfire server. The parameter is bound as {{data.column}}.

The values are never written to the log or the audit log; only their counts are.

Consent recordsConsent records

The Consent records tab shows every consent given for this connection: when, who, scope, privilege level, target and Status (valid, outdated (the connection or the text changed) or revoked). Revoke cancels a consent; the record is kept and marked, not deleted.

Every privilege check, schema read, EXPLAIN batch and sample read is written to the log and the audit log: the connection, the user, counts and durations. No secrets and no data values are written.

Common problems

Symptom Cause Fix
No Suggest from schema button You are not an installation admin, or the connection type is not supported Ask an installation admin
An installation admin's consent for this connection (as it is now) and scope is needed first. No consent, or the connection (host, user, SSH, production flag), the scope or the text version changed Consent again via 1. Check → Continue to the consent
Confirm the extra warning (production database or superuser account) to continue. Superuser/admin user or a production connection Switch to a read-only user; if you still go on, tick the red checkbox
The consent text has changed; read it again. The text version changed while the dialog was open Close and reopen the dialog, consent again
Privilege level could not be checked The user cannot read the catalog views, or no connection Test first; grant the privileges from the script
No tables in the chosen schemas (or the user cannot see them). Wrong filter or no SELECT Clear the filters; grant SELECT / USAGE
Only the first 2000 tables were read; narrow the schemas. More than 2000 tables Narrow with Only these schemas
No suggestions: the selected tables have no primary key, index or foreign key to build on. No keys or indexes Pick tables with keys or write queries by hand
The column has no values in the sample. Empty sample or an all-NULL column Pick another column or fill it by hand

Once the suggestions are in the test and Try it returns rows, you are done. Next: SQL, SQL: SSH tunnel.