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 1uEqNJ-00Dp8K-Pp for pgsql-general@arkaria.postgresql.org; Tue, 13 May 2025 14:12:54 +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 1uEqNI-005kpG-KO for pgsql-general@arkaria.postgresql.org; Tue, 13 May 2025 14:12:52 +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 1uEqNI-005kor-9c for pgsql-general@lists.postgresql.org; Tue, 13 May 2025 14:12:52 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uEqNF-001b1M-2Q for pgsql-general@lists.postgresql.org; Tue, 13 May 2025 14:12:51 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 54DECkvU1458990; Tue, 13 May 2025 10:12:46 -0400 From: Tom Lane To: Markus Demleitner cc: pgsql-general@lists.postgresql.org Subject: Re: Index not used in certain nested views but not in others In-reply-to: <20250512141217.4dwnfxbaf53mhvi7@victor> References: <20250430151647.7kootztymzznydn5@victor> <1400978.1746046929@sss.pgh.pa.us> <91e617539ff887f1aac4e27bf1481b51fcf4b131.camel@cybertec.at> <20250512141217.4dwnfxbaf53mhvi7@victor> Comments: In-reply-to Markus Demleitner message dated "Mon, 12 May 2025 16:12:17 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3846.1747145566.1@sss.pgh.pa.us> Date: Tue, 13 May 2025 10:12:46 -0400 Message-ID: <3847.1747145566@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Markus Demleitner writes: > You see, when creating the "big", 30-tables view, I do cast all > columns to common types in the view statement that actually make up > the view. The original SQL fragments look like this: > SELECT > CAST(ssa_dstype AS text) AS dataproduct_type, > CAST(NULL AS text) AS dataproduct_subtype, > CAST(2 AS smallint) AS calib_level, > ... > and have a common source, so I'd believe by the time the things end > up in the view, they should type-align even though their source > tables do not. Oh, well, that's your problem. The source tables' column types need to match. Otherwise the UNIONs don't get flattened and you don't get indexscans. regards, tom lane