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 1t9F8f-008dIj-I0 for pgsql-performance@arkaria.postgresql.org; Fri, 08 Nov 2024 02:54:20 +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 1t9F8c-005HsO-N3 for pgsql-performance@arkaria.postgresql.org; Fri, 08 Nov 2024 02:54:19 +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 1t9F8c-005HqQ-Be for pgsql-performance@lists.postgresql.org; Fri, 08 Nov 2024 02:54:18 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t9F8a-000jRC-4N for pgsql-performance@lists.postgresql.org; Fri, 08 Nov 2024 02:54:17 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-20cd76c513cso15978895ad.3 for ; Thu, 07 Nov 2024 18:54:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731034455; x=1731639255; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=xHY4mYEEyRa8zpPSKjEHUSGskXuoTN0aByc8iQHjKlw=; b=QzidtWyrb90DynDGkQiCQSoyPD1yiW3Yi8amAU15kWEF3iKEZfHQp2bDksaANB6jR7 QdZWk0v/FJh/6F2etWaWGyontJga0QhquhHVsUiBiiTr1eDvsXEtcS1dx4/nVtLdrFLV JiELKBfPyw4naZhXVVQHD/G3PJjj6cgBHtHPXE3ItcsckIzxk6/R0ooofzwnrbLbHNqc LnSgCkYEyrL/NvpcgVQ3n4axuky/ifOqyDfJ3pKNz/PmBJoQQYxHM3tjhst95d2UobPs keiJ/ASvOglUquvlxfuJF8vfn3NO3Hg10v5/4QMrnvniUtDmZ1fQJ/NvxB778jgIkHCx drCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731034455; x=1731639255; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xHY4mYEEyRa8zpPSKjEHUSGskXuoTN0aByc8iQHjKlw=; b=q/sESjB25iX6XnpMmk2/Mo4for44m9KRHysXsM6361iZ5SrnLGdXTDfhdkzHGbLp7A dts+HX0nRjWFPXabvLEUceTyx80LUx5gfvKFDniEYW9UvaGN3RC/vjVZcpuM2WjqFzyw 2hAz7B9LHbAF9h2Qyhg1AX2vFfA6LAwWupLQD6OzD8MAO3aX23mOsmc3Sjf5MxSv1Ee3 6Gy6A8kzKYOV2E4w4Z5kWftBbLD/SUknNsD5/Ev1JUY0Er52ygXgtWv3aavDbQ1kgSNB yomJUs1Y76qozrUDwRRxOQXV3HVcVomnoZLOqwsp4YUFPPf8l2eZCQEvsWKseWec+BfE 8y2A== X-Gm-Message-State: AOJu0Yz/TYLU5URTyAcpHIv30fPOBc/2T4M8gg6AeySDBaFb77CnI+Rd qXpBorN+QuAqbsIQwwfQolgSRupOQzQetEfbclCbU9DAWyhf8qAIx8RYwA== X-Google-Smtp-Source: AGHT+IGFVAZ4N7O6iH8zbqaRk9vUyixyAUtytj8qVvFMS1NoQJxuBnVA3RgRH+qAl3SLgOFAvgwG5Q== X-Received: by 2002:a17:902:ec90:b0:20c:f820:1ad3 with SMTP id d9443c01a7336-2118356c19cmr15542585ad.26.1731034454944; Thu, 07 Nov 2024 18:54:14 -0800 (PST) Received: from [10.10.20.106] (node-tfy.pool-101-109.dynamic.totinternet.net. [101.109.149.14]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177ddf0f5sm20349335ad.79.2024.11.07.18.54.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 18:54:14 -0800 (PST) Message-ID: Date: Fri, 8 Nov 2024 09:54:10 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Major performance degradation with joins in 15.8 or 15.7? To: Ed Sabol Cc: pgsql-performance@lists.postgresql.org References: <197E1EF0-BEDF-42C0-8508-56BC6E88AA35@gmail.com> <7A0AB841-65F3-4317-905C-E98D45953E3E@gmail.com> <2afa93b9-17d9-4bdd-bee2-f33dc12383cc@gmail.com> <2F4F210E-3BEA-4365-AB19-AC7917EF9F49@gmail.com> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: <2F4F210E-3BEA-4365-AB19-AC7917EF9F49@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/8/24 09:45, Ed Sabol wrote: > On Nov 7, 2024, at 9:27 PM, Andrei Lepikhov wrote: >> Postgres didn't want Materialize in this example because of the low estimation on its outer subquery. AFAIC, by increasing the *_page_cost's value, you added extra weight to the inner subquery > What kind of extended statistics do you suggest for this? ndistinct, dependencies, or mcv? > > CREATE STATISTICS tablename_stats () ON relation, type FROM tablename; > ANALYZE tablename; I'd recommend to use all of them - MCV is helpful in most of the cases (and relatively cheap), distinct is actually used in Postgres now to calculate number of groups (GROUP-BY, Sort, Memoize, etc.); dependencies - to find correlations between columns - usually in scan filters. -- regards, Andrei Lepikhov