int id = getId(); linkedIndex = new LinkedIndex(this, id, IndexColumn.wrap(cols), IndexType.createNonUnique(false)); indexes.add(linkedIndex); try { addIndex(list, IndexType.createPrimaryKey(false, false)); rs.close(); indexType = unique ? IndexType.createUnique(false, false) : IndexType.createNonUnique(false); String col = rs.getString("COLUMN_NAME"); col = convertColumnName(col);
@Override public Index getUniqueIndex() { for (Index idx : indexes) { if (idx.getIndexType().isUnique()) { return idx; } } return null; }
/** * Initialize the table. * * @param session the session */ void init(Session session) { primaryIndex = new MVPrimaryIndex(session.getDatabase(), this, getId(), IndexColumn.wrap(getColumns()), IndexType.createScan(true)); indexes.add(primaryIndex); }
/** * @param tbl Table. * @param name Index name. * @param pk Primary key. * @param colsList Index columns. */ public H2TreeClientIndex( GridH2Table tbl, String name, boolean pk, List<IndexColumn> colsList ) { IndexColumn[] cols = colsList.toArray(new IndexColumn[colsList.size()]); IndexColumn.mapColumns(cols, tbl); initBaseIndex(tbl, 0, name, cols, pk ? IndexType.createPrimaryKey(false, false) : IndexType.createNonUnique(false, false, false)); }
private void checkNullable(Table table) { for (Index index : table.getIndexes()) { if (index.getColumnIndex(oldColumn) < 0) { continue; } IndexType indexType = index.getIndexType(); if (indexType.isPrimaryKey() || indexType.isHash()) { throw DbException.get( ErrorCode.COLUMN_IS_PART_OF_INDEX_1, index.getSQL()); } } }
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) { int indexId = getObjectId(); IndexType indexType; if (unique) { // for unique constraints indexType = IndexType.createUnique(t.isPersistIndexes(), false); } else { // constraints indexType = IndexType.createNonUnique(t.isPersistIndexes()); } indexType.setBelongsToConstraint(true); String prefix = constraintName == null ? "CONSTRAINT" : constraintName; String indexName = t.getSchema().getUniqueIndexName(session, t, prefix + "_INDEX_"); try { Index index = t.addIndex(session, indexName, indexId, cols, indexType, true, null); createdIndexes.add(index); return index; } finally { getSchema().freeUniqueName(indexName); } }
IndexColumn[] cols, IndexType indexType, boolean create, String indexComment) { if (indexType.isPrimaryKey()) { for (IndexColumn c : cols) { Column column = c.column; if (isPersistIndexes() && indexType.isPersistent()) { int mainIndexColumn; if (database.isStarting() && index = new PageDelegateIndex(this, indexId, indexName, indexType, mainIndex, create, session); } else if (indexType.isSpatial()) { index = new SpatialTreeIndex(this, indexId, indexName, cols, indexType, true, create, session); if (indexType.isHash()) { if (cols.length != 1) { throw DbException.getUnsupportedException( "hash indexes may index only one column"); if (indexType.isUnique()) { index = new HashIndex(this, indexId, indexName, cols, indexType); } else if (indexType.isSpatial()) { index = new SpatialTreeIndex(this, indexId, indexName, cols, indexType, false, true, session);
current.getIndexType().isScan() || columnIndex == current)) { IndexType type = columnIndex.getIndexType(); if (!type.isHash() && (!type.isUnique() || columnIndex.getColumns().length > 1)) { topTableFilter.setIndex(columnIndex); Index current = topTableFilter.getIndex(); if (index != null && current != null) { if (current.getIndexType().isScan() || current == index) { topTableFilter.setIndex(index); if (!topTableFilter.hasInComparisons()) { Index index = getGroupSortedIndex(); Index current = topTableFilter.getIndex(); if (index != null && current != null && (current.getIndexType().isScan() || current == index)) { topTableFilter.setIndex(index);
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY); indexType = IndexType.createPrimaryKey(persistent, hash); } else if (unique) { indexType = IndexType.createUnique(persistent, hash); } else if (affinity) { indexType = IndexType.createAffinity(); } else { indexType = IndexType.createNonUnique(persistent, hash, spatial);
if (isPersistIndexes() && indexType.isPersistent()) { if (indexType.isSpatial()) { index = new SpatialTreeIndex(this, indexId, indexName, cols, indexType, true, create, session); if (indexType.isSpatial()) { index = new SpatialTreeIndex(this, indexId, indexName, cols, indexType, false, true, session);
/** * @param cctx Cache context. * @param tbl Table. * @param name Index name. * @param colsList Index columns. * @param segments Segments. */ public H2PkHashIndex( GridCacheContext<?, ?> cctx, GridH2Table tbl, String name, List<IndexColumn> colsList, int segments ) { assert segments > 0: segments; this.segments = segments; IndexColumn[] cols = colsList.toArray(new IndexColumn[colsList.size()]); IndexColumn.mapColumns(cols, tbl); initBaseIndex(tbl, 0, name, cols, IndexType.createPrimaryKey(false, true)); this.tbl = tbl; this.cctx = cctx; }
private Index getGroupSortedIndex() { if (groupIndex == null || groupByExpression == null) { return null; } ArrayList<Index> indexes = topTableFilter.getTable().getIndexes(); if (indexes != null) { for (Index index : indexes) { if (index.getIndexType().isScan()) { continue; } if (index.getIndexType().isHash()) { // does not allow scanning entries continue; } if (isGroupSortedIndex(topTableFilter, index)) { return index; } } } return null; }
IndexColumn[] cols, IndexType indexType, boolean create, String indexComment) { if (indexType.isPrimaryKey()) { for (IndexColumn c : cols) { Column column = c.column; index = new MVDelegateIndex(this, indexId, indexName, primaryIndex, indexType); } else if (indexType.isSpatial()) { index = new MVSpatialIndex(session.getDatabase(), this, indexId, indexName, cols, indexType);
/** * Create a non-unique index. * * @param persistent if the index is persistent * @return the index type */ public static IndexType createNonUnique(boolean persistent) { return createNonUnique(persistent, false, false); }
Constraint constraint = constraints.get(k); if (constraint.usesIndex(index)) { if (index.getIndexType().isPrimaryKey()) { if (constraint.getConstraintType() == Constraint.Type.PRIMARY_KEY) { constraintName = constraint.getName(); index.getIndexType().isUnique() ? "FALSE" : "TRUE", index.getIndexType().getBelongsToConstraint() ? "TRUE" : "FALSE", index.getIndexType().isAffinity() ? "TRUE" : "FALSE" );
public Index addIndex(Session session, String indexName, int indexId, IndexColumn[] cols, IndexType indexType, int headPos, String indexComment) throws SQLException { if (indexType.isPrimaryKey()) { for (int i = 0; i < cols.length; i++) { Column column = cols[i].column; if (isPersistent() && indexType.isPersistent()) { index = new BtreeIndex(session, this, indexId, indexName, cols, indexType, headPos); } else { if (indexType.isHash()) { index = new HashIndex(this, indexId, indexName, cols, indexType); } else { if (index.getIndexType().isPersistent() && !database.getReadOnly() && !database.getLog().containsInDoubtTransactions()) {
@Override public Index getScanIndex(Session session) { // Look for scan index for(Index index : indexes) { if(index.getIndexType().isScan()) { return index; } } return null; }
IndexType indexType = IndexType.createPrimaryKey( table.isPersistIndexes(), primaryKeyHash); String indexName = table.getSchema().getUniqueIndexName( index.getIndexType().setBelongsToConstraint(true); int constraintId = getObjectId(); String name = generateConstraintName(table); if (index != null && canUseUniqueIndex(index, table, indexColumns)) { isOwner = true; index.getIndexType().setBelongsToConstraint(true); } else { index = getUniqueIndex(table, indexColumns); if (index != null && canUseIndex(index, table, indexColumns, false)) { isOwner = true; index.getIndexType().setBelongsToConstraint(true); } else { index = getIndex(table, indexColumns, false); canUseIndex(refIndex, refTable, refIndexColumns, false)) { isRefOwner = true; refIndex.getIndexType().setBelongsToConstraint(true); } else { refIndex = null;
/** * Get the primary key index if there is one, or null if there is none. * * @return the primary key index or null */ public Index findPrimaryKey() { ArrayList<Index> indexes = getIndexes(); if (indexes != null) { for (Index idx : indexes) { if (idx.getIndexType().isPrimaryKey()) { return idx; } } } return null; }
pk ? IndexType.createUnique(false, false) : IndexType.createNonUnique(false, false, false));