dbcli / pgcli

Postgres CLI with autocompletion and syntax highlighting
http://pgcli.com
BSD 3-Clause "New" or "Revised" License
12.07k stars 557 forks source link

Syntax-highlight and maybe realign EXPLAIN output? #416

Open d33tah opened 8 years ago

d33tah commented 8 years ago

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?

amjith commented 8 years ago

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.

cbandy commented 8 years ago

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

d33tah commented 8 years ago

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

amjith commented 8 years ago

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

d33tah commented 8 years ago

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

deather commented 3 years ago

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.