What is the use of the reorg command in IBM DB2?

What is the use of the reorg command in ibm db2 db? What does Regan do internally? Does reorg need to be run when creating new indexes in a table?

+4
source share
4 answers

I believe that it works the same as the DBCC DBREINDEX command in SQL Server. This is similar to disk defragmentation in that indexes become fragmented over time, as records are deleted, etc., This will certainly speed things up ...

You may already have this link, but it is described here ...

http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0001966.htm

Added

I am trying to answer your question about how this works and why it is necessary, and I do not find anything specific for DB2. The best article I've found is related to SQL Server, but the concept is exactly the same. This article explains what index fragmentation is and why it slows down.

By translating this into IBM DB2, files are defragmented the same way.

http://www.sql-server-performance.com/articles/per/Analyze_and_Fix_Index_Fragmentation_in_SQL_Server_2008_p1.aspx

+1
source

When you delete a record (or row) in (at least for iSeries) DB2, it marks the record for deletion, but does not physically delete the record. When reorg is started, it takes those records marked for deletion and then physically deletes them. I believe that it also moves all data records for optimal performance in the process. On iSeries, this need may be obsolete by telling the file (or table) to reuse the delete entries.

As I said, I know that this applies to DB2 for iSeries (or IBM i). I can only assume that this process is similar to DB2.

+1
source

In fact, this returns the physical records in the order of the primary keys with the correct amount of free space (specified by PCTFREE) in the right places.

Obviously, this also requires the indexes to be rebuilt as well, resulting in well-balanced btrees.

0
source

The REORG operation performs the following functions:

  • Checks referential integrity, if applicable to the target table, and either deletes rows that violate it or invalidates any affected indexes. (Referential integrity is a relational property that every foreign key value in a table exists as a primary key value in a referenced table.

  • Performs an internal reorganization of one or more indexes for a table (of all types) to improve the internal storage of this information and, therefore, performance when the index is used to access data. It can rebuild all indices, selectively rebuild one or more named indices, or selectively rebuild one or more segments of one or more named indices.

  • Specifies the DEFERRED index created using the CREATE INDEX statement. A DEFERRED index is an empty index structure that can be populated later.

  • Restores pre-computed views. For example, if your application supports precalculation of views, you can use the REORG command to restore only precomputed views without touching the indexes in the target table. Alternatively, you can use the REORG command to restore indexes and views.

In addition to restoring aggregate table data, the REORG command restores indexes in aggregate tables.

REORG operation is necessary in the following cases:

  • To repair damaged indexes if you use the database restore operation to restore individual segments of a table or index.

  • Whenever changes to the database affect more than 30 percent of the data, run TMU with the REORG statement for any tables that are directly modified. Periodically rebuilding such tables and indexes using the REORG statement provides referential integrity and optimal performance.

  • To reorganize invalid STAR indexes. Some operations may invalidate STAR indices. For example, increasing the MAXROWS PER SEGMENT or MAXSEGMENTS parameter in a table or using the ALTER statement to expand a segment may invalidate the STAR indexes in tables that reference the modified table. These operations always generate a warning message stating that STAR indices based on the changed table may be invalid, in which case it is necessary to change the resulting STAR indices. You can either reorganize the affected indexes when a message is issued, or assign a REORG operation for a more convenient time. However, any operation without a query (INSERT, UPDATE, or DELETE) against a table with an invalid index results in an error message stating that the index should be reorganized. You must perform a REORG operation before the table is available for INSERT, UPDATE, DELETE, or LOAD operations.

REORG is not required in the following cases:

  • If no changes are made to the database, with the exception of full data downloads.

  • If the table and indexes are segmented the same way, and new index data is loaded into new index segments corresponding to the new table segments.

0
source

All Articles