Adding Fields to a Previously Defined Space

ActiveSpaces allows you to alter the fields in a space that is already defined by using the as-admin utility or by calling Metaspace.alterspace(). The C API and the .NET API provide equivalent operations. There is no disruption in service when you alter the space.

Any new fields that you add must be nullable. If the space has not yet been defined or the space definition is incompatible with the one that is defined (for example, has new fields that are not nullable), ActiveSpaces generates an exception describing what was incorrect.

Note: Ensure that the Metaspace.alterspace() method is not used in a tight loop with other calls to the metaspace. The following is a bad example that uses a tight loop:
for( int j=0; j<500; j++){
spaceDef = space.getSpaceDef();
FieldDef newFieldDf = FieldDef.create("FieldId"+j, FieldType.INTEGER);
newFieldDf.setNullable(true);
space.putFieldDef(lNewFieldDf);
metaspace.alterSpace(lSpaceDf);
}
The following is a good example:
for( int j=0; j<500; j++)
{
spaceDef = space.getSpaceDef();
FieldDef newFieldDf = FieldDef.create("FieldId"+j, FieldType.INTEGER);
newFieldDf.setNullable(true);
space.putFieldDef(lNewFieldDf);
}
metaspace.alterSpace(lSpaceDf);

Adding and Dropping Indexes

ActiveSpaces allows you to add indexes to a space that is already defined or drop indexes from the space. You can add or drop indexes by using the as-admin utility or by calling Metaspace.alterspace(). The C API and the .NET API provide equivalent operations. There is no disruption in service. ActiveSpaces builds the new indexes in the background, and when they are ready, sues them automatically to optimize queries.

Note: You cannot modify an existing index’s fields or index type. If you want to modify the fields or index type, you must first drop the index, then alter the space, add the index and alter it again. Also, when you add a new index, you cannot use fields from an existing index.

The following example shows how to add and drop an index using the Java API.

SpaceDef spaceDef = metaspace.getSpaceDef(“test”);
    spacedef.removeIndexDef(“index1”);
    spaceDef.addIndexDef(…)
    spaceDef.addIndexDef(…)
    spaceDef.putFieldDef(FieldDef….)
metaspace.alterSpace(spaceDef);