@Override public String getName() { return base.getName(); }
/** * Allow an index to be used. * * @param index the index * @return whether it was already allowed */ public boolean allowIndex(Index index) { return allowedIndexes.contains(index.getName()); } }
/** * Check whether user index with provided name exists. * * @param idxName Index name. * @return {@code True} if exists. */ public boolean containsUserIndex(String idxName) { for (int i = 2; i < idxs.size(); i++) { Index idx = idxs.get(i); if (idx.getName().equalsIgnoreCase(idxName)) return true; } return false; }
/** * 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); } } }
/** * Add a local temporary index to this session. * * @param index the index to add * @throws DbException if a index with this name already exists */ public void addLocalTempTableIndex(Index index) { if (localTempTableIndexes == null) { localTempTableIndexes = database.newStringMap(); } if (localTempTableIndexes.get(index.getName()) != null) { throw DbException.get(ErrorCode.INDEX_ALREADY_EXISTS_1, index.getSQL()); } localTempTableIndexes.put(index.getName(), index); }
/** * Get an index by name. * * @param indexName the index name to search for * @return the found index */ public Index getIndex(String indexName) { ArrayList<Index> indexes = getIndexes(); if (indexes != null) { for (Index index : indexes) { if (index.getName().equals(indexName)) { return index; } } } throw DbException.get(ErrorCode.INDEX_NOT_FOUND_1, indexName); }
/** * Add index that is in an intermediate state and is still being built, thus is not used in queries until it is * promoted. * * @param idx Index to add. * @throws IgniteCheckedException If failed. */ public void proposeUserIndex(Index idx) throws IgniteCheckedException { assert idx instanceof GridH2IndexBase; lock(true); try { ensureNotDestroyed(); for (Index oldIdx : idxs) { if (F.eq(oldIdx.getName(), idx.getName())) throw new IgniteCheckedException("Index already exists: " + idx.getName()); } Index oldTmpIdx = tmpIdxs.put(idx.getName(), (GridH2IndexBase)idx); assert oldTmpIdx == null; } finally { unlock(true); } }
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()); } } } }
private IndexHints parseIndexHints(Table table) { if (table == null) { throw getSyntaxError(); } read("("); LinkedHashSet<String> indexNames = new LinkedHashSet<>(); if (!readIf(")")) { do { String indexName = readIdentifierWithSchema(); Index index = table.getIndex(indexName); indexNames.add(index.getName()); } while (readIfMore(true)); } return IndexHints.createUseIndexHints(indexNames); }
/** * Remove the given index from the list. * * @param h2Idx the index to remove */ public void removeIndex(Session session, Index h2Idx) { lock(true); try { ArrayList<Index> idxs = new ArrayList<>(this.idxs); Index targetIdx = (h2Idx instanceof GridH2ProxyIndex) ? ((GridH2ProxyIndex)h2Idx).underlyingIndex() : h2Idx; for (int i = pkIndexPos; i < idxs.size();) { Index idx = idxs.get(i); if (idx == targetIdx || (idx instanceof GridH2ProxyIndex && ((GridH2ProxyIndex)idx).underlyingIndex() == targetIdx)) { idxs.remove(i); if (idx instanceof GridH2ProxyIndex && idx.getSchema().findIndex(session, idx.getName()) != null) database.removeSchemaObject(session, idx); continue; } i++; } this.idxs = idxs; } finally { unlock(true); } }
/** {@inheritDoc} */ @Override public void removeChildrenAndResources(Session ses) { lock(true); try { super.removeChildrenAndResources(ses); // Clear all user indexes registered in schema. while (idxs.size() > sysIdxsCnt) { Index idx = idxs.get(sysIdxsCnt); if (idx.getName() != null && idx.getSchema().findIndex(ses, idx.getName()) == idx) { // This call implicitly removes both idx and its proxy, if any, from idxs. database.removeSchemaObject(ses, idx); // We have to call destroy here if we are who has removed this index from the table. if (idx instanceof GridH2IndexBase) ((GridH2IndexBase)idx).destroy(rmIndex); } } if (SysProperties.CHECK) { for (SchemaObject obj : database.getAllSchemaObjects(DbObject.INDEX)) { Index idx = (Index) obj; if (idx.getTable() == this) DbException.throwInternalError("index not dropped: " + idx.getName()); } } database.removeMeta(ses, getId()); invalidate(); } finally { unlock(true); } }
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()); } }
String proxyName = target.getName() + "_proxy";
if (mv.isUncommittedFromOtherSession(session, row)) { throw DbException.get( ErrorCode.CONCURRENT_UPDATE_1, index.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); }
o.toString(), cacheCtx.name(), idx.getName(), t);
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()) {