Skip to content

feat: add --explain flag for query plan introspection#185

Merged
vmvarela merged 1 commit into
masterfrom
issue-166/explain-flag
Jul 3, 2026
Merged

feat: add --explain flag for query plan introspection#185
vmvarela merged 1 commit into
masterfrom
issue-166/explain-flag

Conversation

@vmvarela

Copy link
Copy Markdown
Owner

Description

Adds --explain flag that runs EXPLAIN QUERY PLAN on the user's SQL query and prints the SQLite execution plan to stderr before executing the query. Each plan line is prefixed with QUERY PLAN: for readability.

$ printf 'region,amount\nEast,100\nWest,200\n' | sql-pipe --explain 'SELECT region, SUM(amount) FROM t GROUP BY region'
QUERY PLAN: SCAN t
East,100
West,200

The query plan goes to stderr so stdout stays clean for piping. The actual query still executes normally.

Changes

  • src/args.zigExplainWithFlags error variant, explain field, parsing, help text, mutual exclusion with --columns, --validate, --sample, --stats, --output
  • src/main.zigprintQueryPlan() helper function using EXPLAIN QUERY PLAN (ArrayList null-byte pattern for Zig 0.16), wired into run()
  • build.zig — 11 integration tests (basic, stdout-clean, exit-0, 5x mutual exclusion, help-grep, nonexistent-table error, query-file, empty-stdin)
  • README.md — flags table entry + usage example
  • docs/sql-pipe.1.scd — synopsis, OPTIONS, examples

Related Issue

Closes #166

Add --explain flag that runs EXPLAIN QUERY PLAN on the user's SQL query
and prints the SQLite execution plan to stderr before executing the query.
Each plan line is prefixed with QUERY PLAN: for readability. The actual
query still executes normally with results on stdout.

- Add ExplainWithFlags error, explain field, parsing, and mutual exclusion
  in src/args.zig
- Add printQueryPlan() helper and wiring in src/main.zig
- 11 integration tests in build.zig covering basic usage, stdout cleanliness,
  exit codes, mutual exclusion with all mode flags, nonexistent table error,
  query file support, and empty stdin
- Update README.md and docs/sql-pipe.1.scd with flag documentation
@vmvarela vmvarela added type:feature New functionality size:s Small — 1 to 4 hours labels Jun 30, 2026
@vmvarela vmvarela self-assigned this Jun 30, 2026
@vmvarela vmvarela merged commit 9b136b9 into master Jul 3, 2026
5 checks passed
@vmvarela vmvarela deleted the issue-166/explain-flag branch July 3, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:s Small — 1 to 4 hours type:feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --explain flag for query plan introspection

1 participant