private void checkRowCount(Session session, Index index, int offset) { if (SysProperties.CHECK && !database.isMultiVersion()) { if (!(index instanceof PageDelegateIndex)) { long rc = index.getRowCount(session); if (rc != rowCount + offset) { DbException.throwInternalError( "rowCount expected " + (rowCount + offset) + " got " + rc + " " + getName() + "." + index.getName()); } } } }
@Override public void close(Session session) { for (Index index : indexes) { index.close(session); } }
@Override public int compare(Row r1, Row r2) { return index.compareRows(r1, r2); } });
/** * Drop and remove the given local temporary index from this session. * * @param index the index */ public void removeLocalTempTableIndex(Index index) { if (localTempTableIndexes != null) { localTempTableIndexes.remove(index.getName()); synchronized (database) { index.removeChildrenAndResources(this); } } }
private static boolean canUseIndex(Index existingIndex, Table table, IndexColumn[] cols, boolean moreColumnsOk) { if (existingIndex.getTable() != table || existingIndex.getCreateSQL() == null) { Column[] indexCols = existingIndex.getColumns(); int idx = existingIndex.getColumnIndex(col.column); if (idx < 0 || idx >= cols.length) { return false; int idx = existingIndex.getColumnIndex(col.column); if (idx < 0) { return false;
private static boolean canUseUniqueIndex(Index idx, Table table, IndexColumn[] cols) { if (idx.getTable() != table || !idx.getIndexType().isUnique()) { return false; } Column[] indexCols = idx.getColumns(); HashSet<Column> indexColsSet = new HashSet<>(); Collections.addAll(indexColsSet, indexCols); HashSet<Column> colsSet = new HashSet<>(); for (IndexColumn c : cols) { colsSet.add(c.column); } return colsSet.equals(indexColsSet); }
index = new MultiVersionIndex(index, this); if (index.needRebuild() && rowCount > 0) { try { Index scan = getScanIndex(session); long remaining = scan.getRowCount(session); long total = remaining; Cursor cursor = scan.find(session, null, null); long i = 0; int bufferSize = (int) Math.min(rowCount, database.getMaxMemoryRows()); ArrayList<Row> buffer = new ArrayList<>(bufferSize); String n = getName() + ":" + index.getName(); int t = MathUtils.convertLongToInt(total); while (cursor.next()) { getSchema().freeUniqueName(indexName); try { index.remove(session); } catch (DbException e2) { index.setTemporary(isTemporary()); if (index.getCreateSQL() != null) { index.setComment(indexComment); if (isSessionTemporary) { session.addLocalTempTableIndex(index);
index = new MultiVersionIndex(index, this); if (index.needRebuild() && rowCount > 0) { try { Index scan = getScanIndex(session); long remaining = scan.getRowCount(session); long total = remaining; Cursor cursor = scan.find(session, null, null); long i = 0; int bufferSize = Constants.DEFAULT_MAX_MEMORY_ROWS; getSchema().freeUniqueName(indexName); try { index.remove(session); } catch (SQLException e2) { index.setTemporary(temporary); if (index.getCreateSQL() != null) { index.setComment(indexComment); database.addSchemaObject(session, index); if (index.getIndexType().isPersistent() && !database.getReadOnly() && !database.getLog().containsInDoubtTransactions()) {
for (int size = indexes.size(); i < size; i++) { Index index = indexes.get(i); index.add(session, row); checkRowCount(session, index, 1); while (--i >= 0) { Index index = indexes.get(i); index.remove(session, row); checkRowCount(session, index, 0); if (de.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) { for (Index index : indexes) { if (index.getIndexType().isUnique() && index instanceof MultiVersionIndex) { MultiVersionIndex mv = (MultiVersionIndex) index; if (mv.isUncommittedFromOtherSession(session, row)) { throw DbException.get( ErrorCode.CONCURRENT_UPDATE_1, index.getName());
for (int j = 0; indexes != null && j < indexes.size(); j++) { Index index = indexes.get(j); if (index.getCreateSQL() == null) { continue; Constraint constraint = constraints.get(k); if (constraint.usesIndex(index)) { if (index.getIndexType().isPrimaryKey()) { if (constraint.getConstraintType() == Constraint.Type.PRIMARY_KEY) { constraintName = constraint.getName(); IndexColumn[] cols = index.getIndexColumns(); String indexClass; if (index instanceof MultiVersionIndex) { index.getIndexType().isUnique() ? "FALSE" : "TRUE", String uniqueIndexName = null; if (index != null) { uniqueIndexName = index.getName();
private void rebuildIndexBuffered(Session session, Index index) { Index scan = getScanIndex(session); long remaining = scan.getRowCount(session); long total = remaining; Cursor cursor = scan.find(session, null, null); long i = 0; int bufferSize = (int) Math.min(total, database.getMaxMemoryRows()); ArrayList<Row> buffer = new ArrayList<>(bufferSize); String n = getName() + ":" + index.getName(); int t = MathUtils.convertLongToInt(total); while (cursor.next()) { Row row = cursor.get(); buffer.add(row); database.setProgress(DatabaseEventListener.STATE_CREATE_INDEX, n, MathUtils.convertLongToInt(i++), t); if (buffer.size() >= bufferSize) { addRowsToIndex(session, buffer, index); } remaining--; } addRowsToIndex(session, buffer, index); if (SysProperties.CHECK && remaining != 0) { DbException.throwInternalError("rowcount remaining=" + remaining + " " + getName()); } }
@Override public void addRow(Session session, Row row) { lastModificationId = database.getNextModificationDataId(); Transaction t = session.getTransaction(); long savepoint = t.setSavepoint(); try { for (Index index : indexes) { index.add(session, row); } } catch (Throwable e) { t.rollbackToSavepoint(savepoint); DbException de = DbException.convert(e); if (de.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) { for (Index index : indexes) { if (index.getIndexType().isUnique() && index instanceof MultiVersionIndex) { MultiVersionIndex mv = (MultiVersionIndex) index; if (mv.isUncommittedFromOtherSession(session, row)) { throw DbException.get( ErrorCode.CONCURRENT_UPDATE_1, index.getName()); } } } } throw de; } analyzeIfRequired(session); }
int[] sortTypes = sort.getSortTypesWithNullPosition(); for (Index index : list) { if (index.getCreateSQL() == null) { if (index.getIndexType().isHash()) { continue; IndexColumn[] indexCols = index.getIndexColumns(); if (indexCols.length < sortCols.length) { continue; if (index.isRowIdIndex()) { return index;
@Override public Value[] next() { if (resultCursor == null) { Index idx; if (distinct || sort != null) { idx = index; } else { idx = table.getScanIndex(session); } if (session.getDatabase().getMvStore() != null) { // sometimes the transaction is already committed, // in which case we can't use the session if (idx.getRowCount(session) == 0 && rowCount > 0) { // this means querying is not transactional resultCursor = idx.find((Session) null, null, null); } else { // the transaction is still open resultCursor = idx.find(session, null, null); } } else { resultCursor = idx.find(session, null, null); } } if (!resultCursor.next()) { return null; } Row row = resultCursor.get(); return row.getValueList(); }
return null; IndexColumn[] cols = target.getIndexColumns(); String proxyName = target.getName() + "_proxy"; if (target.getIndexType().isSpatial()) return new GridH2ProxySpatialIndex(this, proxyName, proxyCols, target);
if (index.getName() != null) { database.removeSchemaObject(session, index); for (SchemaObject obj : database.getAllSchemaObjects(DbObject.INDEX)) { Index index = (Index) obj; if (index.getTable() == this) { DbException.throwInternalError("index not dropped: " + index.getName()); scanIndex.remove(session); database.removeMeta(session, getId()); scanIndex = null;
long count = index.getRowCount(session); if (count == 0) { return ValueNull.INSTANCE; Cursor cursor = index.find(session, null, null); cursor.next(); int columnId = index.getColumns()[0].getColumnId(); ExpressionColumn expr = (ExpressionColumn) on; if (expr.getColumn().isNullable()) { SearchRow check = tableFilter.getTable().getTemplateSimpleRow(true); check.setValue(columnId, ValueNull.INSTANCE); Cursor nullsCursor = index.find(session, check, check); while (nullsCursor.next()) { count--;
@Override public List<Future<Cursor>> find() { if (!full) { return Collections.emptyList(); } Cursor c = filter.getIndex().find(filter, first, last); result.set(0, new DoneFuture<>(c)); full = false; first = last = null; return result; } }
for (Column col : columnsToDrop) { for (Index index : indexes) { if (index.getCreateSQL() == null) { continue; 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());
@Override public long getRowCount(Session session) { return base.getRowCount(session); }