4. SQL Statements : MODIFY : MODIFY...TO COMBINE Statement
 
Share this page                  
MODIFY...TO COMBINE Statement
The MODIFY...TO COMBINE statement merges updates buffered in memory and lets you perform bulk DML operations on any form of a table.
For large updates, we recommend using a COPY command or vwload utility to initially load the data into staging tables, and then using explicit MODIFY...TO COMBINE statements.
The MODIFY...TO COMBINE statement has the following format:
MODIFY [schema.]tablename [[UNION ut] [EXCEPT et] ...] TO COMBINE
This statement tells the system that all tuples from except tables (et) must be deleted from the base table, and then all tuples from union tables (ut) must be added to that table. This statement generates a new copy of the base table.
The order of union and except tables does not matter—all deletions are performed before insertions.
Usage Notes:
In the worst case, the MODIFY...TO COMBINE statement may need to rewrite the entire table. As a result, the amount of space required to store the table roughly doubles temporarily. Take the required additional storage space into account when sizing your system.
If the base table contains a Primary Key, the except tables must contain attributes with names that match all attributes of this Primary Key. These attributes do not need to be declared as a Primary Key in the except table; however, they need to be NOT NULL (as Primary Key enforces NOT NULL on the involved base table attributes).
If the base table does not contain a Primary Key, the format of the except table must match exactly the format of the base table, because the entire record is used to identify the tuple to be deleted.
Note:  Performance of deletions using this method is significantly worse than when using a schema with a Primary Key.
Union tables must match the columns of the base table: the names, orders and types (including NULLability) of columns should be identical. The union tables do not need to contain any primary- and foreign-key constraints (see below).
The order of parameters does not matter: all deletions are applied before all insertions.
COMBINE can also be used to quickly delete all tuples from a given table by issuing, for example:
MODIFY a EXCEPT a TO COMBINE
The system detects that this is, in effect, a table truncation, so performs a fast operation.
You can replace all data in a given table with other data. For example:
MODIFY a EXCEPT a UNION b TO COMBINE
replaces all tuples in 'a' with tuples from 'b' with a fast operation involving a table truncation and bulk load.
MODIFY...TO COMBINE is a DDL command, and as a result, no other concurrent updates should be run. Other updates can be run but only the first transaction to commit will succeed.
This statement can return all standard errors reported by DML operations, for example, constraint violations.
Using the same table as the base table and the union table (for example: MODIFY a UNION a TO COMBINE) is illegal.
The MODIFY...TO COMBINE process also applies batch ("small") updates buffered in memory to the new copy of a table—a process known as propagation. You can enforce propagation as follows:
MODIFY a TO COMBINE
After statement execution is completed, the memory used by the buffered updates is freed.
The MODIFY...TO COMBINE statement lets you perform large deletes. For example:
CREATE TABLE deletions AS SELECT key FROM basetable WHERE orderdate < '2010-01-01';
MODIFY basetable EXCEPT deletion TO COMBINE;
DROP TABLE deletions;
The constraints and indexes in the staging tables (union and except tables) are irrelevant for the merging process.
In particular, it is possible to have a non-indexed table and combine it (both as union table and as except table) into an indexed table. Similarly, if the base table has a primary key or a foreign key, the staging tables do not have to have the same primary key defined (as long as the except tables contain columns matching the primary key in the base table and union tables match the column structure of the base table). If the staging tables are not used for querying, we highly recommend that they do not contain constraints (foreign or primary keys) or indexes, to improve their performance in loading data.
The nullability of the columns in the union tables and except tables must match the base table.
The MODIFY...TO COMBINE statement works on Vector tables only, but including temporary tables.
Typically, MODIFY...TO COMBINE does not rewrite the entire table. For insertions, the data usually is written to the end of the table. For deletes, minmax indexes are rebuilt and empty blocks are discarded, which avoids I/O degradation caused by read queries scanning empty or partially empty blocks.
If you want the entire table to be rewritten you can either use the MODIFY…TO RECONSTRUCT statement, or set [system] full_rewrite_on_combine to true in your configuration file.
Note:  When using the MODIFY...TO COMBINE statement on a table with an identity column unexpected results, such as duplicate values, may occur. When records are inserted using MODIFY...TO COMBINE rather than the SQL INSERT, the values in the identify column in the Vector table will not be synchronized with the identity values stored in the Ingres system catalogs.