Small improvement for pretty-printing in paste.depesz.com

As you maybe know, some time ago I made paste service, mostly to use for queries, or related text to share on IRC.

One part of it is that it also has pretty printer of provided queries.

Recently I realized that in case of complex join conditions, the output is, well, sub-optimal. For example:

SELECT
    t1.a,
    t2.b,
    t3.c
FROM
    table_1 AS t1
    JOIN table_2 AS t2 ON t1.x = t2.x AND
    t1.y = t2.y AND
    t1.z = t2.z
    LEFT JOIN table_3 AS t3 ON t1.f = t3.f AND
    t2.g = t3.g
WHERE
    t1.v = 1 AND
    t2.t = 'x' AND
    t3.m < 123

Specifically the problem (for me) is bad indentation of join conditions (aside from first).

Anyway – as of now, the same query will be pretty-printed as:

SELECT
    t1.a,
    t2.b,
    t3.c
FROM
    table_1 AS t1
    JOIN table_2 AS t2 ON t1.x = t2.x
        AND t1.y = t2.y
        AND t1.z = t2.z
    LEFT JOIN table_3 AS t3 ON t1.f = t3.f
        AND t2.g = t3.g
WHERE
    t1.v = 1
    AND t2.t = 'x'
    AND t3.m < 123

Also, as a reminder – you can use this pretty printer from command line or some tools, without storing anything on paste.depesz.com site – simply use script that I described earlier.

Hope you'll find it useful.

vtime – time commands with elapsed time visible all the time

Lately I've been running quite a lot of commands that take long time, and was wondering how long they took. Of course I can use the standard time program, but it doesn't show me how long it already took.

So, figured I can write it myself. Result:

vtime demo

You can download it, as always, from shell_utils git repo.

Hope you'll find it useful 🙂

explain.depesz.com – now with HINTS!

I just pushed change to explain.depesz.com that allows for processing and displaying hints for plans.

For example, take a look at this plan, and check if you'll notice subtle “HINTS" tab.

In there you will see example hints – one about sort and memory, and the other about missing index.

It is not much, but it's a step in (hopefully) right direction, when the explain tool will also provide, automatically, some ideas on what to do to make the thing faster.

Hope you'll find it useful.

Wait for program(s) in tmux panes to end…

I am doing quite a lot of work inside tmux. I especially love that I can start multiple windows/panes and use them to run the same thing across multiple servers, while still having normal shell access between steps.

This thing was greatly improved when I wrote tmux_send_to_many, but one thing was missing – waiting for the thing, running in tmux window to end.

Generally, I had to look at all the windows, and decide when to launch next step on my own.

Not anymore.

Continue reading Wait for program(s) in tmux panes to end…

visual sleep in shell, and shell_utils repo information

I wrote previously about tmux_send_to_many and group_by shell tools that I authored.

Since then I got some more ideas for changes, and for new tool, so figured I'll make an honest git repo for it. Repo is on GitLab, and all the tools inside can be freely used.

While I was doing it, I fixed some things in tmux_send_to_many.

And then – I remembered that for long time I was missing “visual-sleep" type of tool. One that will show some progress information while it's working.

Enter vsleep.

Continue reading visual sleep in shell, and shell_utils repo information