Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jIxOh-0006pd-Qk for pgsql-performance@arkaria.postgresql.org; Mon, 30 Mar 2020 16:36:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jIxOg-0005uw-Gj for pgsql-performance@arkaria.postgresql.org; Mon, 30 Mar 2020 16:36:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jIxOg-0005sw-9K for pgsql-performance@lists.postgresql.org; Mon, 30 Mar 2020 16:36:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jIxOe-0007zE-6h for pgsql-performance@lists.postgresql.org; Mon, 30 Mar 2020 16:36:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 02UGaHtZ019894; Mon, 30 Mar 2020 12:36:17 -0400 From: Tom Lane To: Pavel Stehule cc: Silvio Moioli , Pgsql Performance Subject: Re: Increasing work_mem slows down query, why? In-reply-to: References: <79dd683d-3296-1b21-ab4a-28fdc2d98807@suse.de> <6d829078-b34a-ca4d-909a-5427aa22ae47@suse.de> <18262.1585584121@sss.pgh.pa.us> Comments: In-reply-to Pavel Stehule message dated "Mon, 30 Mar 2020 18:18:17 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19892.1585586177.1@sss.pgh.pa.us> Date: Mon, 30 Mar 2020 12:36:17 -0400 Message-ID: <19893.1585586177@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Pavel Stehule writes: > CTE scan has only 1100 rows, public.rhnpackagecapability has 490964 rows. > But planner does hash from public.rhnpackagecapability table. It cannot be > very effective. [ shrug... ] Without stats on the CTE output, the planner is very leery of putting it on the inside of a hash join. The CTE might produce output that ends up in just a few hash buckets, degrading the join to something not much better than a nested loop. As long as there's enough memory to hash the known-well-distributed table, putting it on the inside is safer and no costlier. regards, tom lane