Subject: in BeginCopyTo make materialized view using COPY TO instead of COPY (query).

From: jian he <[email-masked]>
Date: Thu, 19 Dec 2024 14:28:21 +0800

hi.
generally  COPY TO``COPY table`` is faster than ``COPY (select * from table)``.

in BeginCopyTo. we have
"""
        else if (rel->rd_rel->relkind == RELKIND_MATVIEW)
            ereport(ERROR,
                    (errcode(ERRCODE_WRONG_OBJECT_TYPE),
                     errmsg("cannot copy from materialized view \"%s\"",
                            RelationGetRelationName(rel)),
                     errhint("Try the COPY (SELECT ...) TO variant.")));
"""
Since materialized views have physical storage,

we can make materialized views also using COPY table_name, instead of
COPY(query).

Some simple tests show around %3.7 or 4.3% speed up.

---

From: Michael Paquier <[email-masked]>
Date: Fri, 20 Dec 2024 09:01:48 +0900

> Some simple tests show around %3.7 or 4.3% speed up.

This restriction comes from 3bf3ab8c5636 as such relations may not be
scannable when they have no data, no?  Perhaps this restriction could
be lifted, but I'd suggest to dig more into the lists, there should be
arguments and ideas explaining what could be done in this case
(spoiler: I did not look at that).
--
Michael