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 1uc0Fz-007pqC-Ak for pgsql-performance@arkaria.postgresql.org; Wed, 16 Jul 2025 11:25:08 +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 1uc0Fw-009Xph-4O for pgsql-performance@arkaria.postgresql.org; Wed, 16 Jul 2025 11:25:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with utf8esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uc0Fv-009XpZ-QS for pgsql-performance@lists.postgresql.org; Wed, 16 Jul 2025 11:25:00 +0000 Received: from facteur.thefreecat.org ([212.129.38.6]) by magus.postgresql.org with utf8esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uc0Ft-0083AP-2p for pgsql-performance@lists.postgresql.org; Wed, 16 Jul 2025 11:24:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thefreecat.org; s=thefreecat; t=1752665094; bh=Fm7krE40hJ0fLtRaDIOv5Hd1GGv/rwOlUh8Ya1MoyAY=; h=Date:Subject:To:References:From:In-Reply-To; b=DhAXqZbiln74z8B0+Xs9cktuMZ+o/eeGM9KGipwFmb2eWaDVchkSpj5R8x8n2jg0i lSGb170jcYwADQpFqCDn+xQkUli76Q8wIVUHgv5YdUTvWrPx8VQUOw/nN0iXU9f3M4 qVF4y4h1teX5wclDRX90u0fRRHpVwyH5Fsk0iMu/iMiAi6x1/Y+f4uvF5UK0+ Original-Subject: Re: Any way to get nested loop index joins on CTEs? Original-From: Jean-Christophe BOGGIO Received: from [192.168.1.25] (lmontsouris-656-1-93-81.w82-127.abo.wanadoo.fr [::ffff:82.127.255.81]) (AUTH: LOGIN cat, TLS: TLS1.3,128bits,ECDHE_RSA_AES_128_GCM_SHA256) by facteur.thefreecat.org with ESMTPSA id 0000000009DC06D4.0000000068778C06.0013D7D3; Wed, 16 Jul 2025 13:24:54 +0200 Message-ID: Date: Wed, 16 Jul 2025 13:24:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Any way to get nested loop index joins on CTEs? To: pgsql-performance@lists.postgresql.org References: Content-Language: en-US, fr From: Jean-Christophe BOGGIO In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Following up on this, I very often have to create PLPgSql functions to workaround this problem: create one (or several) temp table(s) (with ON COMMIT DROP), analyze it/them and create indices on some field(s). Being able to write something like: WITH xxx AS MATERIALIZED ANALYZED INDEXED ON field1 (     SELECT DISTINCT myfield AS field1     FROM table1 ) SELECT field2 FROM table2 JOIN xxx USING(field1); would help a lot in some cases. Of course, the syntax is just a thought but the general idea is there.