pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Syntax-highlight and maybe realign EXPLAIN output?

Open d33tah opened this issue 9 years ago • 6 comments

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?

d33tah avatar Nov 18 '15 10:11 d33tah

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.

amjith avatar Nov 18 '15 11:11 amjith

http://explain.depesz.com/history does something similar.

cbandy avatar Feb 06 '16 14:02 cbandy

And pev: http://tatiyants.com/pev/

d33tah avatar Feb 06 '16 14:02 d33tah

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. :)

amjith avatar Feb 07 '16 15:02 amjith

I just put it there as something related. Having what explain.depesz.com has would already be tremendous.

d33tah avatar Feb 07 '16 18:02 d33tah

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.

deather avatar Feb 15 '21 16:02 deather