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 1fptgy-00081W-Ku for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Aug 2018 11:10:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fptgu-0004ud-AN for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Aug 2018 11:10:16 +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 1fptgu-0004uQ-46 for pgsql-bugs@lists.postgresql.org; Wed, 15 Aug 2018 11:10:16 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fptgm-0001NQ-Iv for pgsql-bugs@lists.postgresql.org; Wed, 15 Aug 2018 11:10:15 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 1FCDE5F79C; Wed, 15 Aug 2018 07:10:07 -0400 (EDT) Date: Wed, 15 Aug 2018 07:10:07 -0400 From: Stephen Frost To: Amit Kapila Cc: Tom Lane , Marko Tiikkaja , Andres Freund , Andrew Fletcher , PostgreSQL mailing lists Subject: Re: BUG #15324: Non-deterministic behaviour from parallelised sub-query Message-ID: <20180815111006.GB3326@tamriel.snowman.net> References: <21038.1534181205@sss.pgh.pa.us> <390.1534261450@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="oDT+BabbEBWcQhh5" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --oDT+BabbEBWcQhh5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Amit Kapila (amit.kapila16@gmail.com) wrote: > On Tue, Aug 14, 2018 at 9:14 PM, Tom Lane wrote: > > Marko Tiikkaja 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 o= rder > >> in different workers. And I don't really think that to be the functio= n's > >> fault. > > > > So that basically opens the question of whether *any* window function > > calculation can safely be pushed down to parallel workers. >=20 > I think we can consider it as a parallel-restricted operation. For > the purpose of testing, I have marked row_number as > parallel-restricted in pg_proc and I get the below plan: >=20 > postgres=3D# Explain select count(*) from qwr where (a, b) in (select a, > row_number() over() from qwr); > QUERY PLAN > -------------------------------------------------------------------------= ------------------------------- > Aggregate (cost=3D46522.12..46522.13 rows=3D1 width=3D8) > -> Hash Semi Join (cost=3D24352.08..46362.12 rows=3D64001 width=3D0) > Hash Cond: ((qwr.a =3D qwr_1.a) AND (qwr.b =3D (row_number() OVE= R (?)))) > -> Gather (cost=3D0.00..18926.01 rows=3D128002 width=3D8) > Workers Planned: 2 > -> Parallel Seq Scan on qwr (cost=3D0.00..18926.01 > rows=3D64001 width=3D8) > -> Hash (cost=3D21806.06..21806.06 rows=3D128002 width=3D12) > -> WindowAgg (cost=3D0.00..20526.04 rows=3D128002 width= =3D12) > -> Gather (cost=3D0.00..18926.01 rows=3D128002 wid= th=3D4) > Workers Planned: 2 > -> Parallel Seq Scan on qwr qwr_1 > (cost=3D0.00..18926.01 rows=3D64001 width=3D4) > (11 rows) >=20 > This seems okay, though the results of the above parallel-execution > are not same as serial-execution. I think the reason for it is that > we don't get rows in predictable order from workers. You wouldn't get them in a predictable order even without parallelization due to the lack of an ordering, so this hardly seems like an issue. > > Somewhat like the LIMIT/OFFSET case, it seems to me that we could only > > expect to do this safely if the row ordering induced by the WINDOW clau= se > > can be proven to be fully deterministic. The planner has no such smarts > > at the moment AFAIR. In principle you could do it if there were > > partitioning/ordering by a primary key, but I'm not excited about the > > prospects of that being true often enough in practice to justify making > > the check. >=20 > Yeah, I am also not sure if it is worth adding the additional checks. > So, for now, we can treat any window function calculation as > parallel-restricted and if later anybody has a reason strong enough to > relax the restriction for some particular case, we will consider it. Seems likely that we'll want this at some point, but certainly seems like new work and not a small bit of it. Thanks! Stephen --oDT+BabbEBWcQhh5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJbdAoOAAoJEO1sijiDR2RVGJ0QAIsHCEkMI5wWMilMIuPUM2uD 8LS6U61SNcVbuF0Sfym4KI31SxiXwRjJJG+Ey0obOdKEdkTpAHrXcjkXZ5bs+aCR qLbig3jStN6wRmbDnirLuWz85fgGkxD4QwIyWptGCkSK3GLtwLQy7Eobg99dTxJm v1pXX/IaAQszThOasao74KkApHyp9Mpl6NcV5K9BVYf8OzKyr5OOxb6vhJqPl6xn m7hgXwvMHR3eaeIgvcsh1IaI9prHT6nEohueP8S1LZkaT+LWpx3z9+NBADyBWJC/ 1BQZjofNI+9JBTyWR5yBXjXk65MDc2z3dIv8f8BA4kZq5Szz4mnG84dqZrB0oIge Oh8acsygSSmXb+ZtT6x1cntcEiNnuqz79ploB1hG/SjjzZ6rKSFyJOMiX+0OIzgH ao9dJAmNeVWTGQLRcbLYXMxMj74E+sS3bVYxHZSQy8bpVxIXFIAglwzRFbx10NIf wrBtTP8vC5zWJUB7RzLY9yfVu+GBtvw/1XtRlAFIG7LfVSV77Az+zxquPXc/0u8K R2hfwBIeJub1oqBHWhKefaYcW9rLDCn3aTA5ta2COCiQ3DwTrPrmbKX86WqBkdtl j1/MJrpzhW0Buw2fgZAPQFJoQZCi/WQs7kzbt4/5VQBt7oFDc2xxd74a3R1pxVuM wp6DLZN4ObRE0Bi8ztnI =57zT -----END PGP SIGNATURE----- --oDT+BabbEBWcQhh5--