Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpjvZ-0006Nu-WF for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Aug 2018 00:44:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fpjvV-00025k-Nl for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Aug 2018 00:44:41 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpjvV-00025d-HT for pgsql-bugs@lists.postgresql.org; Wed, 15 Aug 2018 00:44:41 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpjvN-0004Eb-My for pgsql-bugs@lists.postgresql.org; Wed, 15 Aug 2018 00:44:40 +0000 Received: from [192.168.127.1] (port=11089 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1fpjvI-0008cM-QB; Wed, 15 Aug 2018 00:44:28 +0000 Received: from [127.0.0.1] (port=30980 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fpjvI-0009Jv-0F; Wed, 15 Aug 2018 00:44:28 +0000 From: Andrew Gierth To: Tom Lane Cc: Marko Tiikkaja , Amit Kapila , Andres Freund , Andrew Fletcher , PostgreSQL mailing lists Subject: Re: BUG #15324: Non-deterministic behaviour from parallelised sub-query In-Reply-To: <390.1534261450@sss.pgh.pa.us> (Tom Lane's message of "Tue, 14 Aug 2018 11:44:10 -0400") Message-ID: <87sh3g4h8n.fsf@news-spur.riddles.org.uk> References: <153417684333.10284.11356259990921828616@wrigleys.postgresql.org> <20180813163518.gqvu2kqwr6uj75vj@alap3.anarazel.de> <21038.1534181205@sss.pgh.pa.us> <390.1534261450@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Wed, 15 Aug 2018 01:44:27 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Tom" == Tom Lane writes: >> Marking the function parallel safe doesn't seem wrong to me. The >> non-parallel-safe part is that the input gets fed to it in different >> order in different workers. And I don't really think that to be the >> function's fault. Tom> So that basically opens the question of whether *any* window Tom> function calculation can safely be pushed down to parallel Tom> workers. Grepping the spec for the phrase "possibly non-deterministic" is quite enlightening. Leaving out non-determinisms caused by timezone or actual volatility, leaving out cases of non-determinism that we'd call "stable", and leaving out features like multisets that we don't support at all, here's the list of interesting cases (comments after each quoted paragraph are mine): 6.28 d) An . i.e. ARRAY(select) o) An that specifies MIN or MAX and that simply contains a whose declared type is based on a character string type, user-defined type, or datetime with time zone type. i.e. MIN(x) is non-deterministic if "x" can have distinguishable values that compare equal. PG doesn't have that for text or timestamptz, unlike the spec, but it does for citext or other user-defined types. q) An . i.e. array_agg() u) A that specifies ROW_NUMBER, FIRST_VALUE, LAST_VALUE, NTH_VALUE, NTILE, LEAD, or LAG, or whose associated specifies ROWS. This covers those cases where window functions don't treat peer rows together. 7.6 27) A
is possibly non-deterministic if the simply contained
or is possibly non-deterministic or if is specified. i.e. TABLESAMPLE is non-deterministic 7.16 a) The DISTINCT is specified and one of the columns of T has a data type of character string, user-defined type, TIME WITH TIME ZONE, or TIMESTAMP WITH TIME ZONE. c) The