Search in sources :

Example 1 with Index

use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.

the class Table method getIndexForColumn.

/**
 * Get the index that has the given column as the first element. This method
 * returns null if no matching index is found.
 *
 * @param column the column
 * @return the index or null
 */
public Index getIndexForColumn(Column column) {
    ArrayList<Index> indexes = getIndexes();
    if (indexes != null) {
        for (int i = 1, size = indexes.size(); i < size; i++) {
            Index index = indexes.get(i);
            int idx = index.getColumnIndex(column);
            if (idx == 0) {
                return index;
            }
        }
    }
    return null;
}
Also used : Index(com.wplatform.ddal.dbobject.index.Index)

Example 2 with Index

use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.

the class Table method dropSingleColumnConstraintsAndIndexes.

/**
 * Check that this column is not referenced by a multi-column constraint or
 * multi-column index. If it is, an exception is thrown. Single-column
 * references and indexes are dropped.
 *
 * @param session the session
 * @param col the column
 * @throws DbException if the column is referenced by multi-column
 *             constraints or indexes
 */
public void dropSingleColumnConstraintsAndIndexes(Session session, Column col) {
    ArrayList<Index> indexesToDrop = New.arrayList();
    ArrayList<Index> indexes = getIndexes();
    if (indexes != null) {
        for (int i = 0, size = indexes.size(); i < size; i++) {
            Index index = indexes.get(i);
            if (index.getColumnIndex(col) < 0) {
                continue;
            }
            if (index.getColumns().length == 1) {
                indexesToDrop.add(index);
            } else {
                throw DbException.get(ErrorCode.COLUMN_IS_REFERENCED_1, index.getSQL());
            }
        }
    }
    for (Index i : indexesToDrop) {
        // constraint
        if (getIndexes().contains(i)) {
            session.getDatabase().removeSchemaObject(session, i);
        }
    }
}
Also used : Index(com.wplatform.ddal.dbobject.index.Index)

Example 3 with Index

use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.

the class Table method getChildren.

@Override
public ArrayList<DbObject> getChildren() {
    ArrayList<DbObject> children = New.arrayList();
    ArrayList<Index> indexes = getIndexes();
    if (indexes != null) {
        children.addAll(indexes);
    }
    if (sequences != null) {
        children.addAll(sequences);
    }
    ArrayList<Right> rights = database.getAllRights();
    for (Right right : rights) {
        if (right.getGrantedTable() == this) {
            children.add(right);
        }
    }
    return children;
}
Also used : DbObject(com.wplatform.ddal.dbobject.DbObject) Right(com.wplatform.ddal.dbobject.Right) Index(com.wplatform.ddal.dbobject.index.Index)

Example 4 with Index

use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.

the class Aggregate method getColumnIndex.

private Index getColumnIndex() {
    if (on instanceof ExpressionColumn) {
        ExpressionColumn col = (ExpressionColumn) on;
        Column column = col.getColumn();
        TableFilter filter = col.getTableFilter();
        if (filter != null) {
            Table table = filter.getTable();
            Index index = table.getIndexForColumn(column);
            return index;
        }
    }
    return null;
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) Column(com.wplatform.ddal.dbobject.table.Column) TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Index(com.wplatform.ddal.dbobject.index.Index)

Example 5 with Index

use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.

the class SelectExecutor method scanLevelValidation.

private void scanLevelValidation(TableFilter filter) {
    Table test = filter.getTable();
    if (!(test instanceof Table)) {
        return;
    }
    TableMate table = castTableMate(test);
    table.check();
    Index index = filter.getIndex();
    int scanLevel = table.getScanLevel();
    switch(scanLevel) {
        case TableConfig.SCANLEVEL_UNLIMITED:
            break;
        case TableConfig.SCANLEVEL_FILTER:
            if (filter.getFilterCondition() == null) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "filter", "filter");
            }
            break;
        case TableConfig.SCANLEVEL_ANYINDEX:
            if (index.getIndexType().isScan()) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "anyIndex", "index");
            }
            break;
        case TableConfig.SCANLEVEL_UNIQUEINDEX:
            if (!index.getIndexType().isUnique()) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "uniqueIndex", "unique index");
            }
            break;
        case TableConfig.SCANLEVEL_SHARDINGKEY:
            if (!index.getIndexType().isShardingKey()) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "shardingKey", "sharding key");
            }
            break;
        default:
            throw DbException.throwInternalError("error table scan level " + scanLevel);
    }
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) Index(com.wplatform.ddal.dbobject.index.Index) TableMate(com.wplatform.ddal.dbobject.table.TableMate)

Aggregations

Index (com.wplatform.ddal.dbobject.index.Index)12 Table (com.wplatform.ddal.dbobject.table.Table)4 Column (com.wplatform.ddal.dbobject.table.Column)3 Expression (com.wplatform.ddal.command.expression.Expression)2 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)2 Comment (com.wplatform.ddal.dbobject.Comment)1 DbObject (com.wplatform.ddal.dbobject.DbObject)1 FunctionAlias (com.wplatform.ddal.dbobject.FunctionAlias)1 Right (com.wplatform.ddal.dbobject.Right)1 IndexMate (com.wplatform.ddal.dbobject.index.IndexMate)1 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)1 TableMate (com.wplatform.ddal.dbobject.table.TableMate)1 RuleColumn (com.wplatform.ddal.dispatch.rule.RuleColumn)1