pgplan 0.2.0 → 0.3.0

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