NAME
DBIO::DB2::Diff::Reorg - Diff operation for the REORG a DB2 table needs after some column changes
VERSION
version 0.900007
DESCRIPTION
Some of the ALTER TABLE statements DBIO::DB2::Diff::Column writes leave the table in reorg-pending state. Until a REORG has run, Db2 refuses INSERT, UPDATE and CREATE INDEX on it with SQL0668N, reason code 7 (SQLSTATE 57007) -- so a diff that drops a column and creates an index on the same table stops at the index, and since this deploy does not run its DDL in a transaction ("Transactional DDL -- the engine has it, this deploy does not use it" in DBIO::DB2::Deploy) the column is gone by then.
This operation is that REORG, as a statement of the diff: it is in "operations" in DBIO::Diff::Base, "as_sql" in DBIO::Diff::Base and "summary" in DBIO::Diff::Base before anything is applied, and "apply" in DBIO::Deploy::Base runs it like every other statement. DBIO::DB2::Diff puts one per table after the column operations and before the index operations; which column operations ask for one is "reorg_recommended" in DBIO::DB2::Diff::Column.
It is a classic REORG TABLE, run through the SYSPROC.ADMIN_CMD procedure because REORG is a command and not an SQL statement. It rewrites the table: the time it takes grows with the table, and it is part of the upgrade from the moment the diff contains one of those ALTER TABLE statements -- the table takes no row before it has run. See ADR 0008 for the measurements, and for what is known about locks and the authority the call needs.
A table that is reorg-pending before the diff -- an earlier upgrade that stopped half way, a REORG that failed, an ALTER TABLE run by hand -- is not in the diff: reorg-pending is a state of the table and not part of the introspected model, so the diff sees no column operation and writes no REORG. "upgrade" in DBIO::DB2::Deploy covers it outside the diff: it asks SYSIBMADM.ADMINTABINFO for the tables present in both models and runs this operation's statement for the pending ones first (ADR 0008, addendum). diff and as_sql do not show that REORG; apply alone, given a diff, does not run it either.
new, action (always reorg) and summary_prefix come from DBIO::Diff::Op.
METHODS
diff
my @ops = DBIO::DB2::Diff::Reorg->diff(@column_ops);
Takes the operations of the column pass and returns one reorg operation for every table that has at least one operation answering true to "reorg_recommended" in DBIO::DB2::Diff::Column -- one, however many there are, in the order the tables first appear. Db2 takes further ALTER TABLE statements on a reorg-pending table, so one REORG after the last of them is enough.
as_sql
CALL SYSPROC.ADMIN_CMD('REORG TABLE "author"');
The table name is a quoted identifier and unqualified, like the ALTER TABLE statements before it: ADMIN_CMD resolves it against CURRENT SCHEMA, as the server does theirs. The command is a string literal, so an apostrophe in the name is doubled.
summary
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.