Previous Topic

Next Topic

Bulk Copy

The copy statement to reload a table whose characteristics allow a bulk copy to be performed has the following format:

copy [table] [schema.]tablename

  ([column_name = format [with null [(value)]]

  {, column_name = format [with null[(value)]]}])

  from 'input_filename'

  [with [standard-with-clauses]

  [, allocation = n] [, extend = n] [, row_estimate = n]

  [, fillfactor=n] [, minpages=n] [, maxpages=n]

  [, leaffill=n] [, nonleaffill=n]]

If the file is formatted, you must specify columns in the column list as described for reloading formatted data. If the file is binary, use an empty column list.

Previous Topic

Next Topic

Bulk Copying Requirements

To perform a bulk copy when loading data from a file into a table, the table must have the following characteristics:

If these requirements are not met, the copy is performed in incremental mode.

Previous Topic

Next Topic

Transaction Logging During Bulk and Incremental Copy

The bulk copy requires only minimal transaction logging.

Note: A transaction is still entered into the log file and normal logging occurs for the associated system catalogs.

In contrast, an incremental copy can generate a large amount of transaction log records. The incremental copy requires logging for every record transfer and every structural change to the table.

An alternative method to reducing logging is described in Large Data Loads with the Set Nologging Statement.

Previous Topic

Next Topic

Bulk and Incremental Copy Processing

The processing for a bulk copy is similar to a modify statement, except that the data comes from an external source rather than an existing table. For a bulk copy, the copy statement:

  1. Reads all data from the source.
  2. Deposits the data in the Data Manipulation Facility (DMF) sorter.
  3. The sorter sorts all data into the required order.

    Note: For a heap table, no sorting is done.

  4. The copy extracts the data from the sorter, builds the table, and populates the table.

In contrast, for an incremental copy, the sequence is to:

  1. Read one record from the external file.
  2. Add to the table as an insert.
  3. Repeat these steps until the data has been copied.

Previous Topic

Next Topic

Bulk Copy With-Clauses

The with clause options on the copy statement for bulk copy operate like the corresponding clauses in the modify statement.

If these clauses are omitted, the table default values in the system catalogs are used. If any of these clauses are specified, the values become the new defaults for the table in the system catalogs.

The following clauses can be used only with a bulk copy:

Note: If these clauses are used with a copy statement with columns specified, an error message is returned and the copy is not performed.

For further details on these with clause options, see the chapter "Maintaining Storage Structures."

Previous Topic

Next Topic

Example: Perform a Bulk Copy to Create a Hash Table

The following sequence of statements allows a bulk copy to be performed. This example creates a hash table:

create table tmp1

    (col1 integer not null, 

    col2 char(25))

    with nojournaling;

    modify tmp1 to hash;

    copy tmp1() from 'tmp1.saved' 

    with row_estimate = 10000, 

    maxpages = 1000, 

    allocation = 1000;

Bulk copy is chosen for the copy because the table is not journaled (it is created with nojournaling), it has no indexes (none have yet been created), and the table has under 18 pages (it is a newly created table that has not yet been populated with data).

The modify to hash operation is quick because the table is empty at this point. The row_estimate parameter allows a more efficient sort than if the default estimate (of 0 rows) is used. Additionally, for the hash table, row_estimate enables the number of hash buckets to be calculated efficiently. This calculation uses the row width (set by the create table statement), row_estimate, max_pages, and the (default) fillfactor. The copy statement includes an allocation clause to preallocate disk space for the table to grow, increasing efficiency of later row additions.

Previous Topic

Next Topic

Example: Perform Bulk Copy and Create B-tree Table

The following example of a bulk copy uses a B-tree table:

create table tmp2

    (col1 integer not null, 

    col2 char(25));. . .

    Populate table. . .

    Save any data needed in table

    modify tmp2 to truncated;

    modify tmp2 to btree;

    set nojournaling on tmp2;

    copy tmp2() from 'tmp2.saved' 

    with row_estimate = 10000, 

    leaffill = 70,

    fillfactor = 95,

    allocation = 1000;

The existing table tmp2 is truncated to assure it has fewer than 18 pages. This also removes any indexes. Journaling is disabled for the table with the set nojournaling statement. The table meets the bulk copy requirements and a bulk copy is performed.

The copy statement includes a row estimate for efficient sorting during the copy. The leaffill and fillfactor clauses allow the Btree table to be set up as specified during the copy operation. The allocation clause provides for efficient future table growth.

Previous Topic

Next Topic

Example: Perform Bulk Copy into a Heap Table

When a heap table is unjournaled and has no indexes, all copies are performed using bulk copy, regardless of the size of the table. Bulk copying into a non-empty heap table is allowed by logging the last valid page before starting the copy. If an error or rollback occurs, all new pages are marked as free.

Note: The table is not returned to its original size.

For example, in the following sequence of statements, all of the copy operations into the heap table are done as bulk copies:


© 2007 Ingres Corporation. All rights reserved.