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 1ggclG-000703-Vk for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Jan 2019 21:48:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ggclF-0006or-KB for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Jan 2019 21:48: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_SHA1:256) (Exim 4.89) (envelope-from ) id 1ggccP-0004U3-4O for pgsql-bugs@lists.postgresql.org; Mon, 07 Jan 2019 21:39:33 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ggccL-0001AN-FR for pgsql-bugs@lists.postgresql.org; Mon, 07 Jan 2019 21:39:32 +0000 Received: by mail-wm1-x334.google.com with SMTP id y139so2197393wmc.5 for ; Mon, 07 Jan 2019 13:39:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NE2fH8IxZ/ghD49UHoK1Tme+F9/IyOOJTHp4+TPCAZQ=; b=qqJPvxwfu4c1N9tocvymTVga5ufI4CMfwIu0PHVMuN1mJd2qtxqLk0kfkWLxKf0cTd 7U7G/MN+SwIKmvaavAgjcGX9ug5/oVxIky9iZFT8Mm9mqC/z73dFq7n8R2RosUmnFAAg r8usE2JkxZoaIXEoGbx1WgOLOnck2vkyFD2FFy1b5DOxhTlvOqwcZw7Ch0Tl712vn4FQ 4Z/NpmgSAKoSJfFC8jubUUQ+PrWaj3w2+PhkXsm/Et0GxrVpSWp60IdkcSOng698hMSg EOawezFQPKDfeOnVTsIDHo4vdTjrK0yxtgBK/6QGTc6I9TkilIP+svkDyqWp3y2f80BK p+Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NE2fH8IxZ/ghD49UHoK1Tme+F9/IyOOJTHp4+TPCAZQ=; b=PNvJOCbmxFxcF5QrCgVn/dfUAIXp15WoTvg30yJW4BhnCCLWvkmdDc2rqLCwcl3woa dr2O2BArdXmvAM/WANUOqeRUq/Z/p+R4uQRIWWoEsCAtjHhbuSU6sTTyKRI4mDXK+HLB R++0AZAC+GOftu8biWW5J1DGYF+mE6JojQ5852bQKLBV61zwySS1tCIaADHJHy2WzG/v Gd7hiGZF/OHUyl8qE3q1An/rR4sRfDYcd42nYumuDf+eBUmXinioCxP8YtGcLG5OhF9D 7FwQtiKghv0mnFNgEHhhNyQtXRDonMtbz+UyNAATkmM2QjGdJvVr1Gu0Jz9KkEcndfIW anLw== X-Gm-Message-State: AJcUukezCtQ/Kfo3wAEdXIXUbAam0iU2DRdtd+znu+Q9Qj1Fu5Y7LU5i AqrUPKf0h62SujsDtLyCtwz9RUqn9yFc4N1Y9wM= X-Google-Smtp-Source: ALg8bN7HptVS0H/mQq8rf/W0v4mB4cjogDzIkcXvw+ZFP92ND9oWIjlFUHUR32LrKNhEc3QGh1wWozFXCehZhv8T8zw= X-Received: by 2002:a1c:35ca:: with SMTP id c193mr9692398wma.146.1546897167638; Mon, 07 Jan 2019 13:39:27 -0800 (PST) MIME-Version: 1.0 References: <15577-ca61ab18904af852@postgresql.org> In-Reply-To: From: Bartosz Polnik Date: Mon, 7 Jan 2019 22:39:17 +0100 Message-ID: Subject: Re: BUG #15577: Query returns different results when executed multiple times To: Thomas Munro Cc: David Rowley , PostgreSQL mailing lists Content-Type: multipart/alternative; boundary="0000000000002e6569057ee51078" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000002e6569057ee51078 Content-Type: text/plain; charset="UTF-8" For the following sql: *SET force_parallel_mode = on;* explain (costs false, analyze true) SELECT ta.id AS table_a_id, tc.id as table_c_id, tba.id AS table_b_id FROM test.table_b_active tba INNER JOIN test.table_c tc ON tba.target_id = tc.id INNER JOIN test.table_d td ON tc.table_d_id = td.id LEFT JOIN test.table_a ta ON ta.table_c_id = tc.id AND ta.date = '2018-08-31' :: DATE WHERE tba.date BETWEEN '2018-08-10' :: DATE AND '2018-09-01' :: DATE AND td.group = 'A' AND tc.table_e_id = 4 AND ( (tba.target_id = tc.id AND tba.group_type = 'A') OR tba.source_id = tc.id ); I got: QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop Left Join (actual time=145.151..284.612 rows=26 loops=1) -> Gather (actual time=145.092..304.166 rows=26 loops=1) Workers Planned: 1 Workers Launched: 1 -> Nested Loop (actual time=153.289..247.768 rows=13 loops=2) -> Hash Join (actual time=0.221..15.028 rows=945 loops=2) Hash Cond: (tc.table_d_id = td.id) -> Parallel Seq Scan on table_c tc (actual time=0.085..14.442 rows=1751 loops=2) Filter: (table_e_id = 4) Rows Removed by Filter: 49117 -> Hash (actual time=0.044..0.045 rows=8 loops=2) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Seq Scan on table_d td (actual time=0.028..0.033 rows=8 loops=2) Filter: (group = 'A'::test.group) Rows Removed by Filter: 55 -> Index Scan using table_b_idx_target_id on table_b (actual time=0.242..0.246 rows=0 loops=1890) Index Cond: (target_id = tc.id) Filter: ((date >= '2018-08-10'::date) AND (date <= '2018-09-01'::date) AND (((target_id = tc.id) AND (group_type = 'A'::test.group_type)) OR (source_id = tc.id))) Rows Removed by Filter: 26 -> Index Scan using table_a_uq_001 on table_a ta (actual time=0.016..0.016 rows=1 loops=26) Index Cond: ((table_c_id = tc.id) AND (date = '2018-08-31'::date)) Planning Time: 5.024 ms Execution Time: 304.858 ms On Second execution: QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop Left Join (actual time=228.405..279.383 rows=19 loops=1) -> Gather (actual time=228.376..288.807 rows=19 loops=1) Workers Planned: 1 Workers Launched: 1 -> Nested Loop (actual time=150.785..242.440 rows=10 loops=2) -> Hash Join (actual time=0.212..14.353 rows=945 loops=2) Hash Cond: (tc.table_d_id = td.id) -> Parallel Seq Scan on table_c tc (actual time=0.075..13.794 rows=1751 loops=2) Filter: (table_e_id = 4) Rows Removed by Filter: 49117 -> Hash (actual time=0.050..0.050 rows=8 loops=2) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Seq Scan on table_d_id td (actual time=0.031..0.037 rows=8 loops=2) Filter: (group = 'A'::test.group) Rows Removed by Filter: 55 -> Index Scan using table_b_idx_target_id on table_b (actual time=0.237..0.241 rows=0 loops=1890) Index Cond: (target_id = tc.id) Filter: ((date >= '2018-08-10'::date) AND (date <= '2018-09-01'::date) AND (((target_id = tc.id) AND (group_type = 'A'::test.group_type)) OR (source_id = tc.id))) Rows Removed by Filter: 26 -> Index Scan using table_a_uq_001 on table_a ta (actual time=0.021..0.021 rows=1 loops=19) Index Cond: ((table_c_id = tc.id) AND (date = '2018-08-31'::date)) Planning Time: 4.816 ms Execution Time: 289.503 ms I executed it a couple of times and saw in output 26 rows (as above), 21 rows (also above), 28 rows, 28 rows, 29 rows etc. The changing parts (nr of rows) were: Nested Loop Left Join and Nested Loop. For the following sql: *SET parallel_leader_participation = on;* explain (costs false, analyze true) SELECT ta.id AS table_a_id, tc.id as table_c_id, tba.id AS table_b_id FROM test.table_b_active tba INNER JOIN test.table_c tc ON tba.target_id = tc.id INNER JOIN test.table_d td ON tc.table_d_id = td.id LEFT JOIN test.table_a ta ON ta.table_c_id = tc.id AND ta.date = '2018-08-31' :: DATE WHERE tba.date BETWEEN '2018-08-10' :: DATE AND '2018-09-01' :: DATE AND td.group = 'A' AND tc.table_e_id = 4 AND ( (tba.target_id = tc.id AND tba.group_type = 'A') OR tba.source_id = tc.id ); I received: QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop Left Join (actual time=143.805..279.354 rows=29 loops=1) -> Gather (actual time=143.735..299.066 rows=29 loops=1) Workers Planned: 1 Workers Launched: 1 -> Nested Loop (actual time=149.334..242.108 rows=15 loops=2) -> Hash Join (actual time=0.203..14.536 rows=945 loops=2) Hash Cond: (tc.table_d_id = td.id) -> Parallel Seq Scan on table_c tc (actual time=0.072..13.971 rows=1751 loops=2) Filter: (table_e_id = 4) Rows Removed by Filter: 49117 -> Hash (actual time=0.043..0.043 rows=8 loops=2) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Seq Scan on table_d td (actual time=0.028..0.034 rows=8 loops=2) Filter: (group = 'A'::test.group) Rows Removed by Filter: 55 -> Index Scan using table_b_idx_target_id on table_b (actual time=0.237..0.240 rows=0 loops=1890) Index Cond: (target_id = tc.id) Filter: ((date >= '2018-08-10'::date) AND (date <= '2018-09-01'::date) AND (((target_id = tc.id) AND (group_type = 'A'::test.group_type)) OR (source_id = tc.id))) Rows Removed by Filter: 26 -> Index Scan using table_a_uq_001 on table_a ta (actual time=0.018..0.018 rows=1 loops=29) Index Cond: ((table_c_id = tc.id) AND (date = '2018-08-31'::date)) Planning Time: 5.070 ms Execution Time: 299.849 ms QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop Left Join (actual time=231.714..276.770 rows=26 loops=1) -> Gather (actual time=231.654..295.971 rows=26 loops=1) Workers Planned: 1 Workers Launched: 1 -> Nested Loop (actual time=151.209..239.965 rows=13 loops=2) -> Hash Join (actual time=0.214..14.467 rows=945 loops=2) Hash Cond: (tc.table_d_id = td.id) -> Parallel Seq Scan on table_c tc (actual time=0.070..13.923 rows=1751 loops=2) Filter: (table_e_id = 4) Rows Removed by Filter: 49117 -> Hash (actual time=0.045..0.045 rows=8 loops=2) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Seq Scan on table_d td (actual time=0.028..0.033 rows=8 loops=2) Filter: (group = 'A'::test.group) Rows Removed by Filter: 55 -> Index Scan using table_b_idx_target_id on table_b (actual time=0.235..0.238 rows=0 loops=1890) Index Cond: (target_id = tc.id) Filter: ((date >= '2018-08-10'::date) AND (date <= '2018-09-01'::date) AND (((target_id = tc.id) AND (group_type = 'A'::test.group_type)) OR (source_id = tc.id))) Rows Removed by Filter: 26 -> Index Scan using table_a_uq_001 on table_a ta (actual time=0.017..0.017 rows=1 loops=26) Index Cond: ((table_c_id = tc.id) AND (date = '2018-08-31'::date)) Planning Time: 4.976 ms Execution Time: 296.729 ms I also made a test with: *SET parallel_leader_participation = off;* *SET force_parallel_mode = on;* explain (costs false, analyze true) SELECT ta.id AS table_a_id, tc.id as table_c_id, tba.id AS table_b_id FROM test.table_b_active tba INNER JOIN test.table_c tc ON tba.target_id = tc.id INNER JOIN test.table_d td ON tc.table_d_id = td.id LEFT JOIN test.table_a ta ON ta.table_c_id = tc.id AND ta.date = '2018-08-31' :: DATE WHERE tba.date BETWEEN '2018-08-10' :: DATE AND '2018-09-01' :: DATE AND td.group = 'A' AND tc.table_e_id = 4 AND ( (tba.target_id = tc.id AND tba.group_type = 'A') OR tba.source_id = tc.id ); The output is correct - 31 rows, but the plan is different: QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Gather (actual time=263.880..507.668 rows=31 loops=1) Workers Planned: 1 Workers Launched: 1 Single Copy: true -> Nested Loop Left Join (actual time=193.246..415.020 rows=31 loops=1) -> Nested Loop (actual time=192.997..414.336 rows=31 loops=1) -> Hash Join (actual time=0.287..23.958 rows=1890 loops=1) Hash Cond: (tc.table_d_id = td.id) -> Seq Scan on table_c tc (actual time=0.128..23.044 rows=3501 loops=1) Filter: (table_e_id = 4) Rows Removed by Filter: 98233 -> Hash (actual time=0.064..0.069 rows=8 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Seq Scan on table_d td (actual time=0.045..0.052 rows=8 loops=1) Filter: (group = 'A'::test.group) Rows Removed by Filter: 55 -> Index Scan using table_b_idx_target_id on table_b (actual time=0.203..0.206 rows=0 loops=1890) Index Cond: (target_id = tc.id) Filter: ((date >= '2018-08-10'::date) AND (date <= '2018-09-01'::date) AND (((target_id = tc.id) AND (group_type = 'A'::test.group_type)) OR (source_id = tc.id))) Rows Removed by Filter: 26 -> Index Scan using table_a_uq_001 on table_a ta (actual time=0.021..0.021 rows=1 loops=31) Index Cond: ((table_c_id = tc.id) AND (date = '2018-08-31'::date)) Planning Time: 5.051 ms Execution Time: 507.858 ms On Mon, Jan 7, 2019 at 8:59 PM Thomas Munro wrote: > On Tue, Jan 8, 2019 at 1:56 AM Bartosz Polnik > wrote: > > I've modified the script: > > 1. I Added SET force_parallel_mode = on;: > > What if you try that with your original query in the database that > shows the problem? Or alternatively SET parallel_leader_participation > = on. What I'm wondering is whether the parallel worker is > consistently getting the same result, but it's a different result from > the leader, and the variation comes from the race between leader and > worker, or whether the instability comes from somewhere else. > > -- > Thomas Munro > http://www.enterprisedb.com > --0000000000002e6569057ee51078 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
For the following sql:

