Skip to content

Commit

Permalink
attempt to fix delete index with key and rid condition
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Mar 21, 2017
1 parent 3945a04 commit a2af4e2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
Expand Up @@ -28,6 +28,7 @@ public CountStep(OCommandContext ctx) {
OResultSet prevResult = getPrev().get().syncPull(ctx, nRecords);
if (!prevResult.hasNext()) {
OInternalResultSet result = new OInternalResultSet();
resultRecord.setProperty("count", count);
result.add(resultRecord);
return result;
}
Expand Down
Expand Up @@ -65,22 +65,42 @@ private boolean handleIndexAsTarget(ODeleteExecutionPlan result, OIndexIdentifie

switch (indexIdentifier.getType()) {
case INDEX:
OBooleanExpression condition = null;
OBooleanExpression keyCondition = null;
OBooleanExpression ridCondition = null;
if (flattenedWhereClause == null || flattenedWhereClause.size() == 0) {
if (!index.supportsOrderedIterations()) {
throw new OCommandExecutionException("Index " + indexName + " does not allow iteration without a condition");
}
} else if (flattenedWhereClause.size() > 1) {
} else if (flattenedWhereClause.size() > 2) {
throw new OCommandExecutionException("Index queries with this kind of condition are not supported yet: " + whereClause);
} else {
OAndBlock andBlock = flattenedWhereClause.get(0);
if (andBlock.getSubBlocks().size() != 1) {
if (andBlock.getSubBlocks().size() == 1) {

whereClause = null;//The WHERE clause won't be used anymore, the index does all the filtering
flattenedWhereClause = null;
keyCondition = getKeyCondition(andBlock);
if (keyCondition == null) {
throw new OCommandExecutionException("Index queries with this kind of condition are not supported yet: " + whereClause);
}
} else if (andBlock.getSubBlocks().size() == 2) {
whereClause = null;//The WHERE clause won't be used anymore, the index does all the filtering
flattenedWhereClause = null;
keyCondition = getKeyCondition(andBlock);
ridCondition = getRidCondition(andBlock);
if (keyCondition == null || ridCondition == null) {
throw new OCommandExecutionException("Index queries with this kind of condition are not supported yet: " + whereClause);
}
} else {
throw new OCommandExecutionException("Index queries with this kind of condition are not supported yet: " + whereClause);
}

condition = andBlock.getSubBlocks().get(0);
}
result.chain(new DeleteFromIndexStep(index, condition, null, ctx));
result.chain(new DeleteFromIndexStep(index, keyCondition, null, ctx));
if (ridCondition != null) {
OWhereClause where = new OWhereClause(-1);
where.setBaseExpression(ridCondition);
result.chain(new FilterStep(where, ctx));
}
return true;
case VALUES:
case VALUESASC:
Expand Down Expand Up @@ -130,4 +150,31 @@ private void handleTarget(OUpdateExecutionPlan result, OCommandContext ctx, OFro
OSelectExecutionPlanner planner = new OSelectExecutionPlanner(sourceStatement);
result.chain(new SubQueryStep(planner.createExecutionPlan(ctx), ctx, ctx));
}

private OBooleanExpression getKeyCondition(OAndBlock andBlock) {
for (OBooleanExpression exp : andBlock.getSubBlocks()) {
String str = exp.toString();
if (str.length() < 5) {
continue;
}
if (str.substring(0, 4).equalsIgnoreCase("key ")) {
return exp;
}
}
return null;
}

private OBooleanExpression getRidCondition(OAndBlock andBlock) {
for (OBooleanExpression exp : andBlock.getSubBlocks()) {
String str = exp.toString();
if (str.length() < 5) {
continue;
}
if (str.substring(0, 4).equalsIgnoreCase("rid ")) {
return exp;
}
}
return null;
}

}
Expand Up @@ -761,7 +761,7 @@ private void handleIndexAsTarget(OSelectExecutionPlan result, OIndexIdentifier i
if (!index.supportsOrderedIterations()) {
throw new OCommandExecutionException("Index " + indexName + " does not allow iteration without a condition");
}
} else if (flattenedWhereClause.size() > 1) {
} else if (flattenedWhereClause.size() > 2) {
throw new OCommandExecutionException("Index queries with this kind of condition are not supported yet: " + whereClause);
} else {
OAndBlock andBlock = flattenedWhereClause.get(0);
Expand Down

0 comments on commit a2af4e2

Please sign in to comment.