Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1szhbZ-007XuY-Vo for pgsql-general@arkaria.postgresql.org; Sat, 12 Oct 2024 19:16:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1szhbY-008uu3-B8 for pgsql-general@arkaria.postgresql.org; Sat, 12 Oct 2024 19:16:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1szhbY-008utX-05 for pgsql-general@lists.postgresql.org; Sat, 12 Oct 2024 19:16:44 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1szhbV-000YwI-9y for pgsql-general@lists.postgresql.org; Sat, 12 Oct 2024 19:16:43 +0000 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3e4eabe3779so141956b6e.3 for ; Sat, 12 Oct 2024 12:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728760600; x=1729365400; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=E7Z0f8GSsZecqUmTdH76EbTTWEfdKB7cFOufbpRVxXs=; b=EYpDQ0Qd4mvaSYvteqSYigRAgIX+ztH936LQ2TjI37G1t0CpmWd24mcWWuTza4/H+Q wkxrKal4/EHEkNsvrvSmmDeBLu+lM2H3tFq52AbijsYKk+vsrvUkoII1SEP0zbizbn+v djr8G30uFxCo5Iz/35EjD9riS6b0jdZlfOMgrhnWVH/EejY5W/yN973X7CIXvDD2U5Ar XS6OQ3Ruw5mEogGJspoOr5GdNQARFkmO/h7S/zmEWp6UQ/aFKjwrsfCB6qsgPQ+ctbA6 kwtm1r8iYNsdCb8JY4jvwhXpq7Dk7jv+EM0PQTZB6Ko+Qv65QdLv5vf2Ql6AWC4XirW6 +YxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728760600; x=1729365400; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E7Z0f8GSsZecqUmTdH76EbTTWEfdKB7cFOufbpRVxXs=; b=HP69myaZuBmlRnjh2v3RV1OgW7Meh7Q1G6vm515xDG9daSUGkvebodmgYjvwCJcSwW RuPGUv6fXNgibGKqN66jEUMNWyxdz/kBxqaEi9k54lGNLmioLo/PPzm8yESIqqiGDFrB eUW84fTob7I90w/8QxdIQKti1EUoXHP6zlDpG5TVwFd/gb66R6XoYtKawER5wLZnGSnX wJgqoV+1diskagVUl4zhVp52UYFghD3pJ+xw+ZxUAl+gEIADCLQkO6IGoIls3G8oA4Oi rZYPTdpMoOPGP7Pnosy3SQ1IAy9mlBC9QPQcKVAuiCcvxmd/WlraMLFPY1WwIKR11Jvh UQIg== X-Gm-Message-State: AOJu0YxKWOFu4Dou40PVn3HKRHvlhAjajjgGQXiedUx6RF8n0RfuK5t4 VmQdxG4R+LDTBkmTG49ji6b+XKj/RQOoEN6K88jPhgm5slG4E2AecI34JwSf3fYzIZBp59OW47L JiERMYBVAwPwMfFydsKekCzYTEsk= X-Google-Smtp-Source: AGHT+IEdFFXACPMBDH46vOTBPw3hUKI+OGNh2VBt1vZp78JqGarwbIe4h1Sr5zUd+p98ZmGH55tIDGRPbFyGU36UTEA= X-Received: by 2002:a05:6870:d204:b0:27b:9f8b:277b with SMTP id 586e51a60fabf-2886e0cfb54mr1167958fac.14.1728760600070; Sat, 12 Oct 2024 12:16:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Thomas Munro Date: Sun, 13 Oct 2024 08:16:04 +1300 Message-ID: Subject: Re: Naive question about multithreading/multicore To: Marc SCHAEFER Cc: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Oct 13, 2024 at 6:31=E2=80=AFAM Marc SCHAEFER wrote: > template1=3D> SELECT COUNT(*) FROM pg_class a, pg_class b, pg_class c; > > I see only one 100% CPU PostgreSQL process. If you set set min_parallel_table_scan_size =3D 0 then it uses parallelism, and completes much faster. The planner generally works by comparing the estimated cost of various plans (it is a "cost based" optimiser), but the decision to actually consider parallelism at all is essentially "rule based", and the rules aren't smart enough for this query with default settings. pg_class is considered too small to bother parallelising the scan, and here you have a 3-way cross-join which generates an enormous of work for each tuple so it is actually a good idea to parallelise it. I guess people don't actually do that too often.