summaryrefslogtreecommitdiffstats
path: root/pgcli/pgexecute.py
diff options
context:
space:
mode:
authorDaniel Kukula <904179+dkuku@users.noreply.github.com>2022-04-04 03:20:02 +0100
committerGitHub <noreply@github.com>2022-04-03 19:20:02 -0700
commit372da81ec4bb6572f293c00cdd5b3b4d3c38350d (patch)
treea8df0513433cae513b3f9823f53bf1ca21a097be /pgcli/pgexecute.py
parent366c01bbb97fee96a8169629854af7c83d626c99 (diff)
add explain visualizer (#1279)
* add explain visualizer * format files * remove humanize dependency * disable by default * add explain visualizer * run black
Diffstat (limited to 'pgcli/pgexecute.py')
-rw-r--r--pgcli/pgexecute.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py
index 48086301..b902c55e 100644
--- a/pgcli/pgexecute.py
+++ b/pgcli/pgexecute.py
@@ -411,7 +411,12 @@ class PGExecute:
)
def run(
- self, statement, pgspecial=None, exception_formatter=None, on_error_resume=False
+ self,
+ statement,
+ pgspecial=None,
+ exception_formatter=None,
+ on_error_resume=False,
+ explain_mode=False,
):
"""Execute the sql in the database and return the results.
@@ -442,7 +447,9 @@ class PGExecute:
if not sql:
continue
try:
- if pgspecial:
+ if explain_mode:
+ sql = self.explain_prefix() + sql
+ elif pgspecial:
# \G is treated specially since we have to set the expanded output.
if sql.endswith("\\G"):
if not pgspecial.expanded_output:
@@ -931,3 +938,6 @@ class PGExecute:
cur.execute(query)
for row in cur:
yield row[0]
+
+ def explain_prefix(self):
+ return "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) "