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 1uAEZP-00CZP6-Ab for pgsql-general@arkaria.postgresql.org; Wed, 30 Apr 2025 21:02:19 +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 1uAEZM-00GXAx-Pc for pgsql-general@arkaria.postgresql.org; Wed, 30 Apr 2025 21:02:17 +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 1uAEZM-00GXAp-Ej for pgsql-general@lists.postgresql.org; Wed, 30 Apr 2025 21:02:17 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uAEZL-000QIK-21 for pgsql-general@lists.postgresql.org; Wed, 30 Apr 2025 21:02:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 53UL29TK1400979; Wed, 30 Apr 2025 17:02:10 -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: <20250430151647.7kootztymzznydn5@victor> References: <20250430151647.7kootztymzznydn5@victor> Comments: In-reply-to Markus Demleitner message dated "Wed, 30 Apr 2025 17:16:47 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1400977.1746046929.1@sss.pgh.pa.us> Date: Wed, 30 Apr 2025 17:02:09 -0400 Message-ID: <1400978.1746046929@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Markus Demleitner writes: > So, when the SELECT statement on dfbsspec.ssa stands along in the view > definition, Postgres does the right thing; when the exact same query > stands in a UNION ALL with other tables, Postgres doesn't use the > index. Hu? It's hard to be sure when you've shown us no table definitions and only fragments of the view definitions. But I suspect what is happening here is that the view's UNIONs are causing a data type coercion of raw_spectra.pub_did before it gets to the top level of the view output. That might interfere with the planner's ability to see that the outer query's join operator is compatible with the table's index. regards, tom lane