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 1mAYqj-0004Ba-JF for pgsql-general@arkaria.postgresql.org; Mon, 02 Aug 2021 14:23:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mAYqi-0002zT-E8 for pgsql-general@arkaria.postgresql.org; Mon, 02 Aug 2021 14:23:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mAYqi-0002zL-4u for pgsql-general@lists.postgresql.org; Mon, 02 Aug 2021 14:23:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mAYqg-0008Px-3j for pgsql-general@lists.postgresql.org; Mon, 02 Aug 2021 14:23:23 +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 172ENGvJ1626112; Mon, 2 Aug 2021 10:23:16 -0400 From: Tom Lane To: Avi Weinberg cc: "pgsql-general@lists.postgresql.org" Subject: Re: Lazy View's Column Computing In-reply-to: References: Comments: In-reply-to Avi Weinberg message dated "Mon, 02 Aug 2021 14:12:38 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1626110.1627914196.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 02 Aug 2021 10:23:16 -0400 Message-ID: <1626111.1627914196@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Avi Weinberg writes: > Is there a way to compute a column in a view only if it is referenced in= the query? I have a view's column that its value is computed by a functi= on. If in the query that column is not used at all, can Postgres "skip" c= omputing it? If the function is not volatile, and you're using a moderately recent PG version, I'd expect the planner to do that for you. regards, tom lane