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 1snXYx-004IOQ-12 for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2024 06:07:48 +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 1snXXy-006p6g-GK for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2024 06:06:46 +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 1snXXy-006p6Y-6P for pgsql-hackers@lists.postgresql.org; Mon, 09 Sep 2024 06:06:46 +0000 Received: from fhigh6-smtp.messagingengine.com ([103.168.172.157]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1snXXu-000FgQ-Lu for pgsql-hackers@postgresql.org; Mon, 09 Sep 2024 06:06:45 +0000 Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7B22811401D2; Mon, 9 Sep 2024 02:06:42 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Mon, 09 Sep 2024 02:06:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm3; t=1725862002; x=1725948402; bh=mWc+H54IEMPzzEAfMx+/BmVCPVi65Bej QDC5TEvR9ls=; b=sQTvGBTPmkcroAT9dgectxKlw6A/reuE99ApUo57fH98Vi+L 7m0EOCBe3TpHlsN9e9jkJqJZH64NgETHUpz9HsLRmUuisSGWVpr3EaX4FWd6xNhU W2Q1LDrhxnJGw4veZV8FAx98YOClcNVBAGCk/jBChiUbjunHebxpiwNKPKWNfVZU yslPonT5ZTJ/nNzs0s08/8xo9Gh8TAd3opGTOgIrLdOjjdTKwoWahtgwDFcQveeF /6v0g4L/B37MkFPjU8ei31QE+TreDky3C6OlCmmVkeL6k9rMWNUW1ps6EF7whQPU la7VRf7wbetNR3SCTo+JDDZdOeQ7T5fL8mRaJg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725862002; x= 1725948402; bh=mWc+H54IEMPzzEAfMx+/BmVCPVi65BejQDC5TEvR9ls=; b=h G9KOz0juoPVDzTBTT/0OcvPhDjHOZ0jZdrc3QJz6ejSlOhHU/5v4xqAdAEcwxVcO NNvPCVqn2L8wBO06e6GNfve0a92GB3Cg5tZEwyuUR+9w4iF+OwigLKPct7PI30B9 xESjR1XU3rQ/3UqOdDjD0KrkSWdPxkd8WGiRcpD2iVHiMcxW+zcyQBHpOJ8uMUIL bJ6/tZ4Kf0YX7fs5IPSZA8hQWAXKbzLavVRh2R4RmCBRRsoPE9K442Uw/T5o9YeK DWbIpyiqTeBVGnRYzNyj0xDE5yNkZSwVoTps1gPIMkIixeQjGxPdCS7CKAcT3wvO 3ukKu4zwwbfSin238Vs5w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeiiedgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdej necuhfhrohhmpefrvghtvghrucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvg hnthhrrghuthdrohhrgheqnecuggftrfgrthhtvghrnhepjefhveehtdetgfffhffhfeef gffghffflefgieeuueekhedvhedvfeehffdvfeeunecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdho rhhgpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hjihgrnhdruhhnihhvvghrshgrlhhithihsehgmhgrihhlrdgtohhmpdhrtghpthhtohep uggvrghnrdgrrdhrrghshhgvvggusehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgsh hqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Sep 2024 02:06:41 -0400 (EDT) Message-ID: <1841bdbe-85a5-4f9d-b8ee-7f8790aa33ff@eisentraut.org> Date: Mon, 9 Sep 2024 08:06:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Virtual generated columns To: jian he Cc: Dean Rasheed , pgsql-hackers References: <732a9543-0312-4f0c-a471-857b507a3546@eisentraut.org> <0f811f71-8c86-4e1b-b3bb-6a535674a440@eisentraut.org> Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 05.09.24 10:27, jian he wrote: > On Wed, Sep 4, 2024 at 4:40 PM Peter Eisentraut wrote: >> >> >> Here is an implementation of this. It's much nicer! It also appears to >> fix all the additional test cases that have been presented. (I haven't >> integrated them into the patch set yet.) >> >> I left the 0001 patch alone for now and put the new rewriting >> implementation into 0002. (Unfortunately, the diff is kind of useless >> for visual inspection.) Let me know if this matches what you had in >> mind, please. Also, is this the right place in fireRIRrules()? > > hi. some minor issues. > > in get_dependent_generated_columns we can > > /* skip if not generated column */ > if (!TupleDescAttr(tupdesc, defval->adnum - 1)->attgenerated) > continue; > change to > /* skip if not generated stored column */ > if (!(TupleDescAttr(tupdesc, defval->adnum - > 1)->attgenerated == ATTRIBUTE_GENERATED_STORED)) > continue; I need to study more what to do with this function. I'm not completely sure whether this should apply only to stored generated columns. > in ExecInitStoredGenerated > "if ((tupdesc->constr && tupdesc->constr->has_generated_stored)))" > is true. > then later we finish the loop > (for (int i = 0; i < natts; i++) loop) > > we can "Assert(ri_NumGeneratedNeeded > 0)" > so we can ensure once has_generated_stored flag is true, > then we should have at least one stored generated attribute. This is technically correct, but this code isn't touched by this patch, so I don't think it belongs here. > similarly, in expand_generated_columns_internal > we can aslo add "Assert(list_length(tlist) > 0);" > above > node = ReplaceVarsFromTargetList(node, rt_index, 0, rte, tlist, > REPLACEVARS_CHANGE_VARNO, rt_index, NULL); Ok, I'll add that. > @@ -2290,7 +2291,9 @@ ExecBuildSlotValueDescription(Oid reloid, > if (table_perm || column_perm) > { > - if (slot->tts_isnull[i]) > + if (att->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL) > + val = "virtual"; > + else if (slot->tts_isnull[i]) > val = "null"; > else > { > Oid foutoid; > bool typisvarlena; > getTypeOutputInfo(att->atttypid, &foutoid, &typisvarlena); > val = OidOutputFunctionCall(foutoid, slot->tts_values[i]); > } > > we can add Assert here, if i understand it correctly, like > if (att->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL) > { > Assert(slot->tts_isnull[i]); > val = "virtual"; > } Also technically correct, but I don't see what benefit this would bring. The code guarded by that assert would not make use of the thing being asserted.