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 1vuvaL-00DFOD-1j for pgsql-performance@arkaria.postgresql.org; Tue, 24 Feb 2026 16:48:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vuvaJ-002Is5-1a for pgsql-performance@arkaria.postgresql.org; Tue, 24 Feb 2026 16:48:31 +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 1vuvaJ-002Irx-0B for pgsql-performance@lists.postgresql.org; Tue, 24 Feb 2026 16:48:31 +0000 Received: from mout.gmx.net ([212.227.15.18]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vuvaF-00000000zD3-22d9 for pgsql-performance@postgresql.org; Tue, 24 Feb 2026 16:48:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1771951706; x=1772556506; i=atiware@gmx.net; bh=DZlbiaU01nWZy64Tr8VdwqyRdmSxhDy5yNVDIbsuN1M=; h=X-UI-Sender-Class:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id: References:To:cc:content-transfer-encoding:content-type:date:from: message-id:mime-version:reply-to:subject:to; b=Q5Jcd7S2jzzCPCgvI7y2yunZRfmoMqEA6XdackbTe190QJrSRDFmSVDiSMfxA/TE ku2ymlnjxSWwmPFnTd4uQDT6KG6Ye1b0fD/9tDLZtSMFEPboCPW9fwvyy8C1QE+iz BG/nu+SwzY0v8COb6zcVIW121vbSUQUGxhEDqRRlBSzqBmbRkfxGAPpFbNkPuexaA zKeQkYGUMqF9J2hlTsCXen1x4A4WdgyTVSIJnqCYbXdliXoJ81q456bvP3kE9ST1p cUy+bwWVJ8JCzqLzQF78lIRgGs7apLEthkoYSmxuTDHhQtL5XGEzJBIurVunVwBfA LtveTWUvANoWmvwiog== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from client.hidden.invalid by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M6DWs-1voJs21h60-00En2I; Tue, 24 Feb 2026 17:48:26 +0100 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: unstable query plan on pg 16,17,18 From: Attila Soki In-Reply-To: <0c8b9845-a2ac-4613-8075-45dc55911143@gmail.com> Date: Tue, 24 Feb 2026 17:48:15 +0100 Cc: pgsql-performance@postgresql.org, Laurenz Albe Content-Transfer-Encoding: quoted-printable Message-Id: <45AA83DB-A6B4-43A2-879B-290E4A7845AE@gmx.net> References: <64ddfe83-317c-4cf1-b04f-cb74d9f40629@gmail.com> <529E2365-6C3F-4BDA-9625-312F3A023C5B@gmx.net> <5bace3e5-3d6b-4f81-92a9-9ff4e9e5de53@gmail.com> <1C445A2F-3256-4F04-B55D-9850581FF39A@gmx.net> <0dd76506-053e-4a30-9f95-9dc324e8e1fb@gmail.com> <1388B912-7E9A-475A-93AA-67FB99A084BC@gmx.net> <0c8b9845-a2ac-4613-8075-45dc55911143@gmail.com> To: Andrei Lepikhov X-Mailer: Apple Mail (2.3864.400.21) X-Provags-ID: V03:K1:quIIfDQLrz9YVszrQIxOtqpATPvXIR10K01gf4AKk8h0jULYJDp 7ZSmRznWOjTUiK91dgDQyR1BfdH1XF+CSg+2mg9fhCycbMTK+ZwLWYLFGpnzYdUvfFXS4pf T7SYvQZEJNgO1BRivRAhMrbdm4QI52xI/FT2gbcmgrH8rmxQ0v+DpfsR5sC3umqSGpZknYP qVwXkD81lWwRY9u+FWhh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icLoHIVR1NuW3aIpQ5aN01sdzCCid6g4amgQau/uCVo3eLKCcRMPPmEMxZ 7P3c6FBkcjEaG7t7dJDEkggi8zakckTpVOurnWC2bSzkvJkkbiXuXV5oJueaYTmS210jhOvh7 rgW+JeVmFg/LmBvLAYTuHsdqpMVOnN8lFfwH8UprTNZKCSW3Iy7rl9KDakz3HFIayKU87AkM8 ZO+7NhGEKz2tZGZ7Yp2bKUx5f2PscQFbGATZpYFivXcSczG5ILQt0YxaYbcvRRM6RFghHpQ9e jLct0g3h5NzUHKUHHXTMivpbMlxZsp6Lm9eg/alEGLnYX/DvN0BM31SGd43lfqdMUF/zzQmPs WH3drL/OzOiXsBfB+a3DQr1tS5lc8lrcf4ShwOFsLw9qCEP4AahQ+CxipaLi5Kei2zYqjPXR6 yjd4lKfsW2Qh71Rtp+h5bp6rGm5RVAJqeyzXGh1cc+SZ5e1eATXLTC80HaRiwu38hmW8HDFvW MRZaUG0zynOmpmMBzar3W8dY9bUhOW1eUXcWcgJykI4Bhg3yndg7O13RtCN31DNj0TupUD7wG k8+ROvXbH1b1UUxQ8JW3bU8mg0vTm/SJQDQ4YyFGy6u5fI65iMMviihdFQyAvQC8iQMFAFud/ UWjGggHiPe3zi+YChmakSdJG7M2sQZBj7Mbpsds1cThkQTqEZjKJ+ff6sxW/fSHOP5dJB6H51 aeXknm8Fppj37xsIg933HVbvXcHzpr1uZ871zEHiMvnR4RWxkFHI+lP5RhmjHjfGMDMosZ89C WNZzFItHFzNCBZuiaN1VROuZRILYTT3KmH3n4a4Nv7h4kAkvPY7uipEH/twNt2NjrGu7iHDdl 1AhxKXJvjOa7CwVOfVGeUF7vSxSaFYxxYS7vX4x2pcyQmWSf8JqS2e5XwSQRNbASHDe2tqZSz DR2JsXn7fMDRWRIE4= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 24 Feb 2026, at 16:57, Andrei Lepikhov wrote: >=20 > On 24/2/26 16:50, Attila Soki wrote: >> Now with join_collapse_limit=3D7 works for me and I am not able to = flip the plan. makes that sense? >=20 > It is almost a game of chance. But if it solves your problem - why not = ;)? >=20 >> should I still test with increased statistic on table_k.dp_end_dat as = Laurenz suggested? >=20 > Yes, it may provide us additional info for developing. ok i try that and come with more info. Should I set join_collapse_limit back to default for this test? >=20 >> I could now share some general infos about the query, if you still = interested. > Yes, we still have a problem. So, any additional info that can let us = build a repro is appreciated. The query involves many tables, views, functions and data. Maybe we can = build something simpler to reproduce the problem. I still checking whether it is okay to share the SQL. Until then, here = are some general details. It is basically a per order report on the availability of the inventory = for a rental service. Striped down, it builds an in memory calendar and calculates some sums = for overlapping time periods, where some of the time periods has no end. = (delayed return: late) There are projects (table_e), the project has several orders (table_a). = The order has a renting period, measured in days between start and end. The period is not limited but somewhere between 1 - 365, usually between = 5-15 days. An order can have multiple quotes (auf_oos), but only one of them is = active at a time. A quote lists multiple items (table_k). Usually 10-500 items per quote, = where an item can have one or more accessories tied to it. This list is the customer's order. There is also a helper table that stores one row for each day of the = order: (table_a_dtg) table_a.id and a date. In this table 5 day rental = order has 5 rows. (this is stored on disk and maintained via trigger, = because using generate_series was too slow). There is a list of possible products/items (table_s), which stores the = company's own portion of the inventory. The other portion of the = inventory can be temporarily held (rented long-term) and is stored in = (al_ast). Another portion of the inventory may come from other suppliers as = needed. These stock items are rented for the order and are tied to it. = The rent-order is located in al_zm, and the rent-order's item list is in = al_zm_kal. In addition, there are items that were not returned on time, were lost, = or are temporarily blocked due to repairs. This renders the stock level = of a future day-x not predictable. The items required for a quote are manually allocated from one of the = three possible sources. This allocation is stored in table_k. The info that the rented items are fully or partly returned is also = stored in table_k. The primary function of this query is to list one row per quote, with = multiple flags indicating the various possible summarized states of the = quote. It also computes the total volume and weight of the order. Some of the flags indicates various working phases or possible conflict = states. For example when inventory levels are insufficient, configured as = "fulfilled from stock" but there is not enough items on stock, when = items are configured as "fulfilled from rental" but no rental order has = been placed, or the rental order has not the right amount of items, or = when the required items are not returned as planned, or are returned = damaged or are lost. Because of resource limits, the flags are built only for quotes where = the renting period includes a date between now and now+3 months. To achieve this, the query builds a stock availability report for all = items of the quotes on the fly for each item/day. gauf_1 is table_a in a view is where an item stored in table_k will be = combined with the rental period and so gets one row for each day for the = rental period. This row is representing the required stock quantity per = day for that and order. These rows building the base of this query and will be combined to build = the daily overall demand and state. the view is simple: select ... from table_a_dtg gdt -- one row per order_rental_date, eg. 5 rows for a = 5 days rental left join table_a gauf on gauf.id=3Dgdt.au_id -- one row per order left join auf_oos goftr on goftr.au_id=3Dgauf.id -- one row per quote left join table_k gkal on gkal.oo_id=3Dgofrt.id -- one row per quote = item where gdt.datum >=3D ('now'::text::date - '7 days'::interval)::date; eg. a 3 day rental order with 2x1 items gets 6 rows order1, item1, day1, 1 pcs order1, item1, day2, 1 pcs order1, item1, day3, 1 pcs order1, item2, day1, 1 pcs order1, item2, day2, 1 pcs order1, item2, day3, 1 pcs I can provide more details on other parts of the query too, if that = helps. regards, Attila