use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.AND in project ignite by apache.
the class DmlStatementsProcessor method getPlanForStatement.
/**
* Generate SELECT statements to retrieve data for modifications from and find fast UPDATE or DELETE args,
* if available.
*
* @param schema Schema.
* @param conn Connection.
* @param p Prepared statement.
* @param fieldsQry Original fields query.
* @param loc Local query flag.
* @return Update plan.
*/
@SuppressWarnings({ "unchecked", "ConstantConditions" })
UpdatePlan getPlanForStatement(String schema, Connection conn, Prepared p, SqlFieldsQuery fieldsQry, boolean loc, @Nullable Integer errKeysPos) throws IgniteCheckedException {
H2CachedStatementKey planKey = H2CachedStatementKey.forDmlStatement(schema, p.getSQL(), fieldsQry, loc);
UpdatePlan res = (errKeysPos == null ? planCache.get(planKey) : null);
if (res != null)
return res;
res = UpdatePlanBuilder.planForStatement(p, loc, idx, conn, fieldsQry, errKeysPos);
// Don't cache re-runs
if (errKeysPos == null)
return U.firstNotNull(planCache.putIfAbsent(planKey, res), res);
else
return res;
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.AND in project ignite by apache.
the class UpdatePlanBuilder method checkPlanCanBeDistributed.
/**
* Checks whether the given update plan can be distributed and returns additional info.
*
* @param idx Indexing.
* @param mvccEnabled Mvcc flag.
* @param planKey Plan key.
* @param selectQry Derived select query.
* @param cacheName Cache name.
* @return distributed update plan info, or {@code null} if cannot be distributed.
* @throws IgniteCheckedException if failed.
*/
private static DmlDistributedPlanInfo checkPlanCanBeDistributed(IgniteH2Indexing idx, boolean mvccEnabled, QueryDescriptor planKey, String selectQry, String cacheName, IgniteLogger log) throws IgniteCheckedException {
if ((!mvccEnabled && !planKey.skipReducerOnUpdate()) || planKey.batched())
return null;
try (H2PooledConnection conn = idx.connections().connection(planKey.schemaName())) {
H2Utils.setupConnection(conn, QueryContext.parseContext(idx.backupFilter(null, null), planKey.local()), planKey.distributedJoins(), planKey.enforceJoinOrder());
// Get a new prepared statement for derived select query.
try (PreparedStatement stmt = conn.prepareStatement(selectQry, H2StatementCache.queryFlags(planKey))) {
Prepared prep = GridSqlQueryParser.prepared(stmt);
GridSqlQuery selectStmt = (GridSqlQuery) new GridSqlQueryParser(false, log).parse(prep);
GridCacheTwoStepQuery qry = GridSqlQuerySplitter.split(conn, selectStmt, selectQry, planKey.collocated(), planKey.distributedJoins(), planKey.enforceJoinOrder(), false, idx, prep.getParameters().size(), log);
boolean distributed = // No split for local
!qry.isLocalSplit() && // Over real caches
qry.hasCacheIds() && // No merge table
qry.skipMergeTable() && qry.mapQueries().size() == 1 && // One w/o subqueries
!qry.mapQueries().get(0).hasSubQueries();
if (distributed) {
List<Integer> cacheIds = H2Utils.collectCacheIds(idx, CU.cacheId(cacheName), qry.tables());
H2Utils.checkQuery(idx, cacheIds, qry.tables());
return new DmlDistributedPlanInfo(qry.isReplicatedOnly(), cacheIds, qry.derivedPartitions());
} else
return null;
}
} catch (SQLException e) {
throw new IgniteCheckedException(e);
}
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.AND in project ignite by apache.
the class GridH2Table method indexesInformation.
/**
* @return Information about all indexes related to the table.
*/
@SuppressWarnings("ZeroLengthArrayAllocation")
public List<IndexInformation> indexesInformation() {
List<IndexInformation> res = new ArrayList<>();
IndexColumn keyCol = indexColumn(QueryUtils.KEY_COL, SortOrder.ASCENDING);
List<IndexColumn> wrappedKeyCols = H2Utils.treeIndexColumns(rowDescriptor(), new ArrayList<>(2), keyCol, affKeyCol);
// explicit add HASH index, due to we know all their parameters and it doesn't created on non afinity nodes.
res.add(new IndexInformation(false, true, PK_HASH_IDX_NAME, H2IndexType.HASH, H2Utils.indexColumnsSql(H2Utils.unwrapKeyColumns(this, wrappedKeyCols.toArray(new IndexColumn[0]))), null));
// explicit add SCAN index, due to we know all their parameters and it depends on affinity node or not.
res.add(new IndexInformation(false, false, SCAN_INDEX_NAME_SUFFIX, H2IndexType.SCAN, null, null));
for (Index idx : idxs) {
if (idx instanceof H2TreeIndexBase) {
res.add(new IndexInformation(idx.getIndexType().isPrimaryKey(), idx.getIndexType().isUnique(), idx.getName(), H2IndexType.BTREE, H2Utils.indexColumnsSql(H2Utils.unwrapKeyColumns(this, idx.getIndexColumns())), ((H2TreeIndexBase) idx).inlineSize()));
} else if (idx.getIndexType().isSpatial()) {
res.add(new IndexInformation(false, false, idx.getName(), H2IndexType.SPATIAL, H2Utils.indexColumnsSql(idx.getIndexColumns()), null));
}
}
return res;
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.AND in project ignite by apache.
the class GridH2Table method proposeUserIndex.
/**
* 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();
Index idxExist = checkIndexPresence(idx);
if (idxExist != null) {
String idxCols = Stream.of(idxExist.getIndexColumns()).map(k -> k.columnName).collect(Collectors.joining(", "));
U.warn(log, "Index with the given set or subset of columns already exists " + "(consider dropping either new or existing index) [cacheName=" + cacheInfo.name() + ", " + "schemaName=" + getSchema().getName() + ", tableName=" + getName() + ", newIndexName=" + idx.getName() + ", existingIndexName=" + idxExist.getName() + ", existingIndexColumns=[" + idxCols + "]]");
}
Index oldTmpIdx = tmpIdxs.put(idx.getName(), (GridH2IndexBase) idx);
assert oldTmpIdx == null;
} finally {
unlock(true);
}
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.AND in project ignite by apache.
the class GridH2Table method createDuplicateIndexIfNeeded.
/**
* Creates proxy index for given target index.
* Proxy index refers to alternative key and val columns.
*
* @param target Index to clone.
* @return Proxy index.
*/
private Index createDuplicateIndexIfNeeded(Index target) {
if (!(target instanceof H2TreeIndexBase) && !(target instanceof SpatialIndex))
return null;
IndexColumn[] cols = target.getIndexColumns();
List<IndexColumn> proxyCols = new ArrayList<>(cols.length);
boolean modified = false;
for (IndexColumn col : cols) {
IndexColumn proxyCol = new IndexColumn();
proxyCol.columnName = col.columnName;
proxyCol.column = col.column;
proxyCol.sortType = col.sortType;
int altColId = desc.getAlternativeColumnId(proxyCol.column.getColumnId());
if (altColId != proxyCol.column.getColumnId()) {
proxyCol.column = getColumn(altColId);
proxyCol.columnName = proxyCol.column.getName();
modified = true;
}
proxyCols.add(proxyCol);
}
if (modified) {
String proxyName = target.getName() + "_proxy";
if (target.getIndexType().isSpatial())
return new GridH2ProxySpatialIndex(this, proxyName, proxyCols, target);
return new GridH2ProxyIndex(this, proxyName, proxyCols, target);
}
return null;
}
Aggregations