Re: pg_background contrib module proposal

From: Andrew Borodin <borodin(at)octonica(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, amul sul <sulamul(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_background contrib module proposal
Date: 2016-12-21 06:26:57
Message-ID: CAJEAwVEpKtTeR6oG=8=Lvbb6BVqoepMK5iH=9iuM6sEB-YCnFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2016-12-21 4:55 GMT+05:00 David Fetter <david(at)fetter(dot)org>:
> I see.
>
> I find the following a little easier to follow, and the sleeps still
> work even when very short.

Now I know a little more SQL :) Thank you.

I'm not sure every platform supports microsecond sleeps. But it will
work anyway. This test is deterministic.
Without sequence here is no race condition. So it is not sleepsort, it
is deterministic. Though I agree that it is good thing for test, I'd
still add some miliseconds to test case when main query for sure have
to wait end of other sleeping query.
.
>
> CREATE TABLE input AS
> SELECT x, row_number() OVER (ORDER BY x) n
> FROM
> generate_series(0,.000005,0.000001) x
> ORDER BY x DESC;
>
> CREATE TABLE output(place int,value float);
>
> CREATE TABLE handles AS
> SELECT pg_background_launch(
> format($$
> SELECT pg_sleep(%s);
> INSERT INTO output VALUES (%s, %s)
> $$,
> x, n, x
> )
> ) h
> FROM input;
>
> --wait until everyone finishes
> SELECT * FROM handles JOIN LATERAL pg_background_result(handles.h) AS (x TEXT) ON (true);
>
> --output results
> SELECT * FROM output ORDER BY place;

Best regrards, Andrey Borodin.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Petr Jelinek 2016-12-21 06:37:43 Re: Logical decoding on standby
Previous Message Jim Nasby 2016-12-21 06:06:34 Re: bigint vs txid user confusion