{"id":18413007,"url":"https://github.com/querysorcery/pyev","last_synced_at":"2025-04-12T23:48:08.137Z","repository":{"id":68616491,"uuid":"393763189","full_name":"QuerySorcery/pyev","owner":"QuerySorcery","description":"postgres python explain visualizer","archived":false,"fork":false,"pushed_at":"2021-08-08T09:00:03.000Z","size":127,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T23:48:08.009Z","etag":null,"topics":["hacktoberfest","python","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/QuerySorcery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-07T18:34:29.000Z","updated_at":"2023-11-04T17:40:32.000Z","dependencies_parsed_at":"2023-04-09T00:06:15.358Z","dependency_job_id":null,"html_url":"https://github.com/QuerySorcery/pyev","commit_stats":null,"previous_names":["querysorcery/pyev"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuerySorcery%2Fpyev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuerySorcery%2Fpyev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuerySorcery%2Fpyev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuerySorcery%2Fpyev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QuerySorcery","download_url":"https://codeload.github.com/QuerySorcery/pyev/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","python","sql"],"created_at":"2024-11-06T03:44:31.244Z","updated_at":"2025-04-12T23:48:08.094Z","avatar_url":"https://github.com/QuerySorcery.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a port of [gocmdpev](https://github.com/simon-engledew/gocmdpev) \n\n# Usage:\n \nPrefix your query with `EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON)`\n\nWhen executed it will return a json string that can be passed to the visualizer\n\nThe visualiser takes 2 params:\n\n* terminal_width = default 100\n* color_mode_on = default True\n\n```\nfrom pyev import Visualizer\nfor explain in parsed_json:\n    v = Visualizer(160, True)\n    v.load(explain)\n    v.print()\n```\n\nto read json from a file use\n```\nfrom pyev import Visualizer\nimport json\n\ndef visualize():\n    with open(\"query_plan_full.json\") as json_file:\n        explains = json.load(json_file)\n        for explain in explains:\n            v = Visualizer()\n            v.load(explain)\n            v.print()\nvisualize()\n```\n\nexample output:\n```\n\n○ Total Cost: 808\n○ Planning Time: 25.86 ms\n○ Execution Time: 1.86 s\n┬\n│\n└─⌠ Unique \n  │ Not found : Unique\n  │ ○ Duration: \u003c1 ms (0%)\n  │ ○ Cost: 0 (0%)\n  │ ○ Rows: 1\n  ├►  customers.number\n  │\n  └─⌠ Sort \n    │ Sorts a record set based on the specified sort key.\n    │ ○ Duration: \u003c1 ms (0%)\n    │ ○ Cost: 0 (0%)\n    │ ○ Rows: 1\n    ├►  customers.number\n    │\n    └─⌠ Nested Loop \n      │ Merges two record sets by looping through every record in the first set and trying\n      │ to find a match in the second set. All matching records are returned.\n      │ ○ Duration: 730.10 ms (20%)\n      │ ○ Cost: 0 (0%)\n      │ ○ Rows: 1\n      │   Inner join\n      ├►  customers.number\n      │\n      ├─⌠ Nested Loop bad estimate\n      │ │ Merges two record sets by looping through every record in the first set and\n      │ │ trying to find a match in the second set. All matching records are returned.\n      │ │ ○ Duration: 0.69 s (37%)\n      │ │ ○ Cost: 48 (6%)\n      │ │ ○ Rows: 785\n      │ │   Inner join\n      │ │   rows Underestimated by 785.00x\n      │ ├►  customers.number + customers.id + customers.blocked +\n      │ │  customers.accepts_marketing_notifications + m3.id\n      │ │\n      │ ├─⌠ Nested Loop bad estimate\n      │ │ │ Merges two record sets by looping through every record in the first set and\n      │ │ │ trying to find a match in the second set. All matching records are returned.\n      │ │ │ ○ Duration: 3.74 ms (0%)\n      │ │ │ ○ Cost: 7 (1%)\n      │ │ │ ○ Rows: 760\n      │ │ │   Inner join\n      │ │ │   rows Underestimated by 108.57x\n      │ │ ├►  m2.recipient_phone + (unnest('{12345000000}'::text[])) + m3.id\n      │ │ │\n      │ │ ├─⌠ Nested Loop \n      │ │ │ │ Merges two record sets by looping through every record in the first set and\n      │ │ │ │ trying to find a match in the second set. All matching records are returned.\n      │ │ │ │ ○ Duration: 0.80 s (43%)\n      │ │ │ │ ○ Cost: 808 (100%)\n      │ │ │ │ ○ Rows: 760\n      │ │ │ │   Inner join\n      │ │ │ │   rows Underestimated by 19.00x\n      │ │ │ ├►  m2.recipient_phone + m2.marketing_campaign_settings_id +\n      │ │ │ │  (unnest('{12345000000}'::text[]))\n      │ │ │ │\n      │ │ │ ├─⌠ Aggregate [Hashed] largest\n      │ │ │ │ │ Groups records together based on a GROUP BY or aggregate function (e.g.\n      │ │ │ │ │ sum()).\n      │ │ │ │ │ ○ Duration: 1.11 ms (0%)\n      │ │ │ │ │ ○ Cost: 4 (1%)\n      │ │ │ │ │ ○ Rows: 1,000\n      │ │ │ │ │   rows Overestimated by 0.20x\n      │ │ │ │ ├►  (unnest('{12345000000}'::text[]))\n      │ │ │ │ │\n      │ │ │ │ └─⌠ ProjectSet largest\n      │ │ │ │   │ ProjectSet appears when the SELECT or ORDER BY clause of the query.\n      │ │ │ │   │ They basically just execute the set-returning function(s) for each tuple\n      │ │ │ │   │ until none of the functions return any more records.\n      │ │ │ │   │ ○ Duration: \u003c1 ms (0%)\n      │ │ │ │   │ ○ Cost: 1 (0%)\n      │ │ │ │   │ ○ Rows: 1,000\n      │ │ │ │   ├►  unnest('{12345000000}'::text[])\n      │ │ │ │   │\n      │ │ │ │   └─⌠ Result \n      │ │ │ │     │ Returns result\n      │ │ │ │     │ ○ Duration: \u003c1 ms (0%)\n      │ │ │ │     │ ○ Cost: 0 (0%)\n      │ │ │ │     │ ○ Rows: 1\n      │ │ │ │\n      │ │ │ └─⌠ Index Scan [Forward] slowest\n      │ │ │   │ Finds relevant records based on an Index. Index Scans perform 2 read\n      │ │ │   │ operations: one to read the index and another to read the actual value\n      │ │ │   │ from the table.\n      │ │ │   │ ○ Duration: 0.80 s (43%)\n      │ │ │   │ ○ Cost: 4 (1%)\n      │ │ │   │ ○ Rows: 1\n      │ │ │   │   on public.marketing_offers\n      │ │ │   │   using index_marketing_offers_id\n      │ │ │   │   filter (m2.created_at \u003e '2021-07-05 14:00:00'::timestamp without time zone) [-1 rows]\n      │ │ │   ⌡► m2.recipient_phone + m2.marketing_campaign_settings_id\n      │ │ │\n      │ │ └─⌠ Index Scan [Forward] \n      │ │   │ Finds relevant records based on an Index. Index Scans perform 2 read\n      │ │   │ operations: one to read the index and another to read the actual value from\n      │ │   │ the table.\n      │ │   │ ○ Duration: 3.04 ms (0%)\n      │ │   │ ○ Cost: 0 (0%)\n      │ │   │ ○ Rows: 1\n      │ │   │   on public.marketing_campaign_settings\n      │ │   │   using marketing_campaign_settings_pkey\n      │ │   │   filter (m3.campaign_category = 4) [-0 rows]\n      │ │   ⌡► m3.id + m3.provider_id + m3.marketing_campaign_id + m3.campaign_category +\n      │ │      m3.current + m3.value + m3.discount_type + m3.\"limit\" + m3.valid_for +\n      │ │      m3.created_at + m3.updated_at + m3.all_services + m3.discount_id\n      │ │\n      │ └─⌠ Index Scan [Forward] \n      │   │ Finds relevant records based on an Index. Index Scans perform 2 read\n      │   │ operations: one to read the index and another to read the actual value from\n      │   │ the table.\n      │   │ ○ Duration: 0.69 s (37%)\n      │   │ ○ Cost: 8 (1%)\n      │   │ ○ Rows: 1\n      │   │   on public.customers\n      │   │   using index_customers_on_number\n      │   │   filter ((customers.deleted_at IS NULL) AND (customers.provider_id = 12345)) [-2 rows]\n      │   ⌡► customers.number + customers.id + customers.blocked +\n      │      customers.accepts_notifications\n      │\n      └─⌠ Index Scan [Forward] costliest\n        │ Finds relevant records based on an Index. Index Scans perform 2 read operations:\n        │ one to read the index and another to read the actual value from the table.\n        │ ○ Duration: 730.05 ms (20%)\n        │ ○ Cost: 2 (0%)\n        │ ○ Rows: 0\n        │   on public.customer_payments\n        │   using index_customer_payments_id\n        │   filter (c1.unpaid_amount \u003e '0'::numeric) [-1 rows]\n        ⌡► c1.id + c1.customer_id + c1.provider_id + c1.unpaid_amount + c1.created_at +\n           c1.updated_at\n```\n![example](pyev.png \"color\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquerysorcery%2Fpyev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquerysorcery%2Fpyev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquerysorcery%2Fpyev/lists"}