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 1m5tDh-0001Sq-JJ for pgsql-general@arkaria.postgresql.org; Tue, 20 Jul 2021 17:07:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5tDg-0003SE-J7 for pgsql-general@arkaria.postgresql.org; Tue, 20 Jul 2021 17:07:48 +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 1m5tDg-0003S6-AB for pgsql-general@lists.postgresql.org; Tue, 20 Jul 2021 17:07:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5tDc-0006KC-Kh for pgsql-general@lists.postgresql.org; Tue, 20 Jul 2021 17:07:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 16KH7h8x485660; Tue, 20 Jul 2021 13:07:43 -0400 From: Tom Lane To: Nicolas Seinlet cc: "pgsql-general@lists.postgresql.org" Subject: Re: More records after sort In-reply-to: References: <368621.1626791677@sss.pgh.pa.us> Comments: In-reply-to Nicolas Seinlet message dated "Tue, 20 Jul 2021 15:07:27 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <485658.1626800863.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 20 Jul 2021 13:07:43 -0400 Message-ID: <485659.1626800863@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nicolas Seinlet writes: > Many thanks for the fast response. The full query plan is below, and the= Dalibo link points to it as well. You're right, it's a merge join. One ta= ble doesn't have up-to-date statistics, because the table is filled during= the transaction involving this query. Sure looks like incorporating an ANALYZE into the transaction would help matters. This misestimation: > -> Seq Scan on accou= nt_invoice_line il (cost=3D0.00..9885.48 rows=3D752 width=3D22) (actual t= ime=3D0.049..121.238 rows=3D150448 loops=3D1) > Filter: (displa= y_type IS NULL) looks like it's really hurting you, and "ANALYZE account_invoice_line" after loading that table ought to be enough to fix that. regards, tom lane