Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tcdVQ-001YJi-35 for pgsql-general@arkaria.postgresql.org; Tue, 28 Jan 2025 04:47:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tcdVN-00GQdE-UN for pgsql-general@arkaria.postgresql.org; Tue, 28 Jan 2025 04:47:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tcdVN-00GQd5-3u for pgsql-general@lists.postgresql.org; Tue, 28 Jan 2025 04:47:17 +0000 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tcdVK-001sVa-0l for pgsql-general@postgresql.org; Tue, 28 Jan 2025 04:47:15 +0000 Received: by mail-ej1-x643.google.com with SMTP id a640c23a62f3a-aaeec07b705so1006037066b.2 for ; Mon, 27 Jan 2025 20:47:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1738039632; x=1738644432; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=8ecSQeOsh99A1+llmy/TUTmJTtvdrgPbZMgKagZQjGw=; b=d88yJJ8KsWMpHLs9F6zJj9hsDUyVpH+kv3d/51D/S8OPeStZmSbO4h0QxXgLm5bPeG 60B44AduHdyb2zrBnHTFiFeZ7NNe9493mBHr6D0DIYtbUp8BdhZC4bYqGnvAQVEEv82s G79z9PpBqSNBytpQ3Bp8MhSYLWDC40WtM6fYnyNesSioRDQ37lu/PtYRIIvKOIIJED9e rmOGq+ais6n2nj9eqApuB4a7eCLILduKe9+jLAXlOG0nZRVBSymFgUGtBhnZfBGkbnmo 2DUfDegb2EkBpTPJnpM6tad+1WDf8u3hGTI/USMvT2rsc+7aTxx09xAzplTis8w9Qf/N ODUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738039632; x=1738644432; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8ecSQeOsh99A1+llmy/TUTmJTtvdrgPbZMgKagZQjGw=; b=dePuEkmA9RWInbadw5b+2AkyF+aQJycI/0ldpA50IF1+ux6mawFfvVJwvfvR3cVR4L fPsL+Z+3Q0VsopIDHL3LaDLZJqyaAHbqt6q5K/NcenpaHxZXmH/FU/dpYbTsDGhcvrXd CGaQAB+03Z5l4XYv3fgMhQqNZS2NiJDPN7IvUHpwI/Y3hEwNFlBvUfAV/pj5C7UWyzYt LL8cMDm9XdYVNrgoE9Zo2GvqkMUiROorpR2fvhO9x5Y9C6avNglAeLkYnVhtUGoRlwYw 1GwSzSxINHMezX3gKAFD6tpUV3q8d4FYUDWGnMBepdQi1vw/TYcTMUeADlVN2/idZPUk Wcbw== X-Forwarded-Encrypted: i=1; AJvYcCWxRIVwh5AbftoYjgcZV//9MI6HxI1QO6k5JqFcTC7AbFkFbf1Epv5mtfbrPAyKAoAIfNDrR9CHh2gDKUKn@postgresql.org X-Gm-Message-State: AOJu0YzOEIGO+5H9h3qdLlPVorU0C8Rf4GpmzICKrHHo391ra6+JGwsR ViFIAterzEHrM0JVHSJXL4WP9Dcuh4TtZhdZTmlxJQhqq3L+z71StTMMqYpA1+c= X-Gm-Gg: ASbGncttlSOksi+oXUWPgDOB4/XglLb388sLHAuUTbra3dBI14gd5qICbKfL6LYLIX7 d2v21qvcfXmzS32SWXDQ0a+43QSWxU+I33OwkqV+86qwz42rxpnZTcGdTdMvi8Kr0bTbb5Qa/U9 0xXledvwfas8AGirnYRN2iRbQHxYT88ZUF1DCju0ko2jFBsFq1VJoBwCgPYWfknEe2bMaYtPJe1 GGjTGr5FYh3UMCLorNluc+MVt3vX8jpsOHB4kdJFYH1YpC9yMY23j62AIsCHQjTOa+KAaKiEdjA HavTnm1btPvP/1/hYECkAnQYw3FzhYbbt5W84A== X-Google-Smtp-Source: AGHT+IHpGapT0hwt5ZrItuJv4v7T5lPYUv/O+YYyL2g3gfOlouoik8FIN61uTaUw8aCxu5koU62GYQ== X-Received: by 2002:a17:907:7fa8:b0:aaf:123a:e4f0 with SMTP id a640c23a62f3a-ab38b0b6886mr4317586166b.6.1738039632061; Mon, 27 Jan 2025 20:47:12 -0800 (PST) Received: from localhost.localdomain ([2001:871:255:9ae3:244c:7859:2776:53b7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6760fbe81sm707480366b.137.2025.01.27.20.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 20:47:11 -0800 (PST) Message-ID: <0db12127e1bfc939a66a6ee959346b28cf1c6838.camel@cybertec.at> Subject: Re: Parallel workers via functions? From: Laurenz Albe To: Jim Vanns , pgsql-general Date: Tue, 28 Jan 2025 05:47:11 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2025-01-27 at 18:08 +0000, Jim Vanns wrote: > If I have a function that is marked 'stable parallel safe' and returns > a table, can a calling function or procedure (marked volatile parallel > unsafe) still take advantage of the parallel workers from the first > function - as the data source. I.e. >=20 > func_a(); // selects, returns table, parallel safe > func_b() { > insert into foo > select * from func_a(); // Will func_a still execute parallel > workers to fetch the data? > } >=20 > Or even if func_b() uses 'create temporary table as select * from > func_a()' and then insert? >=20 > I ask because when I simply call func_a() from a psql shell, I see the > parallel workers run and everything is nice and swift. But when called > from a data-modifying function like func_b(), no workers are spawned > :( Even from the read-part of the code. >=20 > Are there differences in functions vs. stored procedures that might > affect the behaviour of the planner to disregard workers? See https://www.postgresql.org/docs/current/when-can-parallel-query-be-used= .html The problem here is the INSERT. Data modifying statements won't use parallel query. There are exceptions: CREATE TABLE ... AS SELECT ... should be able to use parallel query. Yours, Laurenz Albe