pgplan 0.0.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.
package/DESIGN.md ADDED
@@ -0,0 +1,169 @@
1
+ # pgplan design
2
+
3
+ ## Project Goals
4
+
5
+ - Compare PostgreSQL EXPLAIN plans with semantic understanding
6
+ - Provide CLI-native analysis without browser dependency
7
+ - Support multiple input formats (SQL, JSON, TEXT)
8
+ - Offer actionable optimization recommendations
9
+
10
+ ## Commands
11
+
12
+ ```text
13
+ pgplan compare [file1] [file2] [OPTIONS] Compare two query plans
14
+ pgplan analyze [file] [OPTIONS] Analyze a single query plan
15
+ pgplan init Create ~/.config/pgplan/config.yml with example template
16
+ pgplan --help Show help
17
+ pgplan --version Show version
18
+ ```
19
+
20
+ ## pgplan compare [file1] [file2] [OPTIONS]
21
+
22
+ ### Compare Files
23
+
24
+ - `file1` and `file2` are optional
25
+ - Can be SQL files, JSON files (EXPLAIN output), or TEXT files (EXPLAIN output)
26
+ - Either file (but not both) can be `-` to read from stdin
27
+ - Files don't need to be the same type
28
+ - If no files provided, enters interactive mode
29
+
30
+ ### Compare Options
31
+
32
+ | Flag | Description |
33
+ | ------------------- | --------------------------------------- |
34
+ | `--db <connection>` | PostgreSQL connection string |
35
+ | `--profile <name>` | Use named profile from config |
36
+ | `--format <type>` | Output format: `text` (default), `json` |
37
+
38
+ ### Compare Connection Resolution (only needed for SQL input)
39
+
40
+ 1. If `--db` flag provided, use it
41
+ 2. Else if `--profile` flag provided, load from config.yml
42
+ 3. Else if config.yml exists with `default_profile`, use default
43
+ 4. Else, error with helpful message
44
+
45
+ ### Compare Behavior
46
+
47
+ Process each input independently:
48
+
49
+ - SQL: requires DB connection, wraps query in `EXPLAIN (ANALYZE, FORMAT JSON)` and captures output
50
+ - JSON: parse directly
51
+ - EXPLAIN TEXT: parse directly
52
+
53
+ Then compare the two resulting plans.
54
+
55
+ ### Compare Examples
56
+
57
+ ```bash
58
+ # Interactive mode (no files)
59
+ pgplan compare
60
+
61
+ # From files (any combination)
62
+ pgplan compare old.sql new.sql --db postgres://localhost/mydb
63
+ pgplan compare prod-plan.json new-query.sql --profile dev
64
+
65
+ # Read one plan from stdin
66
+ psql -c "EXPLAIN (ANALYZE, FORMAT JSON) SELECT ..." | pgplan compare - new.sql --db postgres://localhost/mydb
67
+ pgplan compare old-plan.json - < new-plan.json
68
+
69
+ # Using default profile
70
+ pgplan compare old.sql new.sql
71
+ ```
72
+
73
+ ## pgplan analyze [file] [OPTIONS]
74
+
75
+ ### Analyze File
76
+
77
+ - `file` is optional
78
+ - Can be a SQL file, JSON file (EXPLAIN output), or TEXT file (EXPLAIN output)
79
+ - Use `-` for stdin
80
+ - If no file provided, enters interactive mode
81
+
82
+ ### Analyze Options
83
+
84
+ | Flag | Description |
85
+ | ------------------- | --------------------------------------- |
86
+ | `--db <connection>` | PostgreSQL connection string |
87
+ | `--profile <name>` | Use named profile from config |
88
+ | `--format <type>` | Output format: `text` (default), `json` |
89
+
90
+ ### Analyze Connection Resolution (only needed for SQL input)
91
+
92
+ Same as `pgplan compare`.
93
+
94
+ ### Analyze Behavior
95
+
96
+ Process input:
97
+
98
+ - SQL: requires DB connection, wraps query in `EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)` and captures output
99
+ - JSON: parse directly
100
+ - EXPLAIN TEXT: parse directly
101
+
102
+ Then analyze the plan and provide insights:
103
+
104
+ - Execution summary (time, cost, rows)
105
+ - Detected issues (seq scans, high filter ratios, missing indexes)
106
+ - Node-by-node breakdown
107
+ - Recommendations for optimization
108
+
109
+ ### Analyze Interactive Mode
110
+
111
+ If no file provided:
112
+
113
+ ```text
114
+ pgplan analyze
115
+
116
+ → Paste or type query or query plan (Ctrl+D or Ctrl+Z when done):
117
+ [user pastes content]
118
+ ^D
119
+
120
+ → Auto-detect input type
121
+ → If SQL, resolve DB connection
122
+ → Analyze plan
123
+ ```
124
+
125
+ ### Analyze Examples
126
+
127
+ ```bash
128
+ # Interactive mode
129
+ pgplan analyze
130
+
131
+ # Analyze SQL file
132
+ pgplan analyze slow-query.sql --db postgres://localhost/mydb
133
+
134
+ # Analyze saved EXPLAIN output
135
+ pgplan analyze prod-slow-plan.json
136
+
137
+ # Analyze from stdin
138
+ pgplan analyze -
139
+
140
+ # Pipe from psql
141
+ psql -c "EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) SELECT ..." | pgplan analyze -
142
+
143
+ # Using profile
144
+ pgplan analyze query.sql --profile prod
145
+
146
+ # JSON output for scripting
147
+ pgplan analyze query.sql --db postgres://localhost/mydb --format json
148
+ ```
149
+
150
+ ## Config File (optional)
151
+
152
+ Location: `~/.config/pgplan/config.yml`
153
+
154
+ ```yaml
155
+ profiles:
156
+ dev:
157
+ host: localhost
158
+ database: myapp_dev
159
+ user: postgres
160
+ password: dev_pass
161
+
162
+ prod:
163
+ host: prod.example.com
164
+ database: myapp_prod
165
+ user: readonly
166
+ password: prod_pass
167
+
168
+ default_profile: dev
169
+ ```
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jacob Arthurs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # pgplan
2
+
3
+ > ⚠️ **Early Development** - Not ready for production use
4
+
5
+ Compare and analyze PostgreSQL EXPLAIN plans from the CLI.
6
+
7
+ ## Why?
8
+
9
+ Understand query performance regressions and get optimization insights without leaving your terminal.
10
+
11
+ ## Planned Features
12
+
13
+ - [ ] EXPLAIN plan parsing (JSON, TEXT formats)
14
+ - [ ] Intelligent plan comparison with semantic diff
15
+ - [ ] Single plan analysis with recommendations
16
+ - [ ] Interactive mode (paste plans directly)
17
+ - [ ] Connection profiles for multiple databases
18
+ - [ ] Web interface
19
+
20
+ ## Installation
21
+
22
+ Not yet published. Clone and run locally:
23
+
24
+ ```bash
25
+ git clone https://github.com/JacobArthurs/pgplan
26
+ cd pgplan
27
+ ```
28
+
29
+ ## Usage (Planned)
30
+
31
+ ```bash
32
+ # Compare two query plans
33
+ pgplan compare old.sql new.sql --db postgres://localhost/mydb
34
+
35
+ # Analyze a single query
36
+ pgplan analyze slow-query.sql --profile prod
37
+
38
+ # Interactive mode
39
+ pgplan compare
40
+ # Paste Plan A, then Plan B
41
+ ```
42
+
43
+ ## Development
44
+
45
+ Contributions welcome! This is an early-stage project.
46
+
47
+ MIT License
package/cmd/analyze.go ADDED
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright © 2026 JACOB ARTHURS
3
+ */
4
+ package cmd
5
+
6
+ import (
7
+ "fmt"
8
+
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ // analyzeCmd represents the analyze command
13
+ var analyzeCmd = &cobra.Command{
14
+ Use: "analyze",
15
+ Short: "A brief description of your command",
16
+ Long: `A longer description that spans multiple lines and likely contains examples
17
+ and usage of using your command. For example:
18
+
19
+ Cobra is a CLI library for Go that empowers applications.
20
+ This application is a tool to generate the needed files
21
+ to quickly create a Cobra application.`,
22
+ Run: func(cmd *cobra.Command, args []string) {
23
+ fmt.Println("analyze called")
24
+ },
25
+ }
26
+
27
+ func init() {
28
+ rootCmd.AddCommand(analyzeCmd)
29
+
30
+ // Here you will define your flags and configuration settings.
31
+
32
+ // Cobra supports Persistent Flags which will work for this command
33
+ // and all subcommands, e.g.:
34
+ // analyzeCmd.PersistentFlags().String("foo", "", "A help for foo")
35
+
36
+ // Cobra supports local flags which will only run when this command
37
+ // is called directly, e.g.:
38
+ // analyzeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
39
+ }
package/cmd/compare.go ADDED
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright © 2026 JACOB ARTHURS
3
+ */
4
+ package cmd
5
+
6
+ import (
7
+ "fmt"
8
+
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ // compareCmd represents the compare command
13
+ var compareCmd = &cobra.Command{
14
+ Use: "compare",
15
+ Short: "A brief description of your command",
16
+ Long: `A longer description that spans multiple lines and likely contains examples
17
+ and usage of using your command. For example:
18
+
19
+ Cobra is a CLI library for Go that empowers applications.
20
+ This application is a tool to generate the needed files
21
+ to quickly create a Cobra application.`,
22
+ Run: func(cmd *cobra.Command, args []string) {
23
+ fmt.Println("compare called")
24
+ },
25
+ }
26
+
27
+ func init() {
28
+ rootCmd.AddCommand(compareCmd)
29
+
30
+ // Here you will define your flags and configuration settings.
31
+
32
+ // Cobra supports Persistent Flags which will work for this command
33
+ // and all subcommands, e.g.:
34
+ // compareCmd.PersistentFlags().String("foo", "", "A help for foo")
35
+
36
+ // Cobra supports local flags which will only run when this command
37
+ // is called directly, e.g.:
38
+ // compareCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
39
+ }
package/cmd/init.go ADDED
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright © 2026 JACOB ARTHURS
3
+ */
4
+ package cmd
5
+
6
+ import (
7
+ "fmt"
8
+
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ // initCmd represents the init command
13
+ var initCmd = &cobra.Command{
14
+ Use: "init",
15
+ Short: "A brief description of your command",
16
+ Long: `A longer description that spans multiple lines and likely contains examples
17
+ and usage of using your command. For example:
18
+
19
+ Cobra is a CLI library for Go that empowers applications.
20
+ This application is a tool to generate the needed files
21
+ to quickly create a Cobra application.`,
22
+ Run: func(cmd *cobra.Command, args []string) {
23
+ fmt.Println("init called")
24
+ },
25
+ }
26
+
27
+ func init() {
28
+ rootCmd.AddCommand(initCmd)
29
+
30
+ // Here you will define your flags and configuration settings.
31
+
32
+ // Cobra supports Persistent Flags which will work for this command
33
+ // and all subcommands, e.g.:
34
+ // initCmd.PersistentFlags().String("foo", "", "A help for foo")
35
+
36
+ // Cobra supports local flags which will only run when this command
37
+ // is called directly, e.g.:
38
+ // initCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
39
+ }
package/cmd/root.go ADDED
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright © 2026 JACOB ARTHURS
3
+ */
4
+ package cmd
5
+
6
+ import (
7
+ "os"
8
+
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ // rootCmd represents the base command when called without any subcommands
13
+ var rootCmd = &cobra.Command{
14
+ Use: "pgplan",
15
+ Short: "A brief description of your application",
16
+ Long: `A longer description that spans multiple lines and likely contains
17
+ examples and usage of using your application. For example:
18
+
19
+ Cobra is a CLI library for Go that empowers applications.
20
+ This application is a tool to generate the needed files
21
+ to quickly create a Cobra application.`,
22
+ // Uncomment the following line if your bare application
23
+ // has an action associated with it:
24
+ // Run: func(cmd *cobra.Command, args []string) { },
25
+ }
26
+
27
+ // Execute adds all child commands to the root command and sets flags appropriately.
28
+ // This is called by main.main(). It only needs to happen once to the rootCmd.
29
+ func Execute() {
30
+ err := rootCmd.Execute()
31
+ if err != nil {
32
+ os.Exit(1)
33
+ }
34
+ }
35
+
36
+ func init() {
37
+ // Here you will define your flags and configuration settings.
38
+ // Cobra supports persistent flags, which, if defined here,
39
+ // will be global for your application.
40
+
41
+ // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.pgplan.yaml)")
42
+
43
+ // Cobra also supports local flags, which will only run
44
+ // when this action is called directly.
45
+ rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
46
+ }
package/go.mod ADDED
@@ -0,0 +1,9 @@
1
+ module pgplan
2
+
3
+ go 1.25.6
4
+
5
+ require (
6
+ github.com/inconshreveable/mousetrap v1.1.0 // indirect
7
+ github.com/spf13/cobra v1.10.2
8
+ github.com/spf13/pflag v1.0.10 // indirect
9
+ )
package/go.sum ADDED
@@ -0,0 +1,11 @@
1
+ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2
+ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3
+ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4
+ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5
+ github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
6
+ github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
7
+ github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
8
+ github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
9
+ github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
10
+ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
11
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
package/main.go ADDED
@@ -0,0 +1,10 @@
1
+ /*
2
+ Copyright © 2026 JACOB ARTHURS
3
+ */
4
+ package main
5
+
6
+ import "pgplan/cmd"
7
+
8
+ func main() {
9
+ cmd.Execute()
10
+ }
package/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "pgplan",
3
+ "version": "0.0.1",
4
+ "description": "Compare and analyze PostgreSQL EXPLAIN plans from the CLI",
5
+ "private": false
6
+ }