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.96) (envelope-from ) id 1vT7Ab-00DMvq-0I for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 23:31:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vT7AZ-008Ymw-2R for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 23:31:00 +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.96) (envelope-from ) id 1vT7AZ-008Ymo-1B for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 23:30:59 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vT7AX-0041tP-0y for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 23:30:58 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id D1BAB43202; Tue, 9 Dec 2025 23:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1765323049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RGI4wpoyLH3sT57pqO+3WDSznnketIXoEZCDbMh8I2w=; b=Bj/W5hUmAv2ECuCAAbjdFNHFFspar5YvaOTixwYKnsWa8BtImTMQMvgQwhb6xt8QqJjZnv DCsfHHvzTwBOMv/7aP+ePbQVxpvaDcBUUdRr9E5xK5TKuxMNyxZWJqM2DJ+8OfEGvqet3v nkS8FNUcqFh7VWWLobU2Hk0X+v++dl/L8xYVoGLGHVZ9LCDFg8VH89YjcE16l3E8zl9i5L 6+Dvig43Vjgai6Ro2niTUwKkhqHL2yIwwjc9DbCNK49TgXiCBUc+lyY5CU9fcdUSQ4qWfZ XqX6b+kbW657SPyV/BaYoLlOcYeri87IMZE9GHzneRh6iNp03MfMXoYa+mAY+A== Message-ID: Date: Wed, 10 Dec 2025 00:30:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Add a greedy join search algorithm to handle large join problems From: Tomas Vondra To: Chengpeng Yan Cc: "pgsql-hackers@lists.postgresql.org" , John Naylor References: <3FF63E99-AB4F-41A9-BC78-AAB28823FBD0@Outlook.com> <6db6d2ec-7529-4add-9a95-178fc318311d@vondra.me> <313ACE5A-CBF1-43B3-9181-10D3E8ADF424@Outlook.com> <5abd6054-413c-4f48-9172-d8b31062b266@vondra.me> Content-Language: en-US In-Reply-To: <5abd6054-413c-4f48-9172-d8b31062b266@vondra.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: tomas@vondra.me X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvtdeklecutefuodetggdotefrodftvfcurf hrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecu fedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffhvfevfh gjtgfgsehtkeertddtvdejnecuhfhrohhmpefvohhmrghsucggohhnughrrgcuoehtohhmrghssehv ohhnughrrgdrmhgvqeenucggtffrrghtthgvrhhnpeejkeegteeileeuledttdelteejieefueevke duieevjeelfedutdeifefgfffgveenucfkphepkeeirdegledrvdeftddrvddtieenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekiedrgeelrddvfedtrddvtdeipdhhvghloh eplgdutddrudefjedrtddrvdgnpdhmrghilhhfrhhomhepthhomhgrshesvhhonhgurhgrrdhmvgdp qhhiugepffduueetueegfedvtddvpdhmohguvgepshhmthhpohhuthdpnhgspghrtghpthhtohepfe dprhgtphhtthhopegthhgvnhhgphgvnhhgpgihrghnsefquhhtlhhoohhkrdgtohhmpdhrtghpthht ohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtg hpthhtohepjhhohhhntghnrgihlhhorhhlshesghhmrghilhdrtghomh List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/9/25 20:20, Tomas Vondra wrote: > On 12/2/25 14:04, Chengpeng Yan wrote: >> Hi, >> >> >> >>> On Dec 2, 2025, at 18:56, Tomas Vondra wrote: >>> >>> I think a much broader evaluation will be needed, comparing not just the >>> planning time, but also the quality of the final plan. Which for the >>> starjoin tests does not really matter, as the plans are all equal in >>> this regard. >> >> >> Many thanks for your feedback. >> >> You are absolutely right — plan quality is also very important. In my >> initial email I only showed the improvements in planning time, but did >> not provide results regarding plan quality. I will run tests on more >> complex join scenarios, evaluating both planning time and plan quality. >> > > I was trying to do some simple experiments by comparing plans for TPC-DS > queries, but unfortunately I get a lot of crashes with the patch. All > the backtraces look very similar - see the attached example. The root > cause seems to be that sort_inner_and_outer() sees > > inner_path = NULL > > I haven't investigated this very much, but I suppose the GOO code should > be calling set_cheapest() from somewhere. > FWIW after looking at the failing queries for a bit, and a bit of tweaking, it seems the issue is about aggregates in the select list. For example this TPC-DS query fails (Q7): select i_item_id, avg(ss_quantity) agg1, avg(ss_list_price) agg2, avg(ss_coupon_amt) agg3, avg(ss_sales_price) agg4 from store_sales, customer_demographics, date_dim, item, promotion where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and ss_cdemo_sk = cd_demo_sk and ss_promo_sk = p_promo_sk and cd_gender = 'F' and cd_marital_status = 'W' and cd_education_status = 'Primary' and (p_channel_email = 'N' or p_channel_event = 'N') and d_year = 1998 group by i_item_id order by i_item_id LIMIT 100; but if I remove the aggregates, it plans just fine: select i_item_id from store_sales, customer_demographics, date_dim, item, promotion where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and ss_cdemo_sk = cd_demo_sk and ss_promo_sk = p_promo_sk and cd_gender = 'F' and cd_marital_status = 'W' and cd_education_status = 'Primary' and (p_channel_email = 'N' or p_channel_event = 'N') and d_year = 1998 group by i_item_id order by i_item_id LIMIT 100; The backtrace matches the one I already posted, I'm not going to post that again. I looked at a couple more failing queries, and removing the aggregates fixes them too. Maybe there are other issues/crashes, of course. regards -- Tomas Vondra