Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ndaC5-0000Lh-Bf for pgsql-sql@arkaria.postgresql.org; Sun, 10 Apr 2022 16:13:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ndaC3-0007uI-I0 for pgsql-sql@arkaria.postgresql.org; Sun, 10 Apr 2022 16:13:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ndaC3-0007s8-8B for pgsql-sql@lists.postgresql.org; Sun, 10 Apr 2022 16:13:39 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ndaBw-0000PO-Mr for pgsql-sql@lists.postgresql.org; Sun, 10 Apr 2022 16:13:37 +0000 Received: by mail-ej1-x630.google.com with SMTP id p15so26299887ejc.7 for ; Sun, 10 Apr 2022 09:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P9N+aV6q/h5y17EigCn6PsNOWAkQea6hfcDthIiUD8s=; b=F5En8VZZevnUiUTSODBJizzGq5VGNNha6+K0NCHw4Bn0xDhozoyIq8dX0JrozNQ6Ak C5Okg/xHlWpIcND/SZIYSqd75Cpu4avkkWV5uCUm6+Se+7YIKwv4wASZPBsFWxY7o3/Q zpJtMhNQjIa0R5HNWi6YmUM0xyDg115bvP60n8jtek5u3ElHnJByfTYpWmo4AqnHEn2d 0PsO1CZVL2caTxA9s2Dhrf9hoBr2+npyae0in88GTp4PHgALcxi8aW9/FwMIjZ1tR3WH MBJb2+jqjkt2YWflLGTJI+5iExvDJXShZB6uKDBa+AdOr3LGd+bLQNNd/j1qFoNnPvHI Ia3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P9N+aV6q/h5y17EigCn6PsNOWAkQea6hfcDthIiUD8s=; b=vw7o1qGFqxQfbAqYl7otlIUncyXrDwjuzQrr/8SaYsdcWU8hlKFYx+0Pxu5O2Ve69o L/flIo7RLis7OTn6M9++OoTj9GcRNWm+PiJwlVT2RRy+8r8IWLfA3FzB5tiQLsbNriw6 qBLNVSmpmhGsGyouZ/uyKEE9qG3FWRplVheHoMR2VCsQG5rBvWSAVwtMA7vTFyhMIRCc EPlMQW5dOKfpDW16vxeWIWV4kvh4fR1CH20FSetapdUdYk0P4Goah7eAb1tR9qGCwqFD 17UEeUKRrSKDTdFHBwXUIMkyXtwp5J/+b+gMIZBVZIrcK9/JHfEPt4yTIgEAplyGM8kV RtCw== X-Gm-Message-State: AOAM531+uoOWUMqEPRo1/auxpfWN9TvbHkwCzhFZYLiIMPtOAVpUq3b4 RfGVuCXqFGrMbRb8F9WEy/OKIsEIjClbquOiEkKf5ScI X-Google-Smtp-Source: ABdhPJwrV1KmOtLDL3VCndU3YDTjfUY8WSwN8bNShk2VX9pZ6lTrWmqz8h90tXelrSsu+bye/a+i9OaD9zpfjReGzSo= X-Received: by 2002:a17:906:52c7:b0:6ce:a880:50a3 with SMTP id w7-20020a17090652c700b006cea88050a3mr26543472ejn.437.1649607210098; Sun, 10 Apr 2022 09:13:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "David G. Johnston" Date: Sun, 10 Apr 2022 09:13:14 -0700 Message-ID: Subject: Re: How best to do parallel query given tens of thousands of iteration of a loop of recursive queries? To: Shaozhong SHI Cc: pgsql-sql Content-Type: multipart/alternative; boundary="000000000000c6e31205dc4f1b8c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c6e31205dc4f1b8c Content-Type: text/plain; charset="UTF-8" On Sun, Apr 10, 2022 at 6:50 AM Shaozhong SHI wrote: > There is a plpgsql script that have a loop to carry out the same recursive > queries. > > The estimation of iteration is in the order of tens of thousands. > > What is the best way of making using parallel query strategy. > An example would be helpful. However, as a general guideline, since parallelism is done at the per-row scope, removing looping logic from the script and turning the main script logic into one or more functions that operate on a single row, while obeying the rules such functions need to abide by in order to be marked parallel safe, will open up the possibility for the server to process different rows using different workers and then appending their results together for the next node to consume. David J. --000000000000c6e31205dc4f1b8c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Apr 10, 2022 at 6:50 AM Shaozhong SHI <shishaozhong@gmail.com> wrote:
There is a plpgsql script that have = a loop to carry out the same recursive queries.

The esti= mation of iteration is in the order of tens of thousands.

What is the best way of making using parallel query strategy.
=

An example would be helpful.
<= br>
However, as a general guideline, since parallelism is done at t= he per-row scope, removing looping logic from the script and turning the ma= in script logic into one or more functions that operate on a single row, wh= ile obeying the rules such functions need to abide by in order to be marked= parallel safe, will open up the possibility for the server to process diff= erent rows using different workers and then appending their results togethe= r for the next node to consume.

David J.
--000000000000c6e31205dc4f1b8c--