pgplan 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +200 -0
  2. package/package.json +8 -7
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # pgplan
2
+
3
+ A command-line tool for analyzing and comparing PostgreSQL query execution plans. Get optimization insights and track performance regressions without leaving your terminal.
4
+
5
+ ## Features
6
+
7
+ - **Plan Analysis** - Run 15+ intelligent rules against a query plan to surface performance issues with actionable fix suggestions
8
+ - **Plan Comparison** - Semantically diff two plans side-by-side to understand what changed and whether it got better or worse
9
+ - **Flexible Input** - Accept JSON EXPLAIN output, raw SQL files, stdin, or paste plans interactively
10
+ - **Connection Profiles** - Save and manage named PostgreSQL connection strings for quick reuse
11
+ - **Multiple Output Formats** - Human-readable colored terminal output or structured JSON for tooling integration
12
+
13
+ ## Installation
14
+
15
+ ### [Go](https://pkg.go.dev/github.com/jacobarthurs/pgplan)
16
+
17
+ ```bash
18
+ go install github.com/jacobarthurs/pgplan@latest
19
+ ```
20
+
21
+ ### [NPM](https://www.npmjs.com/package/pgplan)
22
+
23
+ ```bash
24
+ npm i -g pgplan
25
+ ```
26
+
27
+ ### Binary
28
+
29
+ Download the latest release for your platform from the [releases page](https://github.com/JacobArthurs/pgplan/releases/latest).
30
+
31
+ ## Quick Start
32
+
33
+ ```bash
34
+ # Analyze a query plan from a JSON EXPLAIN output
35
+ pgplan analyze plan.json
36
+
37
+ # Analyze by running a SQL file against a database
38
+ pgplan analyze query.sql --db postgres://localhost:5432/mydb
39
+
40
+ # Compare two plans
41
+ pgplan compare before.json after.json
42
+
43
+ # Interactive mode - paste plans or queries directly into the terminal
44
+ pgplan analyze
45
+ pgplan compare
46
+ ```
47
+
48
+ ## Commands
49
+
50
+ ### `pgplan analyze [file]`
51
+
52
+ Analyzes a single query plan and returns optimization findings sorted by severity.
53
+
54
+ **Arguments:**
55
+
56
+ | Argument | Description |
57
+ | -------- | ----------- |
58
+ | `file` | Path to a `.json` (EXPLAIN output) or `.sql` file. Use `-` for stdin. Omit for interactive mode. |
59
+
60
+ **Flags:**
61
+
62
+ | Flag | Description |
63
+ | ---- | ----------- |
64
+ | `-d, --db` | PostgreSQL connection string (required for SQL input) |
65
+ | `-p, --profile` | Named connection profile to use |
66
+ | `-f, --format` | Output format: `text` (default) or `json` |
67
+
68
+ **Example:**
69
+
70
+ ```bash
71
+ pgplan analyze slow-query.sql --profile prod
72
+ ```
73
+
74
+ ### `pgplan compare [file1] [file2]`
75
+
76
+ Compares two query plans and reports on cost, time, row estimate, and buffer differences across every node in the plan tree.
77
+
78
+ **Arguments:**
79
+
80
+ | Argument | Description |
81
+ | -------- | ----------- |
82
+ | `file1` | The "before" plan. `.json`, `.sql`, `-` for stdin, or omit for interactive. |
83
+ | `file2` | The "after" plan. Same input options as `file1`. |
84
+
85
+ **Flags:**
86
+
87
+ | Flag | Description |
88
+ | ---- | ----------- |
89
+ | `-d, --db` | PostgreSQL connection string (required for SQL input) |
90
+ | `-p, --profile` | Named connection profile to use |
91
+ | `-f, --format` | Output format: `text` (default) or `json` |
92
+ | `-t, --threshold` | Percent change threshold for significance (default: `5`) |
93
+
94
+ **Example:**
95
+
96
+ ```bash
97
+ pgplan compare before.json after.json --threshold 10
98
+ ```
99
+
100
+ ### `pgplan profile <subcommand>`
101
+
102
+ Manages saved PostgreSQL connection profiles stored in `~/.config/pgplan/profiles.yaml`.
103
+
104
+ | Subcommand | Description |
105
+ | ---------- | ----------- |
106
+ | `list [--show]` | List saved profiles. Pass `--show` to display connection strings. |
107
+ | `add <name> <conn_str>` | Add or update a named profile. |
108
+ | `remove <name>` | Remove a profile. |
109
+ | `default <name>` | Set a profile as the default. |
110
+ | `clear-default` | Clear the default profile. |
111
+
112
+ **Example:**
113
+
114
+ ```bash
115
+ pgplan profile add prod postgres://user:pass@host:5432/mydb
116
+ pgplan profile default prod
117
+
118
+ # Now use it with analyze or compare
119
+ pgplan analyze query.sql --profile prod
120
+ ```
121
+
122
+ ## Analysis Rules
123
+
124
+ The `analyze` command applies the following rules to identify performance issues. Each finding includes a severity level and an actionable suggestion.
125
+
126
+ | Severity | Rule | Description |
127
+ | -------- | ---- | ----------- |
128
+ | Critical | Sort Spill to Disk | Sort operation exceeded `work_mem` and spilled to disk |
129
+ | Warning | Hash Spill to Disk | Hash table exceeded `work_mem` |
130
+ | Warning | Temp Block I/O | Plan is reading/writing temporary blocks |
131
+ | Warning | Seq Scan in Join | Sequential scan used inside a join against a smaller set |
132
+ | Warning | Seq Scan with Filter | Standalone sequential scan filtering a large number of rows |
133
+ | Warning | Index Scan Filter Inefficiency | Index scan is fetching many rows then discarding most via filter |
134
+ | Warning | Bitmap Heap Recheck | Lossy bitmap scan rechecking conditions (bitmap exceeded `work_mem`) |
135
+ | Warning | Nested Loop High Loops | Nested loop executing 1,000+ iterations |
136
+ | Warning | Correlated Subplan | Subplan re-executing on every outer row |
137
+ | Warning | Worker Launch Mismatch | Fewer parallel workers launched than planned |
138
+ | Warning | Parallel Overhead | Parallel execution is slower than the serial estimate |
139
+ | Warning | Large Join Filter Removal | Join filter is discarding a large percentage of rows |
140
+ | Warning | Excessive Materialization | Materialize node looping many times |
141
+ | Info | Low Selectivity Index Scan | Index scan is returning most of the table |
142
+ | Info | Wide Row Output | Query is selecting more columns than necessary |
143
+
144
+ ## Comparison Output
145
+
146
+ The `compare` command produces a structured diff of two plans including:
147
+
148
+ - **Summary** - Overall cost, execution time, and buffer changes with directional indicators
149
+ - **Node Details** - Per-node breakdown of metric changes (cost, rows, loops, buffers, filters, indexes)
150
+ - **Verdict** - A final assessment such as "faster and cheaper" or "slower but cheaper"
151
+
152
+ Changes below the significance threshold (default 5%) are filtered out to reduce noise.
153
+
154
+ ## Output Formats
155
+
156
+ ### Text (default)
157
+
158
+ Colored terminal output with severity-coded findings and directional change indicators. Designed for quick human review.
159
+
160
+ ### JSON
161
+
162
+ Structured output suitable for piping into other tools, CI systems, or dashboards. Includes all metrics, findings, and comparison deltas.
163
+
164
+ ```bash
165
+ pgplan analyze plan.json --format json | jq '.findings[] | select(.severity == "critical")'
166
+ ```
167
+
168
+ ## Configuration
169
+
170
+ ### Connection Profiles
171
+
172
+ Profiles are stored in a YAML configuration file at the platform-appropriate config directory:
173
+
174
+ - **Linux/macOS:** `~/.config/pgplan/profiles.yaml`
175
+ - **Windows:** `%APPDATA%\pgplan\profiles.yaml`
176
+
177
+ ```yaml
178
+ default: prod
179
+ profiles:
180
+ - name: prod
181
+ conn_str: postgres://user:pass@host:5432/production
182
+ - name: dev
183
+ conn_str: postgres://localhost:5432/development
184
+ ```
185
+
186
+ Use `--profile <name>` with any command, or set a default to skip the flag entirely. The `--db` and `--profile` flags are mutually exclusive.
187
+
188
+ ## Contributing
189
+
190
+ Contributions are welcome! To get started:
191
+
192
+ 1. Fork the repository
193
+ 2. Create a feature branch (`git checkout -b my-new-feature`)
194
+ 3. Open a pull request
195
+
196
+ CI will automatically run tests and linting on your PR.
197
+
198
+ ## License
199
+
200
+ This project is licensed under the [MIT License](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgplan",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Analyze and compare PostgreSQL query plans",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,13 +16,14 @@
16
16
  "pgplan": "bin/pgplan"
17
17
  },
18
18
  "files": [
19
- "bin/**"
19
+ "bin/**",
20
+ "README.md"
20
21
  ],
21
22
  "optionalDependencies": {
22
- "@pgplan/linux-x64": "0.2.0",
23
- "@pgplan/linux-arm64": "0.2.0",
24
- "@pgplan/darwin-x64": "0.2.0",
25
- "@pgplan/darwin-arm64": "0.2.0",
26
- "@pgplan/win32-x64": "0.2.0"
23
+ "@pgplan/linux-x64": "0.2.1",
24
+ "@pgplan/linux-arm64": "0.2.1",
25
+ "@pgplan/darwin-x64": "0.2.1",
26
+ "@pgplan/darwin-arm64": "0.2.1",
27
+ "@pgplan/win32-x64": "0.2.1"
27
28
  }
28
29
  }