throw this.m_compiler.new VoltCompilerException(msg);
}
}
}
Index index = table.getIndexes().add(name);
index.setCountable(false);
// set the type of the index based on the index name and column types
// Currently, only int types can use hash or array indexes
String indexNameNoCase = name.toLowerCase();
if (indexNameNoCase.contains("tree"))
{
index.setType(IndexType.BALANCED_TREE.getValue());
index.setCountable(true);
}
else if (indexNameNoCase.contains("hash"))
{
if (!has_nonint_col)
{
index.setType(IndexType.HASH_TABLE.getValue());
}
else
{
String msg = "Index " + name + " in table " + table.getTypeName() +
" uses a non-hashable column " + nonint_col_name;
throw m_compiler.new VoltCompilerException(msg);
}
} else {
index.setType(IndexType.BALANCED_TREE.getValue());
index.setCountable(true);
}
// Countable is always on right now. Fix it when VoltDB can pack memory for TreeNode.
// if (indexNameNoCase.contains("NoCounter")) {
// index.setType(IndexType.BALANCED_TREE.getValue());
// index.setCountable(false);
// }
// need to set other index data here (column, etc)
// For expression indexes, the columns listed in the catalog do not correspond to the values in the index,
// but they still represent the columns that will trigger an index update when their values change.
for (int i = 0; i < columns.length; i++) {
ColumnRef cref = index.getColumns().add(columns[i].getTypeName());
cref.setColumn(columns[i]);
cref.setIndex(i);
}
if (exprs != null) {
try {
index.setExpressionsjson(convertToJSONArray(exprs));
} catch (JSONException e) {
throw m_compiler.new VoltCompilerException("Unexpected error serializing non-column expressions for index '" +
name + "' on type '" + table.getTypeName() + "': " + e.toString());
}
}
index.setUnique(unique);
if (assumeUnique) {
index.setUnique(true);
}
index.setAssumeunique(assumeUnique);
// check if an existing index duplicates another index (if so, drop it)
// note that this is an exact dup... uniqueness, counting-ness and type
// will make two indexes different
for (Index existingIndex : table.getIndexes()) {
// skip thineself
if (existingIndex == index) {
continue;
}
if (indexesAreDups(existingIndex, index)) {
// replace any constraints using one index with the other
//for () TODO
// get ready for replacements from constraints created later
indexReplacementMap.put(index.getTypeName(), existingIndex.getTypeName());
// if the index is a user-named index...
if (index.getTypeName().startsWith(HSQLInterface.AUTO_GEN_PREFIX) == false) {
// on dup-detection, add a warning but don't fail
String msg = String.format("Dropping index %s on table %s because it duplicates index %s.",
index.getTypeName(), table.getTypeName(), existingIndex.getTypeName());
m_compiler.addWarn(msg);
}
// drop the index and GTFO
table.getIndexes().delete(index.getTypeName());
return;
}
}
String msg = "Created index: " + name + " on table: " +
table.getTypeName() + " of type: " + IndexType.get(index.getType()).name();
m_compiler.addInfo(msg);
indexMap.put(name, index);
}