SE= T force_parallel_mode =3D on;
explain (costs false, analyze t= rue)
=C2=A0 SELECT ta.id AS table_a_= id,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tc= .id as table_c_id,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tba.id AS table_b_id
=C2=A0 FROM test.tabl= e_b_active tba
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INNER JOIN test.= table_c tc ON tba.target_id =3D tc.id
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INNER JOIN test.table_d td ON tc.table_= d_id =3D td.id
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0LEFT JOIN test.table_a ta ON ta.table_c_id =3D tc.id AND ta.date =3D
'2018-08-31' :: DATE<= /div>
=C2=A0 WHERE tba.date BETWEEN '2018-08-10' :: DATE AND &#= 39;2018-09-01' :: DATE
=C2=A0 =C2=A0 AND td.group =3D 'A&= #39;
=C2=A0 =C2=A0 AND tc.table_e_id =3D 4
=C2=A0 =C2= =A0 AND (
=C2=A0 =C2=A0 =C2=A0 (tba.target_id =3D tc.id AND tba.group_type =3D 'A')
=C2=A0 = =C2=A0 =C2=A0 OR tba.source_id =3D tc.id
=
=C2=A0 =C2=A0 );


I got:
<= div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN
-------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= -------------------------------------------------------------
=C2= =A0Nested Loop Left Join (actual time=3D145.151..284.612 rows=3D26 loops=3D= 1)
=C2=A0 =C2=A0->=C2=A0 Gather (actual time=3D145.092..304.16= 6 rows=3D26 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers = Planned: 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Launched: 1<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Nested Loop (actual= time=3D153.289..247.768 rows=3D13 loops=3D2)
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Hash Join (actual time=3D= 0.221..15.028 rows=3D945 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Hash Cond: (tc.table_d_id = =3D td.id)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Parallel Se= q Scan on table_c tc (actual time=3D0.085..14.442 rows=3D1751 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: (table_e_id =3D 4)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0Rows Removed by Filter: 49117
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Hash= (actual time=3D0.044..0.045 rows=3D8 loops=3D2)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0Buckets: 1024=C2=A0 Batches: 1=C2=A0 Memory Usage: 9kB
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Seq Scan on table_d td (actual time=3D0= .028..0.033 rows=3D8 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0Filter: (group =3D 'A'::test.group)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Rows Removed by Filter: 55
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Index Sc= an using table_b_idx_target_id on table_b (actual time=3D0.242..0.246 rows= =3D0 loops=3D1890)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: (target_id =3D tc.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: ((date >=3D '2018-08-10':= :date) AND (date <=3D '2018-09-01'::date) AND (((target_id =3D <= a href=3D"http://tc.id">tc.id) AND (group_type =3D 'A'::test.gr= oup_type)) OR (source_id =3D tc.id)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Rows Removed by Filter: 26
=C2=A0 =C2=A0->=C2=A0 Index Scan= using table_a_uq_001 on table_a ta (actual time=3D0.016..0.016 rows=3D1 lo= ops=3D26)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: ((table_c= _id =3D tc.id) AND (date =3D '2018-08-31&#= 39;::date))
=C2=A0Planning Time: 5.024 ms
=C2=A0Executi= on Time: 304.858 ms


On Second execu= tion:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN
----------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ----------------------------------------------------------
=C2=A0= Nested Loop Left Join (actual time=3D228.405..279.383 rows=3D19 loops=3D1)<= /div>
=C2=A0 =C2=A0->=C2=A0 Gather (actual time=3D228.376..288.807 r= ows=3D19 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Pla= nned: 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Launched: 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Nested Loop (actual ti= me=3D150.785..242.440 rows=3D10 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Hash Join (actual time=3D0.21= 2..14.353 rows=3D945 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Hash Cond: (tc.table_d_id =3D = td.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Parallel Seq Sc= an on table_c tc (actual time=3D0.075..13.794 rows=3D1751 loops=3D2)
<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: (table_e_id =3D 4)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0Rows Removed by Filter: 49117
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Hash (ac= tual time=3D0.050..0.050 rows=3D8 loops=3D2)
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Buckets: 1024=C2=A0 Batches: 1=C2=A0 Memory Usage: 9kB
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0->=C2=A0 Seq Scan on table_d_id td (actual time=3D0.031= ..0.037 rows=3D8 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0Filter: (group =3D 'A'::test.group)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Rows Removed by Filter: 55
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Index Scan = using table_b_idx_target_id on table_b (actual time=3D0.237..0.241 rows=3D0= loops=3D1890)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: (target_id =3D tc.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: ((date >=3D '2018-08-10'::dat= e) AND (date <=3D '2018-09-01'::date) AND (((target_id =3D tc.id) AND (group_type =3D 'A'::test.group_= type)) OR (source_id =3D tc.id)))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Rows Removed by Filter: 26
=C2=A0 =C2=A0->=C2=A0 Index Scan= using table_a_uq_001 on table_a ta (actual time=3D0.021..0.021 rows=3D1 lo= ops=3D19)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: ((table_c= _id =3D tc.id) AND (date =3D '2018-08-31&#= 39;::date))
=C2=A0Planning Time: 4.816 ms
=C2=A0Executi= on Time: 289.503 ms


I executed it a= couple of times and saw in output 26 rows (as above), 21 rows (also above)= , 28 rows, 28 rows, 29 rows etc.=C2=A0
The changing parts (nr of = rows) were: Nested Loop Left Join and Nested Loop.


For the following sql:

SET para= llel_leader_participation =3D on;
explain (costs false, analy= ze true)
=C2=A0 SELECT ta.id AS tabl= e_a_id,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tc.id as table_c_id,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tba.id AS table_b_id
=C2=A0 FROM test.t= able_b_active tba
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INNER JOIN te= st.table_c tc ON tba.target_id =3D tc.id
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INNER JOIN test.table_d td ON tc.tab= le_d_id =3D td.id
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0LEFT JOIN test.table_a ta ON ta.table_c_id =3D tc.id AND ta.date =3D
'2018-08-31' :: D= ATE
=C2=A0 WHERE tba.date BETWEEN '2018-08-10' :: DATE AN= D '2018-09-01' :: DATE
=C2=A0 =C2=A0 AND td.group =3D = 9;A'
=C2=A0 =C2=A0 AND tc.table_e_id =3D 4
=C2=A0 = =C2=A0 AND (
=C2=A0 =C2=A0 =C2=A0 (tba.target_id =3D tc.id AND tba.group_type =3D 'A')
=C2=A0= =C2=A0 =C2=A0 OR tba.source_id =3D tc.id
=C2=A0 =C2=A0 );

I received:

<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN
--------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------
=C2=A0Nest= ed Loop Left Join (actual time=3D143.805..279.354 rows=3D29 loops=3D1)
=C2=A0 =C2=A0->=C2=A0 Gather (actual time=3D143.735..299.066 rows= =3D29 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Planne= d: 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Launched: 1
<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Nested Loop (actual time= =3D149.334..242.108 rows=3D15 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Hash Join (actual time=3D0.203..= 14.536 rows=3D945 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Hash Cond: (tc.table_d_id =3D td.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Parallel Seq Scan = on table_c tc (actual time=3D0.072..13.971 rows=3D1751 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0Filter: (table_e_id =3D 4)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0Rows Removed by Filter: 49117
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Hash (actua= l time=3D0.043..0.043 rows=3D8 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Buckets: 1024=C2=A0 Batches: 1=C2=A0 Memory Usage: 9kB
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0->=C2=A0 Seq Scan on table_d td (actual time=3D0.028..0= .034 rows=3D8 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Filter: (group =3D 'A'::test.group)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Rows Removed by Filter: 55
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Index Scan usin= g table_b_idx_target_id on table_b (actual time=3D0.237..0.240 rows=3D0 loo= ps=3D1890)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0Index Cond: (target_id =3D tc.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0Filter: ((date >=3D '2018-08-10'::date) = AND (date <=3D '2018-09-01'::date) AND (((target_id =3D tc.id) AND (group_type =3D 'A'::test.group_ty= pe)) OR (source_id =3D tc.id)))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ro= ws Removed by Filter: 26
=C2=A0 =C2=A0->=C2=A0 Index Scan usin= g table_a_uq_001 on table_a ta (actual time=3D0.018..0.018 rows=3D1 loops= =3D29)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: ((table_c_id= =3D tc.id) AND (date =3D '2018-08-31'= ::date))
=C2=A0Planning Time: 5.070 ms
=C2=A0Execution = Time: 299.849 ms



=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 QUERY PLAN
----------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ----------------------------------------
=C2=A0Nested Loop Left J= oin (actual time=3D231.714..276.770 rows=3D26 loops=3D1)
=C2=A0 = =C2=A0->=C2=A0 Gather (actual time=3D231.654..295.971 rows=3D26 loops=3D= 1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Planned: 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Workers Launched: 1
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Nested Loop (actual time=3D151.209..239= .965 rows=3D13 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0->=C2=A0 Hash Join (actual time=3D0.214..14.467 rows=3D= 945 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0Hash Cond: (tc.table_d_id =3D td.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Parallel Seq Scan on table_c tc = (actual time=3D0.070..13.923 rows=3D1751 loops=3D2)
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0Filter: (table_e_id =3D 4)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Rows R= emoved by Filter: 49117
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Hash (actual time=3D0.045..0= .045 rows=3D8 loops=3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Buckets: 1024=C2= =A0 Batches: 1=C2=A0 Memory Usage: 9kB
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-&= gt;=C2=A0 Seq Scan on table_d td (actual time=3D0.028..0.033 rows=3D8 loops= =3D2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: (group = =3D 'A'::test.group)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0Rows Removed by Filter: 55
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Index Scan using table_b_idx_target_= id on table_b (actual time=3D0.235..0.238 rows=3D0 loops=3D1890)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Index Cond: (target_id =3D tc.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Filter: ((date >=3D '2018-08-10'::date) AND (date <=3D = 9;2018-09-01'::date) AND (((target_id =3D tc.i= d) AND (group_type =3D 'A'::test.group_type)) OR (source_id =3D= tc.id)))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Rows Removed by Filter:= 26
=C2=A0 =C2=A0->=C2=A0 Index Scan using table_a_uq_001 on t= able_a ta (actual time=3D0.017..0.017 rows=3D1 loops=3D26)
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: ((table_c_id =3D tc.id) AND (date =3D '2018-08-31'::date))
=C2= =A0Planning Time: 4.976 ms
=C2=A0Execution Time: 296.729 ms
=


I also made a test with:

<= /div>
SET parallel_leader_participation =3D off;
SE= T force_parallel_mode =3D on;
explain (costs false, analyze t= rue)
=C2=A0 SELECT ta.id AS table_a_= id,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tc= .id as table_c_id,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tba.id AS table_b_id
=C2=A0 FROM test.tabl= e_b_active tba
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INNER JOIN test.= table_c tc ON tba.target_id =3D tc.id
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INNER JOIN test.table_d td ON tc.table_= d_id =3D td.id
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0LEFT JOIN test.table_a ta ON ta.table_c_id =3D tc.id AND ta.date =3D
'2018-08-31' :: DATE<= /div>
=C2=A0 WHERE tba.date BETWEEN '2018-08-10' :: DATE AND &#= 39;2018-09-01' :: DATE
=C2=A0 =C2=A0 AND td.group =3D 'A&= #39;
=C2=A0 =C2=A0 AND tc.table_e_id =3D 4
=C2=A0 =C2= =A0 AND (
=C2=A0 =C2=A0 =C2=A0 (tba.target_id =3D tc.id AND tba.group_type =3D 'A')
=C2=A0 = =C2=A0 =C2=A0 OR tba.source_id =3D tc.id
=
=C2=A0 =C2=A0 );

The output is correct - 31 r= ows, but the plan is different:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN
---------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= -----------
=C2=A0Gather (actual time=3D263.880..507.668 rows=3D3= 1 loops=3D1)
=C2=A0 =C2=A0Workers Planned: 1
=C2=A0 =C2= =A0Workers Launched: 1
=C2=A0 =C2=A0Single Copy: true
= =C2=A0 =C2=A0->=C2=A0 Nested Loop Left Join (actual time=3D193.246..415.= 020 rows=3D31 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->= =C2=A0 Nested Loop (actual time=3D192.997..414.336 rows=3D31 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 H= ash Join (actual time=3D0.287..23.958 rows=3D1890 loops=3D1)
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ha= sh Cond: (tc.table_d_id =3D td.id)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0->=C2=A0 Seq Scan on table_c tc (actual time=3D0.128..23.044 rows=3D3= 501 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: (table_e_id =3D 4)<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Rows Removed by Filter: 98233
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0->=C2=A0 Hash (actual time=3D0.064..0.069 rows=3D8 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0Buckets: 1024=C2=A0 Batches: 1=C2=A0 Memory Usag= e: 9kB
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 Seq Scan on table_d td= (actual time=3D0.045..0.052 rows=3D8 loops=3D1)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: (group =3D 'A'::test.group)<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Rows Removed by Filt= er: 55
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-&g= t;=C2=A0 Index Scan using table_b_idx_target_id on table_b (actual time=3D0= .203..0.206 rows=3D0 loops=3D1890)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: (target_id =3D = tc.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: ((date >=3D '= ;2018-08-10'::date) AND (date <=3D '2018-09-01'::date) AND (= ((target_id =3D tc.id) AND (group_type =3D = 9;A'::test.group_type)) OR (source_id =3D tc.i= d)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0Rows Removed by Filter: 26
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0->=C2=A0 Index Scan using table_a_uq_001 on table_a ta = (actual time=3D0.021..0.021 rows=3D1 loops=3D31)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: ((table_c_id =3D tc.id) AND (date =3D '2018-08-31'::date))
=C2=A0Planning Time: 5.051 ms
=C2=A0Execution Time: 507.= 858 ms


On Mon, Jan 7, 2019 at 8:59 PM Thomas Munro <thomas.munro@enterprisedb.com> wrote:
On Tue, Jan 8, 2019 at 1:56 AM Bartos= z Polnik <b= artoszpolnik@gmail.com> wrote:
> I've modified the script:
> 1. I Added SET force_parallel_mode =3D on;:

What if you try that with your original query in the database that
shows the problem?=C2=A0 Or alternatively SET parallel_leader_participation=
=3D on.=C2=A0 What I'm wondering is whether the parallel worker is
consistently getting the same result, but it's a different result from<= br> the leader, and the variation comes from the race between leader and
worker, or whether the instability comes from somewhere else.

--
Thomas Munro
http://www.enterprisedb.com
--0000000000002e6569057ee51078--