The deepcopy() function

Multirepresentational opaque types typically defer creating a smart large object until the database server calls the assign() function. Until assign() is called, the opaque type stores a large value in separately allocated memory and stores the pointer to that memory in the data structure of the opaque type.

However, the database server does not know about this additional memory when it copies a return value, so it copies only part of the value. In other words, the database server performs a shallow copy. This means that only allocations with a very high memory duration persist long enough for some query contexts.

The deepcopy() support function provides the method for the database server to copy the entire opaque type value and lets the opaque type support routines that use the default memory duration.

Alternatively, you might use some higher memory duration such as PER_STMT_EXEC. However, this strategy increases memory usage significantly because there are cases where using the default memory duration is sufficient. For information about PER_STMT_EXEC, refer to the HCL OneDB™ DataBlade® API Programmer's Guide and the HCL OneDB DataBlade API Function Reference.

The deepcopy() function should make a copy of the input opaque type using memory allocated from default memory duration and return the copy. The functions that deepcopy() can use to allocate memory from default memory duration include mi_alloc, mi_zalloc, mi_new_var, and mi_var_copy. It is important to use memory allocated from those functions for the return UDT because the database server prepares the appropriate default memory duration depending on the query context before it invokes deepcopy().

If the input UDT contains pointers to an out-of-row buffer, deepcopy() can copy the out-of-row data using memory from mi_alloc and store the pointer with that of memory in the copied UDT.

If the input UDT contains a reference to a smart large object, deepcopy() should copy the large object handle to the return value, but deepcopy() does not need to copy the large object.