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 1tzzsv-009m7U-Ja for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Apr 2025 15:20:09 +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 1tzzsu-00Ef72-94 for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Apr 2025 15:20:08 +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 1tzzst-00Ef6u-Ur for pgsql-hackers@lists.postgresql.org; Wed, 02 Apr 2025 15:20:07 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tzzsq-002zKK-2p for pgsql-hackers@postgresql.org; Wed, 02 Apr 2025 15:20:07 +0000 Received: from [192.168.11.4] (p1696134-ipoe.ipoe.ocn.ne.jp [118.0.93.133]) by oss.nttdata.com (Postfix) with ESMTPSA id 969C260538; Thu, 3 Apr 2025 00:19:58 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com Message-ID: <4f9481ea-5dbc-43b2-a8a1-ec4cbecce6e7@oss.nttdata.com> Date: Thu, 3 Apr 2025 00:19:58 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: in BeginCopyTo make materialized view using COPY TO instead of COPY (query). To: jian he Cc: Andrew Dunstan , "David G. Johnston" , Kirill Reshke , PostgreSQL-development , Tom Lane , Michael Paquier References: <442e62f7-ef64-4df1-8453-d682fe9bdaa3@dunslane.net> <425ebe4b-06c5-4212-af68-fd0e5537c250@dunslane.net> Content-Language: en-US From: Fujii Masao 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 2025/04/01 12:12, jian he wrote: > On Mon, Mar 31, 2025 at 11:27 PM Fujii Masao > wrote: >> >> Regarding the patch, here are some review comments: >> >> + errmsg("cannot copy from materialized view when the materialized view is not populated"), >> >> How about including the object name for consistency with >> other error messages in BeginCopyTo(), like this? >> >> errmsg("cannot copy from unpopulated materialized view \"%s\"", >> RelationGetRelationName(rel)), >> >> >> + errhint("Use the REFRESH MATERIALIZED VIEW command populate the materialized view first.")); >> >> There seems to be a missing "to" just after "command". >> Should it be "Use the REFRESH MATERIALIZED VIEW command to >> populate the materialized view first."? Or we could simplify >> the hint to match what SELECT on an unpopulated materialized >> view logs: "Use the REFRESH MATERIALIZED VIEW command.". >> > based on your suggestion, i changed it to: Thanks for updating the patch! > > if (!RelationIsPopulated(rel)) > ereport(ERROR, > errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > errmsg("cannot copy from unpopulated > materialized view \"%s\"", > RelationGetRelationName(rel)), > errhint("Use the REFRESH MATERIALIZED VIEW > command to populate the materialized view first.")); I think it's better to use the same hint message as the one output by "COPY (SELECT * FROM ) TO", specifically: "Use the REFRESH MATERIALIZED VIEW command," for consistency. >> The copy.sgml documentation should clarify that COPY TO can >> be used with a materialized view only if it is populated. >> > "COPY TO can be used only with plain tables, not views, and does not > copy rows from child tables or child partitions" > i changed it to > "COPY TO can be used with plain tables and materialized views, not > regular views, and does not copy rows from child tables or child > partitions" It would be clearer to specify that "COPY TO" applies to *populated* materialized views rather than just "materialized views"? > Another alternative wording I came up with: > "COPY TO can only be used with plain tables and materialized views, > not regular views. It also does not copy rows from child tables or > child partitions." If we split the first description into two as you suggested, I'm tempted to propose the following improvements to enhance the overall descriptions: ------------- "COPY TO" can be used with plain tables and populated materialized views. For example, "COPY table TO" copies the same rows as "SELECT * FROM ONLY table." However, it doesn't directly support other relation types, such as partitioned tables, inheritance child tables, or views. To copy all rows from these relations, use "COPY (SELECT * FROM table) TO." ------------- >> Wouldn't it be beneficial to add a regression test to check >> whether COPY matview TO works as expected? > sure. The tests seem to have been placed under the category "COPY FROM ... DEFAULT", which feels a bit misaligned. How about adding them to the end of copy.sql instead? Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION