Skip to main content

PostgreSQL EXPLAIN Plan Analyzer - Extract insights from execution plans

Project description

plananalyze

PostgreSQL EXPLAIN Plan Analyzer - Extract insights from execution plans Query

For best results, run EXPLAIN like so EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS)

``

Quickstart

  1. Run "ANALYZE" on your Query
  2. Copy-paste output from PostgreSQL
  3. Review details :)
from plananalyze import analyze_plan

plan = """
Hash Join  (cost=12.70..30.50 rows=120 width=743)
  Hash Cond: ((d.name)::text = (employees.department)::text)
  ->  Seq Scan on departments d  (cost=0.00..14.80 rows=480 width=142)
  ->  Hash  (cost=11.20..11.20 rows=120 width=601)
        ->  Seq Scan on employees  (cost=0.00..11.20 rows=120 width=601)
"""

result = analyze_plan(plan, format_type="summary")
print(result)

Output:

📊 EXECUTION OVERVIEW:
   Total Cost: 30.50
   Node Count: 5

🔍 OPERATIONS:
   Sequential Scans: 2
   Index Scans: 0
   Joins: 1
   Sorts: 0

Detailed Response

# Use format_type="detailed"
result = analyze_plan(plan, format_type="detailed")

Output:

📈 EXECUTION METRICS:
   Total Cost: 30.50
   Root Operation: Hash Join

🏗️  PLAN STRUCTURE:
   Total Nodes: 5
   Plan Depth: 0

🔍 OPERATION BREAKDOWN:
   Sequential Scans: 2
   Index Scans: 0
   Index Only Scans: 0
   Bitmap Scans: 0
   Join Operations: 1
   Sort Operations: 0
   Hash Operations: 2
   Aggregate Operations: 0

💰 MOST EXPENSIVE OPERATIONS:
   1. Hash Join - Cost: 30.50 (100.0%)
   2. ->  Seq Scan on departments - Cost: 14.80 (48.5%)
   3. ->  Hash - Cost: 11.20 (36.7%)

JSON output

# Use format_type="json"
result = analyze_plan(plan, format_type="json")

JSON Input

Run "explain" on PostgreSQL query using EXPLAIN (FORMAT JSON)

from plananalyze import analyze_plan

plan_json = """
[
  {
    "Plan": {
      "Node Type": "Hash Join",
      "Parallel Aware": false,
      "Async Capable": false,
      "Join Type": "Inner",
      "Startup Cost": 12.70,
      "Total Cost": 30.50,
      "Plan Rows": 120,
      "Plan Width": 743,
      "Inner Unique": false,
      "Hash Cond": "((d.name)::text = (employees.department)::text)",
      "Plans": [
        {
          "Node Type": "Seq Scan",
          "Parent Relationship": "Outer",
          "Parallel Aware": false,
          "Async Capable": false,
          "Relation Name": "departments",
          "Alias": "d",
          "Startup Cost": 0.00,
          "Total Cost": 14.80,
          "Plan Rows": 480,
          "Plan Width": 142
        },
        {
          "Node Type": "Hash",
          "Parent Relationship": "Inner",
          "Parallel Aware": false,
          "Async Capable": false,
          "Startup Cost": 11.20,
          "Total Cost": 11.20,
          "Plan Rows": 120,
          "Plan Width": 601,
          "Plans": [
            {
              "Node Type": "Seq Scan",
              "Parent Relationship": "Outer",
              "Parallel Aware": false,
              "Async Capable": false,
              "Relation Name": "employees",
              "Alias": "employees",
              "Startup Cost": 0.00,
              "Total Cost": 11.20,
              "Plan Rows": 120,
              "Plan Width": 601
            }
          ]
        }
      ]
    }
  }
]
"""

result = analyze_plan(plan_json, format_type="summary")
print(result)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plananalyze-0.1.0.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plananalyze-0.1.0-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file plananalyze-0.1.0.tar.gz.

File metadata

  • Download URL: plananalyze-0.1.0.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for plananalyze-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30ff96a8e32ee235fb67b472e52d0da330eba7563a3928bc3ae9bc35aecfcb1a
MD5 8aae27875652f9121f0c1c1b26b31310
BLAKE2b-256 5e4620ca447a39194473a73e07109c8d8acfdc9695bf0f84f130670628766f57

See more details on using hashes here.

File details

Details for the file plananalyze-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: plananalyze-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for plananalyze-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94ebb9be8599c163f50e8e21f91bfe1503d9e35ce46d1705110a3ab9d6f470be
MD5 b6ad6b5cd293276915f5eab5e728386d
BLAKE2b-256 7fc3bf1c6bde8e2d20a594e6512b3b823b6d58cfdb79ce42b4a8240fdd69a3fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page