Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfyhi-0004l1-C3 for pgsql-performance@arkaria.postgresql.org; Thu, 28 Oct 2021 06:15:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfyhg-0004Wy-Vz for pgsql-performance@arkaria.postgresql.org; Thu, 28 Oct 2021 06:15:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfyhg-0004Wp-N8 for pgsql-performance@lists.postgresql.org; Thu, 28 Oct 2021 06:15:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfyhe-0005VT-Bf for pgsql-performance@lists.postgresql.org; Thu, 28 Oct 2021 06:15:55 +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 19S6Fq3Y309713; Thu, 28 Oct 2021 02:15:52 -0400 From: Tom Lane To: Tim Slechta cc: pgsql-performance@lists.postgresql.org Subject: Re: Views don't seem to use indexes? In-reply-to: References: Comments: In-reply-to Tim Slechta message dated "Wed, 27 Oct 2021 21:31:00 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <309711.1635401752.1@sss.pgh.pa.us> Date: Thu, 28 Oct 2021 02:15:52 -0400 Message-ID: <309712.1635401752@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tim Slechta writes: > Why does the planner not use an index when a view is involved? It's not about a "view" ... you'd get the same results if you wrote out the UNION ALL construct in-line as a sub-select. I think you may be shooting yourself in the foot by not making sure that the UNION ALL arms match in data type. You did not show us the definition of pworkspaceobject, but if pworkspaceobject.pobject_name isn't of type text (maybe it's varchar?) then the type mismatch would prevent pushing down a condition on that column. The source code says: * For subqueries using UNION/UNION ALL/INTERSECT/INTERSECT ALL, we can * push quals into each component query, but the quals can only reference * subquery columns that suffer no type coercions in the set operation. * Otherwise there are possible semantic gotchas. I'm too tired to reconstruct an example of the semantic issues... regards, tom lane