throws StandardException
{
Properties properties = new Properties();
// Get the ConglomerateDescriptor for the index
ConglomerateDescriptor cd =
td.getConglomerateDescriptor(indexConglomerateNumbers[index]);
// Build the properties list for the new conglomerate
ConglomerateController indexCC =
tc.openConglomerate(
indexConglomerateNumbers[index],
false,
TransactionController.OPENMODE_FORUPDATE,
TransactionController.MODE_TABLE,
TransactionController.ISOLATION_SERIALIZABLE);
// Get the properties on the old index
indexCC.getInternalTablePropertySet(properties);
/* Create the properties that language supplies when creating the
* the index. (The store doesn't preserve these.)
*/
int indexRowLength = indexRows[index].nColumns();
properties.put("baseConglomerateId", Long.toString(newHeapConglom));
if (cd.getIndexDescriptor().isUnique())
{
properties.put(
"nUniqueColumns", Integer.toString(indexRowLength - 1));
}
else
{
properties.put(
"nUniqueColumns", Integer.toString(indexRowLength));
}
properties.put(
"rowLocationColumn", Integer.toString(indexRowLength - 1));
properties.put(
"nKeyFields", Integer.toString(indexRowLength));
indexCC.close();
// We can finally drain the sorter and rebuild the index
// Populate the index.
RowLocationRetRowSource cCount = null;
boolean statisticsExist = false;
if (!truncateTable)
{
sorters[index].completedInserts();
sorters[index] = null;
if (td.statisticsExist(cd))
{
cCount =
new CardinalityCounter(
tc.openSortRowSource(sortIds[index]));
statisticsExist = true;
}
else
{
cCount =
new CardinalityCounter(
tc.openSortRowSource(sortIds[index]));
}
newIndexCongloms[index] =
tc.createAndLoadConglomerate(
"BTREE",
indexRows[index].getRowArray(),
ordering[index],
collation[index],
properties,
TransactionController.IS_DEFAULT,
cCount,
(long[]) null);
//For an index, if the statistics already exist, then drop them.
//The statistics might not exist for an index if the index was
//created when the table was empty.
//
//For all alter table actions, including ALTER TABLE COMPRESS,
//for both kinds of indexes (ie. one with preexisting statistics
//and with no statistics), create statistics for them if the table
//is not empty.
if (statisticsExist)
dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc);
long numRows;
if ((numRows = ((CardinalityCounter)cCount).getRowCount()) > 0)
{
long[] c = ((CardinalityCounter)cCount).getCardinality();
for (int i = 0; i < c.length; i++)
{
StatisticsDescriptor statDesc =
new StatisticsDescriptor(
dd,
dd.getUUIDFactory().createUUID(),
cd.getUUID(),
td.getUUID(),
"I",
new StatisticsImpl(numRows, c[i]),
i + 1);
dd.addDescriptor(
statDesc,
null, // no parent descriptor
DataDictionary.SYSSTATISTICS_CATALOG_NUM,
true, // no error on duplicate.
tc);
}
}
}
else
{
newIndexCongloms[index] =
tc.createConglomerate(
"BTREE",
indexRows[index].getRowArray(),
ordering[index],
collation[index],
properties,
TransactionController.IS_DEFAULT);
//on truncate drop the statistics because we know for sure
//rowscount is zero and existing statistic will be invalid.
if (td.statisticsExist(cd))
dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc);
}
/* Update the DataDictionary
*
* Update sys.sysconglomerates with new conglomerate #, we need to