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 1tVGHn-006qdO-AW for pgsql-sql@arkaria.postgresql.org; Tue, 07 Jan 2025 20:34:47 +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 1tVGHl-0089vV-T3 for pgsql-sql@arkaria.postgresql.org; Tue, 07 Jan 2025 20:34:45 +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 1tVGHl-0089vI-KZ for pgsql-sql@lists.postgresql.org; Tue, 07 Jan 2025 20:34:45 +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 1tVGHj-000OGj-0M for pgsql-sql@lists.postgresql.org; Tue, 07 Jan 2025 20:34:44 +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 507KYei11508461; Tue, 7 Jan 2025 15:34:40 -0500 From: Tom Lane To: Tomasz Szypowski cc: "Zornoza Sanchez, Jose Blas" , "pgsql-sql@lists.postgresql.org" Subject: Re: View performance with implicit cast In-reply-to: References: <640397.1736015849@sss.pgh.pa.us> <1468967.1736261534@sss.pgh.pa.us> Comments: In-reply-to Tomasz Szypowski message dated "Tue, 07 Jan 2025 20:07:16 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1508459.1736282080.1@sss.pgh.pa.us> Date: Tue, 07 Jan 2025 15:34:40 -0500 Message-ID: <1508460.1736282080@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomasz Szypowski writes: > Thanks for the explanation, but what about the reported problem. > How can I force the view to use both indexes? You can't, because the indexes are not on the same expressions appearing in the view. Your outer WHERE clause constrains those expressions, not the underlying table columns. If it's impractical to make the underlying tables share the same column type, you would need to do something like create view v_test as select date_1 from test1 union all select date_2::timestamp from test2; create index on test2 ((date_2::timestamp)); Consider the extra index as your penance for not having thought harder about data type choices to begin with. regards, tom lane