Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9VJJ-0002hO-KL for pgsql-general@arkaria.postgresql.org; Tue, 09 Feb 2021 15:52:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l9VJI-0006N4-IR for pgsql-general@arkaria.postgresql.org; Tue, 09 Feb 2021 15:52:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9VJI-0006M5-7D for pgsql-general@lists.postgresql.org; Tue, 09 Feb 2021 15:52:16 +0000 Received: from mail.am-soft.de ([83.218.36.120]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9VJF-0007Ak-9t for pgsql-general@lists.postgresql.org; Tue, 09 Feb 2021 15:52:15 +0000 Received: from mail.am-soft.de (localhost [127.0.0.1]) by mail.am-soft.de (Postfix) with ESMTP id 2671D35FB4F7; Tue, 9 Feb 2021 16:52:11 +0100 (CET) Received: from Bit02EX.bitstoregruppe.local (exchange01.bitstore.group [116.202.141.225]) by mail.am-soft.de (Postfix) with ESMTPA id 1307D35FB4F5 for ; Tue, 9 Feb 2021 16:52:11 +0100 (CET) Received: from tschoening-nb.fritz.box (77.78.163.99) by Bit02EX.bitstoregruppe.local (192.168.254.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Tue, 9 Feb 2021 16:51:17 +0100 Date: Tue, 9 Feb 2021 16:52:02 +0100 From: =?utf-8?B?VGhvcnN0ZW4gU2Now7ZuaW5n?= Organization: AM-SoFT IT-Service - Bitstore Hameln GmbH i.G. Message-ID: <767344739.20210209165202@am-soft.de> To: Subject: How does Postgres decide if to use additional workers? MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [77.78.163.99] X-ClientProxiedBy: Bit02EX.bitstoregruppe.local (192.168.254.21) To Bit02EX.bitstoregruppe.local (192.168.254.21) X-C2ProcessedOrg: e1a4acb5-ea26-4a8f-9559-e23e579650e8 X-AV-Checked: ClamAV using ClamSMTP List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi all, I have the following table with an added BTREE-index on "captured_at". > CREATE TABLE datagram > ( > id bigserial NOT NULL, > src_re integer NOT NULL, > src_clt integer NOT NULL, > src_meter integer NOT NULL, > captured_at timestamp with time zone NOT NULL, > captured_rssi smallint NOT NULL, > oms_status smallint NOT NULL, > oms_enc bytea, > oms_dec bytea > ); I have a query containing the following condition: > AND "datagram"."captured_at" BETWEEN (CAST('2020-08-28T10:34:32.855+02:00= ' AS TIMESTAMP WITH TIME ZONE) - CAST('P5D' AS INTERVAL)) AND (CAST('2020-0= 8-28T10:34:32.855+02:00' AS TIMESTAMP WITH TIME ZONE) + CAST('P0D' AS INTER= VAL)) When that query is applied to the above table with it's index on "captured_at", that results in the following query plan. The important thing to note is that NO parallel workers a re used. > -> Hash Join (cost=3D246164.35..2004405.07 rows=3D11323 width=3D51) (ac= tual time=3D93.802..5776.755 rows=3D104607 loops=3D1) > Hash Cond: (meter.meter_bcd =3D meter_bcd.id) > -> Hash Join (cost=3D246019.19..2003889.83 rows=3D68494 width=3D37)= (actual time=3D93.067..5744.787 rows=3D104607 loops=3D1) > Hash Cond: (datagram.src_meter =3D meter.id) > -> Index Scan using idx_datagram_captured_at_btree on datagram = (cost=3D0.57..1756571.73 rows=3D495033 width=3D20) (actual time=3D0.054..54= 51.417 rows=3D514369 loops=3D1) > Index Cond: ((captured_at >=3D ('2020-08-28 10:34:32.855+02= '::timestamp with time zone - '5 days'::interval)) AND (captured_at <=3D ('= 2020-08-28 10:34:32.855+02'::timestamp with time zone + '00:00:00'::interva= l))) For various reasons I tested the above table as a partitioned one as well, with individual partitions containing the rows of one year only. The important thing to note is that I simply kept the same index on "captured_at" like before, though the query plan looks different now: > Workers Planned: 2 > Workers Launched: 2 > -> Hash Join (cost=3D245966.53..272335.67 rows=3D5419 width=3D51) (actu= al time=3D625.846..1560.103 rows=3D34869 loops=3D3) > Hash Cond: (datagram_y2020_h2.src_meter =3D meter.id) > -> Parallel Append (cost=3D4.19..25430.72 rows=3D236911 width=3D20)= (actual time=3D2.827..863.298 rows=3D171456 loops=3D3) > Subplans Removed: 23 > -> Parallel Index Scan using datagram_y2020_h2_captured_at_idx= on datagram_y2020_h2 (cost=3D0.44..24051.22 rows=3D236888 width=3D20) (ac= tual time=3D2.826..848.388 rows=3D171456 loops=3D3) > Index Cond: ((captured_at >=3D ('2020-08-28 10:34:32.855+= 02'::timestamp with time zone - '5 days'::interval)) AND (captured_at <=3D = ('2020-08-28 10:34:32.855+02'::timestamp with time zone + '00:00:00'::inter= val))) It seems that only because of a different number of rows per individual table, additional workers are used. Though, in the past I had all of those "captured_at" in one table as well, only with far less columns and for that table additional workers have been used, pretty much like is the case now: > Workers Planned: 2 > Workers Launched: 2 > -> Hash Join (cost=3D264793.42..1666293.23 rows=3D4332 width=3D51) (act= ual time=3D96.080..638.802 rows=3D34869 loops=3D3) > Hash Cond: (oms_rec.meter =3D meter.id) > -> Nested Loop (cost=3D1.14..1400747.39 rows=3D189399 width=3D20) (= actual time=3D0.145..496.366 rows=3D171456 loops=3D3) > -> Hash (cost=3D264709.53..264709.53 rows=3D6620 width=3D39) (actua= l time=3D95.521..95.528 rows=3D40044 loops=3D3) > Buckets: 65536 (originally 8192) Batches: 1 (originally 1) Me= mory Usage: 3016kB > -> Parallel Index Scan using idx_clt_rec_captured_at on clt_re= c (cost=3D0.57..14853.95 rows=3D189399 width=3D24) (actual time=3D0.098..8= 1.556 rows=3D171456 loops=3D3) > -> Index Scan using pk_oms_rec on oms_rec (cost=3D0.57..7.32 = rows=3D1 width=3D12) (actual time=3D0.002..0.002 rows=3D1 loops=3D514369) > -> Hash Join (cost=3D145.59..264709.53 rows=3D6620 width=3D39= ) (actual time=3D9.883..86.390 rows=3D40044 loops=3D3) > Index Cond: (id =3D clt_rec.oms_rec) > Index Cond: ((captured_at >=3D ('2020-08-28 10:34:32.855+= 02'::timestamp with time zone - '5 days'::interval)) AND (captured_at <=3D = ('2020-08-28 10:34:32.855+02'::timestamp with time zone + '00:00:00'::inter= val))) > Hash Cond: (meter.meter_bcd =3D meter_bcd.id) So, based on which facts does Postgres decide if to use aadditional workers or not? Can I see those decisions explained somewhere? I don't see anything in the query plan. Thanks! Mit freundlichen Gr=C3=BC=C3=9Fen Thorsten Sch=C3=B6ning --=20 Thorsten Sch=C3=B6ning AM-SoFT IT-Service - Bitstore Hameln GmbH i.G.=C2=A0ist ein Mitglied der Bi= tstore Gruppe - Ihr Full-Service-Dienstleister f=C3=BCr IT und TK E-Mail: Thorsten.Schoening@AM-SoFT.de Web: http://www.AM-SoFT.de/ Telefon: 05151- 9468- 0 Telefon: 05151- 9468-55 Fax: 05151- 9468-88 Mobil: 0178-8 9468-04 AM-SoFT IT-Service - Bitstore Hameln GmbH i.G., Brandenburger Str. 7c, 3178= 9 Hameln AG Hannover HRB neu - Gesch=C3=A4ftsf=C3=BChrer: Janine Galonska F=C3=BCr R=C3=BCckfragen stehe ich Ihnen sehr gerne zur Verf=C3=BCgung. Mit freundlichen Gr=C3=BC=C3=9Fen Thorsten Sch=C3=B6ning Tel: 05151 9468 0 Fax: 05151 9468 88 Mobil:=20 Webseite: https://www.am-soft.de=20 AM-Soft IT-Service - Bitstore Hameln GmbH i.G.=C2=A0ist ein Mitglied der Bi= tstore Gruppe - Ihr Full-Service-Dienstleister f=C3=BCr IT und TK AM-Soft IT-Service - Bitstore Hameln GmbH i.G. Brandenburger Str. 7c 31789 Hameln Tel: 05151 9468 0 Bitstore IT-Consulting GmbH Zentrale - Berlin Lichtenberg Frankfurter Allee 285 10317 Berlin Tel: 030 453 087 80 CBS IT-Service - Bitstore Kaulsdorf UG Tel: 030 453 087 880 1 B=C3=BCro Dallgow-D=C3=B6beritz Tel: 03322 507 020 B=C3=BCro Kloster Lehnin Tel: 033207 566 530 PCE IT-Service=C2=A0- Bitstore Darmstadt UG Darmstadt Tel: 06151 392 973 0 B=C3=BCro Neuruppin Tel: 033932 606 090 ACI EDV Systemhaus Dresden GmbH Dresden Tel: 0351 254 410 Das Systemhaus - Bitstore Magdeburg GmbH Magdeburg Tel: 0391 636 651 0 Allerdata.IT - Bitstore Wittenberg GmbH Wittenberg Tel: 03491=C2=A0876 735 7 B=C3=BCro Liebenwalde Tel: 033054 810 00 HSA - das B=C3=BCro - Bitstore Altenburg UG Altenburg Tel: 0344 784 390 97 Bitstore IT =E2=80=93 Consulting GmbH NL Piesteritz=20 Piesteritz Tel: 03491 644 868 6 Solltec IT-Services - Bitstore Braunschweig UG Braunschweig Tel: 0531 206 068 0 MF Computer Service - Bitstore G=C3=BCtersloh GmbH G=C3=BCtersloh Tel: 05245=C2=A0920 809 3 Firmensitz: MF Computer Service - Bitstore G=C3=BCtersloh GmbH, Gildestra= =C3=9Fe 25, 33442 Herzebrock-Clarholz Gesch=C3=A4ftsf=C3=BChrer Janine Galonska