
As noted in the Storage in Database section,
a subtree may be extracted from a document during writing of "persistent XML"
entity into field of type LONG VARCHAR. The procedure of converting a subtree into
complete document is known as "cutting".  Cutting is performed only for
"persistent XML" documents, it has nothing common with serialization of
XML entities in form of plain XML text.
Usually it is the job of the Server itself who
decides whether a cutting operation should be performed or not, without any specific
activity at application level.
The CPU time occupied due to cutting is up to 10 times greater than the CPU time of plain copying of LONG VARCHAR,
but the amount of disk IO is about the same, so the optimization rules discussed below are
important only for time-critical, memory-located database applications.
The Virtuoso Server tries to reduce the number of cuttings to an absolute minimum.
First of all, cutting is not performed when a given XML entity
refers to the root of the document, or to the only child of the root,
because the result of such cutting will be identical to original document.
In addition, every document remembers the result of last cutting performed on data from
this document, so if data of some XML entity are saved in many places without saving of
other XML entities between them, cutting will be done only once and plain copying will
be done for every subsequent saving.
The only situation when cutting may be seriously optimized by the application developer is in code
like the following:
Calls of xpath_eval are outside the loop, so it is faster than retrieval of suitable form for
every selected record.  But values of both _plain and _isdn shares the same underlaying XML document
and they will be assigned many times by the @insert@ operation.  The XML document has no place to cache
two results of cuttings, so new cutting will be done every time
when _isdn entity is saved after _plain or _plain saved after _isdn.  To optimize, it is better to
cut them once outside the loop: