Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6m95-0000T2-H6 for pgsql-general@arkaria.postgresql.org; Sun, 08 Sep 2019 01:37:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i6m94-00007m-8o for pgsql-general@arkaria.postgresql.org; Sun, 08 Sep 2019 01:37:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6m93-0008KA-Pp for pgsql-general@lists.postgresql.org; Sun, 08 Sep 2019 01:37:37 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i6m90-00006U-Q4 for pgsql-general@postgresql.org; Sun, 08 Sep 2019 01:37:37 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 806AA16FADDAE for ; Sat, 7 Sep 2019 18:37:32 -0700 (MST) Date: Sat, 7 Sep 2019 18:37:32 -0700 (MST) From: Jim Finnerty To: pgsql-general@postgresql.org Message-ID: <1567906652523-0.post@n3.nabble.com> Subject: Whan is it safe to mark a function PARALLEL SAFE? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk According to the documentation: "Functions and aggregates must be marked PARALLEL UNSAFE if they write to the database, access sequences, change the transaction state even temporarily (e.g. a PL/pgSQL function which establishes an EXCEPTION block to catch errors), or make persistent changes to settings." If a LANGUAGE C function calls ereport(ERROR, ...), does that qualify as a potential change to the transaction state that requires it to be marked PARALLEL UNSAFE? If an error is raised in one parallel worker, does this cause the other parallel workers to be immediately terminated? How about a C function f(x) that calls out to an external system and returns a text value. If f(x) is altered on the external system, it might return a slightly different answer for some x. Let's say that for some x it returns "one" instead of "1", and we happen to know that users don't care if it returns "one" or "1". If someone were to declare f(x) to be PARALLEL SAFE, what's the worst that could happen? ----- Jim Finnerty, AWS, Amazon Aurora PostgreSQL -- Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html