feat: add --explain flag for query plan introspection#185
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
--explainflag that runsEXPLAIN QUERY PLANon the user's SQL query and prints the SQLite execution plan to stderr before executing the query. Each plan line is prefixed withQUERY PLAN:for readability.The query plan goes to stderr so stdout stays clean for piping. The actual query still executes normally.
Changes
src/args.zig—ExplainWithFlagserror variant,explainfield, parsing, help text, mutual exclusion with--columns,--validate,--sample,--stats,--outputsrc/main.zig—printQueryPlan()helper function using EXPLAIN QUERY PLAN (ArrayList null-byte pattern for Zig 0.16), wired intorun()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 exampledocs/sql-pipe.1.scd— synopsis, OPTIONS, examplesRelated Issue
Closes #166