RelationshipImpl.CASCADE_DELETES_FLAG |
RelationshipImpl.CASCADE_UPDATES_FLAG |
RelationshipImpl.CASCADE_NULL_FLAG;
-
+
+ // for the purposes of choosing a backing index for a foreign key, there are
+ // certain index flags that can be ignored (we don't care how they are set)
+ private final static byte IGNORED_INDEX_FLAGS =
+ IndexData.IGNORE_NULLS_INDEX_FLAG | IndexData.REQUIRED_INDEX_FLAG;
private TableImpl _primaryTable;
private TableImpl _secondaryTable;
private void addPrimaryIndex() throws IOException {
TableUpdater updater = new TableUpdater(_primaryTable);
updater.setForeignKey(createFKReference(true));
- updater.addIndex(createPrimaryIndex(), true);
+ updater.addIndex(createPrimaryIndex(), true, IGNORED_INDEX_FLAGS, (byte)0);
}
private void addSecondaryIndex() throws IOException {
TableUpdater updater = new TableUpdater(_secondaryTable);
updater.setForeignKey(createFKReference(false));
- updater.addIndex(createSecondaryIndex(), true);
+ updater.addIndex(createSecondaryIndex(), true, IGNORED_INDEX_FLAGS, (byte)0);
}
private IndexImpl.ForeignKeyReference createFKReference(boolean isPrimary) {
if(isPrimary) {
tableType = IndexImpl.PRIMARY_TABLE_TYPE;
otherTableNum = _secondaryTable.getTableDefPageNumber();
+ // we create the primary index first, so the secondary index does not
+ // exist yet
otherIdxNum = _secondaryTable.getLogicalIndexCount();
} else {
tableType = IndexImpl.SECONDARY_TABLE_TYPE;
otherTableNum = _primaryTable.getTableDefPageNumber();
- otherIdxNum = _primaryTable.getLogicalIndexCount();
+ // at this point, we've already created the primary index, it's the last
+ // one on the primary table
+ otherIdxNum = _primaryTable.getLogicalIndexCount() - 1;
}
boolean cascadeUpdates = ((_flags & RelationshipImpl.CASCADE_UPDATES_FLAG) != 0);
boolean cascadeDeletes = ((_flags & RelationshipImpl.CASCADE_DELETES_FLAG) != 0);
String baseName = null;
String suffix = null;
if(isPrimary) {
- // primary naming scheme: ".rC", ".rD", "rE" ...
+ // primary naming scheme: ".rB", .rC", ".rD", "rE" ...
baseName = ".r";
- suffix = "C";
+ suffix = "B";
} else {
// secondary naming scheme: "<t1><t2>", "<t1><t2>1", "<t1><t2>2"
baseName = _primaryTable.getName() + _secondaryTable.getName();
}
public IndexImpl addIndex(IndexBuilder index) throws IOException {
- return addIndex(index, false);
+ return addIndex(index, false, (byte)0, (byte)0);
}
- IndexImpl addIndex(IndexBuilder index, boolean isInternal) throws IOException {
-
+ IndexImpl addIndex(IndexBuilder index, boolean isInternal, byte ignoreIdxFlags,
+ byte ignoreColFlags)
+ throws IOException
+ {
_index = index;
if(!isInternal) {
_index.setIndexNumber(indexNumber);
// initialize backing index state
- initIndexDataState();
+ initIndexDataState(ignoreIdxFlags, ignoreColFlags);
if(!isInternal) {
getPageChannel().startExclusiveWrite();
return idxNames;
}
- private void initIndexDataState() {
+ private void initIndexDataState(byte ignoreIdxFlags, byte ignoreColFlags) {
_idxDataState = new IndexDataState();
_idxDataState.addIndex(_index);
// search for an existing index which matches the given index (in terms of
// the backing data)
- IndexData idxData = findIndexData(_index, _table, (byte)0, (byte)0);
+ IndexData idxData = findIndexData(
+ _index, _table, ignoreIdxFlags, ignoreColFlags);
int idxDataNumber = ((idxData != null) ?
idxData.getIndexDataNumber() :