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 1qRwma-003hgn-Cf for pgsql-performance@arkaria.postgresql.org; Fri, 04 Aug 2023 15:32:04 +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 1qRwmX-008pZW-MI for pgsql-performance@arkaria.postgresql.org; Fri, 04 Aug 2023 15:32:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qRwmX-008pZO-CE for pgsql-performance@lists.postgresql.org; Fri, 04 Aug 2023 15:32:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qRwmV-000Yqz-G4 for pgsql-performance@postgresql.org; Fri, 04 Aug 2023 15:32:01 +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 374FVvwI3661333; Fri, 4 Aug 2023 11:31:57 -0400 From: Tom Lane To: Dane Foster cc: psql-performance Subject: Re: Plan weirdness. A sort produces more rows than the node beneath it In-reply-to: References: <3658472.1691161821@sss.pgh.pa.us> Comments: In-reply-to Dane Foster message dated "Fri, 04 Aug 2023 11:15:40 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3661331.1691163117.1@sss.pgh.pa.us> Date: Fri, 04 Aug 2023 11:31:57 -0400 Message-ID: <3661332.1691163117@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dane Foster writes: >> If the sort is the inner input to a merge join, this could reflect >> mark-and-restore rescanning of the sort's output. Are there a >> whole lot of duplicate keys on the merge's other side? > Yes. The course_id column's values repeat a LOT on the merge side. Hmm. The planner should avoid using a merge join if it knows that to be true. Maybe analyze'ing that table would prompt it to use some other join method? regards, tom lane