| From: | maksim <m(dot)milyutin(at)postgrespro(dot)ru> | 
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | [WIP] Patches to enable extraction state of query execution from external session | 
| Date: | 2016-08-29 15:22:56 | 
| Message-ID: | [email protected] | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Hi, hackers!
Now I complete extension that provides facility to see the current state 
of query execution working on external session in form of EXPLAIN 
ANALYZE output. This extension works on 9.5 version, for 9.6 and later 
it doesn't support detailed statistics for parallel nodes yet.
I want to present patches to the latest version of PostgreSQL core to 
enable this extension.
1. Patch that provides facility to send user signal to external backend 
(custom_signals.patch).
This patch transparently extends process signal interface to enable 
sending user defined signals (I call them - custom signals) and defining 
callbacks to them. Formally it will appear in following manner:
/* Register custom signal and define signal callback */
Reason = RegisterCustomProcSignalHandler(sighandler);
     void
     sighandler(void)
    {
        ...
    }
     /* On other session we can send process signal to the first backend */
    SendProcSignal(pid, Reason, backendId)
The InterruptPending flag is set under process signal handling and 
sighandler is called in CHECK_FOR_INTERRUPTS.
I use this patch to notice other backend to send its state to caller.
2. Patch that enables to interrupt the query executor 
(executor_hooks.patch).
This patch enables to hang up hooks on executor function of each node 
(ExecProcNode). I define hooks before any node execution and after 
execution.
I use this patch to add possibility of query tracing by emitted rows 
from any node. I interrupt query executor after any node delivers one or 
zero rows to upper node. And after execution of specific number trace 
steps I can get the query state of traceable backend which will be 
somewhat deterministic. I use this possibility for regression tests of 
my extension.
3. Patch that enables to output runtime explain statistics 
(runtime_explain.patch).
This patch extends the regular explain functionality. The problem is in 
the point that regular explain call makes result output after query 
execution performing InstrEndLoop on nodes where necessary. My patch 
introduces specific flag *runtime* that indicates whether we explain 
running query and does some insertions in source code dedicated to 
output the statistics of running query.
I want to notice that this patch is completed only for 9.5 postgres 
version. For later versions there is not implemented detailed statistics 
for parellel nodes. Now, I'm working at this feature.
That's all. CC welcome!
-- 
Maksim Milyutin
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
| Attachment | Content-Type | Size | 
|---|---|---|
| custom_signals.patch | text/x-patch | 6.2 KB | 
| executor_hooks.patch | text/x-patch | 2.0 KB | 
| runtime_explain.patch | text/x-patch | 10.1 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andres Freund | 2016-08-29 15:35:45 | Re: Renaming of pg_xlog and pg_clog | 
| Previous Message | David Steele | 2016-08-29 15:18:38 | Re: Renaming of pg_xlog and pg_clog |