use of com.actiontech.dble.plan.common.item.subquery.ItemExistsSubQuery in project dble by actiontech.
the class PlanUtil method rebuildSubQueryItem.
public static Item rebuildSubQueryItem(Item item) {
if (!item.isWithSubQuery()) {
return item;
}
BoolPtr reBuild = new BoolPtr(false);
if (PlanUtil.isCmpFunc(item)) {
Item res1 = rebuildBoolSubQuery(item, 0, reBuild);
if (res1 != null) {
return res1;
}
Item res2 = rebuildBoolSubQuery(item, 1, reBuild);
if (res2 != null) {
return res2;
}
} else if (item instanceof ItemInSubQuery) {
ItemInSubQuery inSubItem = (ItemInSubQuery) item;
if (inSubItem.getValue().size() == 0) {
return genBoolItem(inSubItem.isNeg());
} else {
List<Item> args = new ArrayList<>(inSubItem.getValue().size() + 1);
args.add(inSubItem.getLeftOperand());
args.addAll(inSubItem.getValue());
return new ItemFuncIn(args, inSubItem.isNeg());
}
} else if (item instanceof ItemExistsSubQuery) {
ItemExistsSubQuery existsSubQuery = (ItemExistsSubQuery) item;
Item result = existsSubQuery.getValue();
if (result == null) {
return genBoolItem(existsSubQuery.isNot());
} else {
return genBoolItem(!existsSubQuery.isNot());
}
} else if (item instanceof ItemCondAnd || item instanceof ItemCondOr) {
for (int index = 0; index < item.getArgCount(); index++) {
Item rebuildItem = rebuildSubQueryItem(item.arguments().get(index));
item.arguments().set(index, rebuildItem);
item.setItemName(null);
}
} else if (item instanceof ItemScalarSubQuery) {
Item result = ((ItemScalarSubQuery) item).getValue();
if (result == null || result.getResultItem() == null) {
return new ItemFuncEqual(new ItemInt(1), new ItemInt(0));
}
return result.getResultItem();
}
if (!reBuild.get() && item instanceof ItemFunc) {
return rebuildSubQueryFuncItem(item);
}
return item;
}
use of com.actiontech.dble.plan.common.item.subquery.ItemExistsSubQuery in project dble by actiontech.
the class MySQLItemVisitor method endVisit.
@Override
public void endVisit(SQLExistsExpr x) {
SQLSelectQuery sqlSelect = x.getSubQuery().getQuery();
item = new ItemExistsSubQuery(currentDb, sqlSelect, x.isNot(), metaManager);
}
Aggregations