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 1tU91o-00ETKg-Ju for pgsql-sql@arkaria.postgresql.org; Sat, 04 Jan 2025 18:37:40 +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 1tU91l-00CVeB-9g for pgsql-sql@arkaria.postgresql.org; Sat, 04 Jan 2025 18:37:36 +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 1tU91l-00CVdO-0h for pgsql-sql@lists.postgresql.org; Sat, 04 Jan 2025 18:37:36 +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 1tU91i-0025R1-2R for pgsql-sql@lists.postgresql.org; Sat, 04 Jan 2025 18:37:35 +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 504IbTDI640398; Sat, 4 Jan 2025 13:37:30 -0500 From: Tom Lane To: Tomasz Szypowski cc: "pgsql-sql@lists.postgresql.org" Subject: Re: View performance with implicit cast In-reply-to: References: Comments: In-reply-to Tomasz Szypowski message dated "Thu, 02 Jan 2025 20:02:05 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <640396.1736015849.1@sss.pgh.pa.us> Date: Sat, 04 Jan 2025 13:37:29 -0500 Message-ID: <640397.1736015849@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomasz Szypowski writes: > I have got an example, in which PostgreSQL could speed up: The reason why the first version of the view doesn't behave well is that it's not optimized into an "append relation", because is_simple_union_all() doesn't think that's safe: /* * is_simple_union_all * Check a subquery to see if it's a simple UNION ALL. * * We require all the setops to be UNION ALL (no mixing) and there can't be * any datatype coercions involved, ie, all the leaf queries must emit the * same datatypes. */ Perhaps this could be improved, but it's a lot easier just to add the cast yourself. regards, tom lane