pgplan 1.1.0__py3-none-win_arm64.whl

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.
pgplan/__init__.py ADDED
@@ -0,0 +1,29 @@
1
+ import os
2
+ import subprocess
3
+ import sys
4
+ import platform
5
+
6
+
7
+ def main():
8
+ system = platform.system().lower()
9
+
10
+ if system == "windows":
11
+ binary_name = "pgplan.exe"
12
+ else:
13
+ binary_name = "pgplan"
14
+
15
+ binary_path = os.path.join(os.path.dirname(__file__), "bin", binary_name)
16
+
17
+ if not os.path.isfile(binary_path):
18
+ print(
19
+ f"pgplan: binary not found at {binary_path}\n"
20
+ f"try reinstalling: pip install pgplan",
21
+ file=sys.stderr,
22
+ )
23
+ sys.exit(1)
24
+
25
+ if system == "windows":
26
+ proc = subprocess.run([binary_path] + sys.argv[1:])
27
+ sys.exit(proc.returncode)
28
+ else:
29
+ os.execv(binary_path, [binary_path] + sys.argv[1:])
pgplan/bin/pgplan.exe ADDED
Binary file
@@ -0,0 +1,223 @@
1
+ Metadata-Version: 2.1
2
+ Name: pgplan
3
+ Version: 1.1.0
4
+ Summary: Analyze and compare PostgreSQL query plans
5
+ License: MIT
6
+ Requires-Python: >=3.7
7
+ Description-Content-Type: text/markdown
8
+
9
+ # pgplan
10
+
11
+ [![GitHub Release](https://img.shields.io/github/v/release/JacobArthurs/pgplan)](https://github.com/JacobArthurs/pgplan/releases/latest)
12
+ [![npm](https://img.shields.io/npm/v/pgplan)](https://www.npmjs.com/package/pgplan)
13
+ [![PyPI](https://img.shields.io/pypi/v/pgplan)](https://pypi.org/project/pgplan/)
14
+ [![Go Reference](https://pkg.go.dev/badge/github.com/jacobarthurs/pgplan.svg)](https://pkg.go.dev/github.com/jacobarthurs/pgplan)
15
+ [![Go Report Card](https://goreportcard.com/badge/github.com/jacobarthurs/pgplan)](https://goreportcard.com/report/github.com/jacobarthurs/pgplan)
16
+ [![ci](https://img.shields.io/github/actions/workflow/status/JacobArthurs/pgplan/ci.yml?branch=main)](https://github.com/JacobArthurs/pgplan/actions/workflows/ci.yml)
17
+ [![go version](https://img.shields.io/github/go-mod/go-version/JacobArthurs/pgplan)](./go.mod)
18
+ [![License](https://img.shields.io/github/license/JacobArthurs/pgplan)](LICENSE)
19
+
20
+ A command-line tool for analyzing and comparing PostgreSQL query execution plans. Get optimization insights and track performance regressions without leaving your terminal.
21
+
22
+ ## Features
23
+
24
+ - **Plan Analysis** - Run 15+ intelligent rules against a query plan to surface performance issues with actionable fix suggestions
25
+ - **Plan Comparison** - Semantically diff two plans side-by-side to understand what changed and whether it got better or worse
26
+ - **Flexible Input** - Accept JSON EXPLAIN output, raw SQL files, stdin, or paste plans interactively
27
+ - **Connection Profiles** - Save and manage named PostgreSQL connection strings for quick reuse
28
+ - **Multiple Output Formats** - Human-readable colored terminal output or structured JSON for tooling integration
29
+
30
+ ## Installation
31
+
32
+ ### [PyPI](https://pypi.org/project/pgplan/)
33
+
34
+ ```bash
35
+ pip install pgplan
36
+ ```
37
+
38
+ ### [npm](https://www.npmjs.com/package/pgplan)
39
+
40
+ ```bash
41
+ npm i -g pgplan
42
+ ```
43
+
44
+ ### [Go](https://pkg.go.dev/github.com/jacobarthurs/pgplan)
45
+
46
+ ```bash
47
+ go install github.com/jacobarthurs/pgplan@latest
48
+ ```
49
+
50
+ ### Binary
51
+
52
+ Download the latest release for your platform from the [releases page](https://github.com/JacobArthurs/pgplan/releases/latest).
53
+
54
+ ## Quick Start
55
+
56
+ ```bash
57
+ # Analyze a query plan from a JSON EXPLAIN output
58
+ pgplan analyze plan.json
59
+
60
+ # Analyze by running a SQL file against a database
61
+ pgplan analyze query.sql --db postgres://localhost:5432/mydb
62
+
63
+ # Compare two plans
64
+ pgplan compare before.json after.json
65
+
66
+ # Interactive mode - paste plans or queries directly into the terminal
67
+ pgplan analyze
68
+ pgplan compare
69
+ ```
70
+
71
+ ## Commands
72
+
73
+ ### `pgplan analyze [file]`
74
+
75
+ Analyzes a single query plan and returns optimization findings sorted by severity.
76
+
77
+ **Arguments:**
78
+
79
+ | Argument | Description |
80
+ | -------- | ----------- |
81
+ | `file` | Path to a `.json` (EXPLAIN output) or `.sql` file. Use `-` for stdin. Omit for interactive mode. |
82
+
83
+ **Flags:**
84
+
85
+ | Flag | Description |
86
+ | ---- | ----------- |
87
+ | `-d, --db` | PostgreSQL connection string (required for SQL input) |
88
+ | `-p, --profile` | Named connection profile to use |
89
+ | `-f, --format` | Output format: `text` (default) or `json` |
90
+
91
+ **Example:**
92
+
93
+ ```bash
94
+ pgplan analyze slow-query.sql --profile prod
95
+ ```
96
+
97
+ ### `pgplan compare [file1] [file2]`
98
+
99
+ Compares two query plans and reports on cost, time, row estimate, and buffer differences across every node in the plan tree.
100
+
101
+ **Arguments:**
102
+
103
+ | Argument | Description |
104
+ | -------- | ----------- |
105
+ | `file1` | The "before" plan. `.json`, `.sql`, `-` for stdin, or omit for interactive. |
106
+ | `file2` | The "after" plan. Same input options as `file1`. |
107
+
108
+ **Flags:**
109
+
110
+ | Flag | Description |
111
+ | ---- | ----------- |
112
+ | `-d, --db` | PostgreSQL connection string (required for SQL input) |
113
+ | `-p, --profile` | Named connection profile to use |
114
+ | `-f, --format` | Output format: `text` (default) or `json` |
115
+ | `-t, --threshold` | Percent change threshold for significance (default: `5`) |
116
+
117
+ **Example:**
118
+
119
+ ```bash
120
+ pgplan compare before.json after.json --threshold 10
121
+ ```
122
+
123
+ ### `pgplan profile <subcommand>`
124
+
125
+ Manages saved PostgreSQL connection profiles stored in `~/.config/pgplan/profiles.yaml`.
126
+
127
+ | Subcommand | Description |
128
+ | ---------- | ----------- |
129
+ | `list [--show]` | List saved profiles. Pass `--show` to display connection strings. |
130
+ | `add <name> <conn_str>` | Add or update a named profile. |
131
+ | `remove <name>` | Remove a profile. |
132
+ | `default <name>` | Set a profile as the default. |
133
+ | `clear-default` | Clear the default profile. |
134
+
135
+ **Example:**
136
+
137
+ ```bash
138
+ pgplan profile add prod postgres://user:pass@host:5432/mydb
139
+ pgplan profile default prod
140
+
141
+ # Now use it with analyze or compare
142
+ pgplan analyze query.sql --profile prod
143
+ ```
144
+
145
+ ## Analysis Rules
146
+
147
+ The `analyze` command applies the following rules to identify performance issues. Each finding includes a severity level and an actionable suggestion.
148
+
149
+ | Severity | Rule | Description |
150
+ | -------- | ---- | ----------- |
151
+ | Critical | Sort Spill to Disk | Sort operation exceeded `work_mem` and spilled to disk |
152
+ | Warning | Hash Spill to Disk | Hash table exceeded `work_mem` |
153
+ | Warning | Temp Block I/O | Plan is reading/writing temporary blocks |
154
+ | Warning | Seq Scan in Join | Sequential scan used inside a join against a smaller set |
155
+ | Warning | Seq Scan with Filter | Standalone sequential scan filtering a large number of rows |
156
+ | Warning | Index Scan Filter Inefficiency | Index scan is fetching many rows then discarding most via filter |
157
+ | Warning | Bitmap Heap Recheck | Lossy bitmap scan rechecking conditions (bitmap exceeded `work_mem`) |
158
+ | Warning | Nested Loop High Loops | Nested loop executing 1,000+ iterations |
159
+ | Warning | Correlated Subplan | Subplan re-executing on every outer row |
160
+ | Warning | Worker Launch Mismatch | Fewer parallel workers launched than planned |
161
+ | Warning | Parallel Overhead | Parallel execution is slower than the serial estimate |
162
+ | Warning | Large Join Filter Removal | Join filter is discarding a large percentage of rows |
163
+ | Warning | Excessive Materialization | Materialize node looping many times |
164
+ | Info | Low Selectivity Index Scan | Index scan is returning most of the table |
165
+ | Info | Wide Row Output | Query is selecting more columns than necessary |
166
+
167
+ ## Comparison Output
168
+
169
+ The `compare` command produces a structured diff of two plans including:
170
+
171
+ - **Summary** - Overall cost, execution time, and buffer changes with directional indicators
172
+ - **Node Details** - Per-node breakdown of metric changes (cost, rows, loops, buffers, filters, indexes)
173
+ - **Verdict** - A final assessment such as "faster and cheaper" or "slower but cheaper"
174
+
175
+ Changes below the significance threshold (default 5%) are filtered out to reduce noise.
176
+
177
+ ## Output Formats
178
+
179
+ ### Text (default)
180
+
181
+ Colored terminal output with severity-coded findings and directional change indicators. Designed for quick human review.
182
+
183
+ ### JSON
184
+
185
+ Structured output suitable for piping into other tools, CI systems, or dashboards. Includes all metrics, findings, and comparison deltas.
186
+
187
+ ```bash
188
+ pgplan analyze plan.json --format json | jq '.findings[] | select(.severity == "critical")'
189
+ ```
190
+
191
+ ## Configuration
192
+
193
+ ### Connection Profiles
194
+
195
+ Profiles are stored in a YAML configuration file at the platform-appropriate config directory:
196
+
197
+ - **Linux/macOS:** `~/.config/pgplan/profiles.yaml`
198
+ - **Windows:** `%APPDATA%\pgplan\profiles.yaml`
199
+
200
+ ```yaml
201
+ default: prod
202
+ profiles:
203
+ - name: prod
204
+ conn_str: postgres://user:pass@host:5432/production
205
+ - name: dev
206
+ conn_str: postgres://localhost:5432/development
207
+ ```
208
+
209
+ Use `--profile <name>` with any command, or set a default to skip the flag entirely. The `--db` and `--profile` flags are mutually exclusive.
210
+
211
+ ## Contributing
212
+
213
+ Contributions are welcome! To get started:
214
+
215
+ 1. Fork the repository
216
+ 2. Create a feature branch (`git checkout -b my-new-feature`)
217
+ 3. Open a pull request
218
+
219
+ CI will automatically run tests and linting on your PR.
220
+
221
+ ## License
222
+
223
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,6 @@
1
+ pgplan/bin/pgplan.exe,sha256=QKT0NeFTKc_Y1xLKNacjyb4wAyLqKEkGBpzOGfXz854,9394176
2
+ pgplan/__init__.py,sha256=GFDoiKU9fjDQcmbGWpxHbIIM9Bc6D-5lAdy-CMnCqpI,712
3
+ pgplan-1.1.0.dist-info/METADATA,sha256=_J8IP2dBz0nOCCkpOwcQGmbYEvo4bGVPyyd2LkOempE,8048
4
+ pgplan-1.1.0.dist-info/WHEEL,sha256=OsDn4BwVQRqAYlkD4BRAwYu7ioSBwMUxlMrzFOFxtPE,85
5
+ pgplan-1.1.0.dist-info/entry_points.txt,sha256=hKygqUiFPCN_114UF-ft_L1vYpXV2VBBhEZrHCziK0Q,39
6
+ pgplan-1.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: shipbin
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_arm64
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pgplan = pgplan:main