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 1t9Eip-008aWW-K1 for pgsql-performance@arkaria.postgresql.org; Fri, 08 Nov 2024 02:27:38 +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 1t9Eim-0050qG-Te for pgsql-performance@arkaria.postgresql.org; Fri, 08 Nov 2024 02:27:37 +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 1t9Eim-0050q8-Jl for pgsql-performance@lists.postgresql.org; Fri, 08 Nov 2024 02:27:37 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t9Eij-000m6x-H5 for pgsql-performance@lists.postgresql.org; Fri, 08 Nov 2024 02:27:36 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-720cb6ac25aso1432627b3a.3 for ; Thu, 07 Nov 2024 18:27:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731032853; x=1731637653; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=ac2BvKZcDByHuhdf9NhqW58nqMl8CHv9+R20+kZu96c=; b=EWZdAwHjMgN2AF73P6GMbAYmJdE0EqW2ONkzRQXCLWBdcRZBbn5MSURUgJjUCLUKkm NR7POobxShBQuKZ0qS+/Fj6o4BXVGL09RQj2H076abeHzPPoqOwbFvVKl34eAv5zzwOD PZOlt4haolyRfmK//D5HW/VP8ebEF6GK2ATTyOO9W8uYeYQSEF7n7HzSparvc0SpnYfy oNrcOqx2g8tG5fKmW4g1QZgd7u4XMQDBX5c4Dcxr2NkofwGvHrQi4GjI4PFjOdUjRcOg MK/5DjYuJnEr1nerRnMi3LhWTNL9Yl6AT9gizMQD24gbCO2lXrDFmsQAL5ureNT/rLy9 UH6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731032853; x=1731637653; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ac2BvKZcDByHuhdf9NhqW58nqMl8CHv9+R20+kZu96c=; b=vaje7blBNH1mtw9nw8Y9bbSQt7FlRVEjhXeg1lADIV+XAY+12Ro1XPmLJ3scvIOEy5 /+upERQzM+NHgFi/QVQmeeo0DzY+WpMFzInHviBURUSdRdp/heSlNGifjB1DH9p1mrt0 D/AtAMFiKsz9LlX/7OJugCz6qJ/bcHQ4NdVcUMwsadkOkv5lRfjsuU1NT07lJ3BnHzjZ jOb5wEx4mNLloHAB4lh+nOueIehlrARA9IR8J8Z+gfjIXGBzB1/XB8xov2DHQ/MmIPKA K3jMnIyG0X40APUHpqI8ypQpcCaAXJft2umkmGSy8ZOBrcK+9A2ox1Jw4Hfa+lkg3MJu 4lvA== X-Forwarded-Encrypted: i=1; AJvYcCUSdz4b6x3AlpxVZ/0i+HGrsqLeVBvoQ7KLyxNW8z2XsaHgk17pCGvyYGWP9fHSoVvSIJC4qJKGgcxIkWAxyO6IRQ==@lists.postgresql.org X-Gm-Message-State: AOJu0Ywai/S5VM9m+pJRlxZpnKgKIpe+a/zGoGVpaf1eiVaCTt5658Ob lp3NDxOdWZREb0z4nycNGjHoCP/zhmS+egB5YHEOIQjzIa/Bch5y X-Google-Smtp-Source: AGHT+IE0xLkVBKCM4Hlvu74B1hE3qm6kW0s4bYd3P/qU1771K2XcqExVTXDfR+IPXVvWLK1nqxx68A== X-Received: by 2002:a05:6a00:148f:b0:717:8ee0:4ea1 with SMTP id d2e1a72fcca58-7241312beecmr1868832b3a.0.1731032852585; Thu, 07 Nov 2024 18:27:32 -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 d2e1a72fcca58-72407864180sm2460462b3a.11.2024.11.07.18.27.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 18:27:31 -0800 (PST) Message-ID: <2afa93b9-17d9-4bdd-bee2-f33dc12383cc@gmail.com> Date: Fri, 8 Nov 2024 09:27:28 +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 , pgsql-performance@lists.postgresql.org References: <197E1EF0-BEDF-42C0-8508-56BC6E88AA35@gmail.com> <7A0AB841-65F3-4317-905C-E98D45953E3E@gmail.com> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: <7A0AB841-65F3-4317-905C-E98D45953E3E@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 08:21, Ed Sabol wrote: > On Nov 7, 2024, at 5:18 PM, David Rowley wrote: >> It's impossible to say with the given information. You didn't mention >> which version you upgraded from to start with. > > Sorry, 15.6 to 15.7 to 15.8, but we weren't on 15.7 for very long before 15.8. > >> You can set random_page_cost for just the session you're connected to >> and try it. SET random_page_cost = ; before running >> EXPLAIN (ANALYZE, BUFFERS). > > Oh, I didn't think of that. Duh. Here it is with random_page_cost = 4.0: I see estimation errors in many places here. The second plan survived by using the Materialize node instead of repeating the execution of the inner subquery. 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 and shifted the decision to use materialisation. It looks like a game of chance and doesn't witness issues of the balance between page read cost and other operations. It is hard to say what you can use in general to avoid issues in queries of such a type except for some query-based Postgres extensions like AQO, but for now, you can try the following: I see huge underestimation in the simple scan: Bitmap Heap Scan on metainfo b_1 (cost=23.96..35.77 rows=3 width=38) (actual time=1.225..4.206 rows=1025 loops=1) It may be caused by some functional dependency in its filter: ((relation = 'located'::text) AND (type = 'document'::text)) You can create extended statistics on the columns 'relation' and 'type'. These statistics can reduce estimation errors and enable the optimiser to find a better plan without changing the cost balance. -- regards, Andrei Lepikhov