pgcli
pgcli copied to clipboard
Syntax-highlight and maybe realign EXPLAIN output?
Now that the indentation within EXPLAIN was fixed, perhaps it'd be a good idea to make it more readable than in original PostgreSQL? Color highlighting would imho be a good start - what should I start with if I want to experiment with this feature?
Another idea I have is to realign its output so that we'd have two columns and multiple rows instead of 1x1 text field. Rows would mean separate activities and their details (seq scan, hash join etc), columns would be for things like cost and ANALYZE results. What do you think?
Having two columns for the output of Explain is possible. Take a look at this function format_output()
https://github.com/dbcli/pgcli/blob/master/pgcli/main.py#L650.
We currently use this function to create the tabular output. The idea is quite simple.
If there are 2 columns then there will be a list with two items of headers
. The cur
variable is an iterable (list, tuple, generator etc) that has the values that correspond to each row. Think of it as a list of tuples like this [('a', 'b'), ('c', 'd')]. This means (a, b)
forms the first row where a
is in first column and b
is in second column, (c, d)
forms the second row and so on.
I'm not sure about the syntax coloring of output. We use pygments for syntax coloring, you're welcome to take a stab at it.
http://explain.depesz.com/history does something similar.
And pev: http://tatiyants.com/pev/
It's possible to do what explain.depesz.com is doing.
To do what pev is doing would require me to implement a tree drawing library for the terminal, I seriously doubt, I can pull that off. :)
I just put it there as something related. Having what explain.depesz.com has would already be tremendous.
Hi,
I don't know if this could help, but I found a repository where someone have written a pygments lexer for EXPLAIN ANALYZE
.
https://github.com/maahl/pg_explain_lexer/
I have no idea if it is easily pluggable with pgcli
, I give the informations just in case.