use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.
the class GridH2Table method removeChildrenAndResources.
/**
* {@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.
destroyIndex(idx);
}
}
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);
}
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.
the class GridH2Table method commitUserIndex.
/**
* Promote temporary index to make it usable in queries.
*
* @param ses H2 session.
* @param idxName Index name.
* @return Temporary index with given name.
*/
private Index commitUserIndex(Session ses, String idxName) {
lock(true);
try {
ensureNotDestroyed();
Index idx = tmpIdxs.remove(idxName);
assert idx != null;
Index cloneIdx = createDuplicateIndexIfNeeded(idx);
ArrayList<Index> newIdxs = new ArrayList<>(idxs.size() + ((cloneIdx == null) ? 1 : 2));
newIdxs.addAll(idxs);
newIdxs.add(idx);
if (cloneIdx != null)
newIdxs.add(cloneIdx);
idxs = newIdxs;
database.addSchemaObject(ses, idx);
if (cloneIdx != null)
database.addSchemaObject(ses, cloneIdx);
incrementModificationCounter();
return idx;
} finally {
unlock(true);
}
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.
the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method checkNoLeaks.
/**
* Ensure there are no leaks in data structures associated with distributed dml execution.
*/
private void checkNoLeaks() {
GridQueryProcessor qryProc = grid(NODE_CLIENT).context().query();
IgniteH2Indexing h2Idx = GridTestUtils.getFieldValue(qryProc, GridQueryProcessor.class, "idx");
GridReduceQueryExecutor rdcQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "rdcQryExec");
Map updRuns = GridTestUtils.getFieldValue(rdcQryExec, GridReduceQueryExecutor.class, "updRuns");
assertEquals(0, updRuns.size());
for (int idx = 0; idx < NODE_COUNT; idx++) {
qryProc = grid(idx).context().query();
h2Idx = GridTestUtils.getFieldValue(qryProc, GridQueryProcessor.class, "idx");
GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");
Map qryRess = GridTestUtils.getFieldValue(mapQryExec, GridMapQueryExecutor.class, "qryRess");
for (Object obj : qryRess.values()) {
Map updCancels = GridTestUtils.getFieldValue(obj, "updCancels");
assertEquals(0, updCancels.size());
}
}
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.
the class IgniteH2Indexing method executeUpdateNonTransactional.
/**
* Execute update in non-transactional mode.
*
* @param qryId Query id.
* @param qryDesc Query descriptor.
* @param qryParams Query parameters.
* @param dml Plan.
* @param loc Local flag.
* @param filters Filters.
* @param cancel Cancel hook.
* @return Update result.
* @throws IgniteCheckedException If failed.
*/
private UpdateResult executeUpdateNonTransactional(long qryId, QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultDml dml, boolean loc, IndexingQueryFilter filters, GridQueryCancel cancel) throws IgniteCheckedException {
UpdatePlan plan = dml.plan();
UpdateResult fastUpdateRes = plan.processFast(qryParams.arguments());
if (fastUpdateRes != null)
return fastUpdateRes;
DmlDistributedPlanInfo distributedPlan = loc ? null : plan.distributedPlan();
if (distributedPlan != null) {
if (cancel == null)
cancel = new GridQueryCancel();
UpdateResult result = rdcQryExec.update(qryDesc.schemaName(), distributedPlan.getCacheIds(), qryDesc.sql(), qryParams.arguments(), qryDesc.enforceJoinOrder(), qryParams.pageSize(), qryParams.timeout(), qryParams.partitions(), distributedPlan.isReplicatedOnly(), cancel);
// Null is returned in case not all nodes support distributed DML.
if (result != null)
return result;
}
final GridQueryCancel selectCancel = (cancel != null) ? new GridQueryCancel() : null;
if (cancel != null)
cancel.add(selectCancel::cancel);
SqlFieldsQuery selectFieldsQry = new SqlFieldsQuery(plan.selectQuery(), qryDesc.collocated()).setArgs(qryParams.arguments()).setDistributedJoins(qryDesc.distributedJoins()).setEnforceJoinOrder(qryDesc.enforceJoinOrder()).setLocal(qryDesc.local()).setPageSize(qryParams.pageSize()).setTimeout(qryParams.timeout(), TimeUnit.MILLISECONDS).setLazy(qryParams.lazy() && plan.canSelectBeLazy());
Iterable<List<?>> cur;
// sub-query and not some dummy stuff like "select 1, 2, 3;"
if (!loc && !plan.isLocalSubquery()) {
assert !F.isEmpty(plan.selectQuery());
cur = executeSelectForDml(qryId, qryDesc.schemaName(), selectFieldsQry, null, selectCancel, qryParams.timeout());
} else if (plan.hasRows())
cur = plan.createRows(qryParams.arguments());
else {
selectFieldsQry.setLocal(true);
QueryParserResult selectParseRes = parser.parse(qryDesc.schemaName(), selectFieldsQry, false);
final GridQueryFieldsResult res = executeSelectLocal(qryId, selectParseRes.queryDescriptor(), selectParseRes.queryParameters(), selectParseRes.select(), filters, null, selectCancel, false, qryParams.timeout());
cur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
try {
return new GridQueryCacheObjectsIterator(res.iterator(), objectContext(), true);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
}, cancel, true, qryParams.lazy());
}
int pageSize = qryParams.updateBatchSize();
// TODO: IGNITE-11176 - Need to support cancellation
try {
return DmlUtils.processSelectResult(plan, cur, pageSize);
} finally {
if (cur instanceof AutoCloseable)
U.closeQuiet((AutoCloseable) cur);
}
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.
the class GridSubqueryJoinOptimizer method pullOutSubQryFromInClause.
/**
* Pull out sub-select from IN clause to the parent select level.
* <p>
* Example:
* <pre>
* Before:
* SELECT name
* FROM emp e
* WHERE e.dep_id IN (SELECT d.id FROM dep d WHERE d.name = 'dep1')
* AND sal > 2000
*
* After:
* SELECT name
* FROM emp e
* JOIN dep d
* WHERE sal > 2000 AND d.id = e.dep_id and d.name = 'dep1
* </pre>
*
* @param parent Parent select.
* @param targetEl Target sql element. Can be {@code null}.
* @param childInd Column index.
*/
private static boolean pullOutSubQryFromInClause(GridSqlSelect parent, @Nullable GridSqlAst targetEl, int childInd) {
// extract sub-query
GridSqlSubquery subQry = targetEl != null ? targetEl.child(childInd).child(1) : parent.where().child(1);
if (!isSimpleSelect(subQry.subquery()))
return false;
GridSqlSelect subS = subQry.subquery();
GridSqlAst leftExpr = targetEl != null ? targetEl.child(childInd).child(0) : parent.where().child(0);
// 4) c1 + c2/const IN (SELECT in_col FROM ...)
if (subS.visibleColumns() != 1)
return false;
List<GridSqlElement> conditions = new ArrayList<>();
if (leftExpr instanceof GridSqlArray) {
GridSqlAst col = subS.columns(true).get(0);
if (!(col instanceof GridSqlArray) || leftExpr.size() != col.size())
return false;
for (int i = 0; i < col.size(); i++) {
GridSqlElement el = leftExpr.child(i);
conditions.add(new GridSqlOperation(EQUAL, el, col.child(i)));
}
} else if (targetEl instanceof GridSqlFunction)
return false;
else
conditions.add(new GridSqlOperation(EQUAL, leftExpr, subS.columns(true).get(0)));
// save old condition and IN expression to restore them
// in case of unsuccessfull pull out
GridSqlElement oldCond = (GridSqlElement) subS.where();
if (oldCond != null)
conditions.add(oldCond);
GridSqlElement oldInExpr = targetEl != null ? targetEl.child(childInd) : (GridSqlElement) parent.where();
// update sub-query condition and convert IN clause to EXISTS
subS.where(buildConditionBush(conditions));
GridSqlOperation existsExpr = new GridSqlOperation(EXISTS, subQry);
if (targetEl != null)
targetEl.child(childInd, existsExpr);
else
parent.where(existsExpr);
boolean res = pullOutSubQryFromExistsClause(parent, targetEl, childInd);
if (!res) {
// restore original query in case of failure
if (targetEl != null)
targetEl.child(childInd, oldInExpr);
else
parent.where(oldInExpr);
subS.where(oldCond);
}
return res;
}
Aggregations