Re: Defer selection of asynchronous subplans until the executor initialization stage

Zhihong Yu <zyu@yugabyte.com>

From: Zhihong Yu <zyu@yugabyte.com>
To: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
Cc: Etsuro Fujita <etsuro.fujita@gmail.com>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>, Justin Pryzby <pryzby@telsasoft.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2021-05-11T03:55:34Z
Lists: pgsql-hackers
On Mon, May 10, 2021 at 8:45 PM Andrey Lepikhov <a.lepikhov@postgrespro.ru>
wrote:

> On 7/5/21 21:05, Etsuro Fujita wrote:
> > I think it would be better to start a new thread for this, and add the
> > patch to the next CF so that it doesn’t get lost.
>
> Current implementation of async append choose asynchronous subplans at
> the phase of an append plan creation. This is safe approach, but we
> loose some optimizations, such of flattening trivial subqueries and
> can't execute some simple queries asynchronously. For example:
>
> EXPLAIN (ANALYZE, TIMING OFF, SUMMARY OFF, COSTS OFF)
> (SELECT * FROM f1 WHERE a < 10) UNION ALL
> (SELECT * FROM f2 WHERE a < 10);
>
> But, as I could understand, we can choose these subplans later, at the
> init append phase when all optimizations already passed.
> In attachment - implementation of the proposed approach.
>
> Initial script for the example see in the parent thread [1].
>
>
> [1]
>
> https://www.postgresql.org/message-id/a38bb206-8340-9528-5ef6-37de2d5cb1a3%40postgrespro.ru
>
>
> --
> regards,
> Andrey Lepikhov
> Postgres Professional
>
Hi,

+           /* Check to see if subplan can be executed asynchronously */
+           if (subplan->async_capable)
+           {
+               subplan->async_capable = false;

It seems the if statement is not needed: you can directly assign false
to  subplan->async_capable.

Cheers

Commits

  1. Improve comments for trivial_subqueryscan().

  2. Disable asynchronous execution if using gating Result nodes.

  3. Allow asynchronous execution in more cases.

  4. Doc: Further update documentation for asynchronous execution.

  5. Fix rescanning of async-aware Append nodes.

  6. Doc: Update documentation for asynchronous execution.

  7. Fix EXPLAIN ANALYZE for async-capable nodes.

  8. Minor code cleanup in asynchronous execution support.

  9. Adjust input value to WaitEventSetWait() in ExecAppendAsyncEventWait().

  10. Add support for asynchronous execution.