Skip to content

Commit

Permalink
fixed issue #3627 - wrong number of result when limit is used
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed Mar 16, 2015
1 parent 92599ca commit b90e757
Showing 1 changed file with 12 additions and 6 deletions.
Expand Up @@ -548,8 +548,10 @@ protected boolean handleResult(final OIdentifiable iRecord) {

resultCount++;

if (!addResult(lastRecord))
if (!addResult(lastRecord)) {
return false;
}


return !((orderedFields.isEmpty() || fullySortedByIndex || isRidOnlySort()) && !isAnyFunctionAggregates()
&& (groupByFields == null || groupByFields.isEmpty()) && fetchLimit > -1 && resultCount >= fetchLimit);
Expand All @@ -571,6 +573,7 @@ protected int getTemporaryRIDCounter() {
}

protected boolean addResult(OIdentifiable iRecord) {
System.out.println("adding "+iRecord);
if (iRecord == null)
return true;

Expand Down Expand Up @@ -1294,7 +1297,7 @@ public void initContext() {
metricRecorder.setContext(context);
}

private void fetchFromTarget(final Iterator<? extends OIdentifiable> iTarget) {
private boolean fetchFromTarget(final Iterator<? extends OIdentifiable> iTarget) {
fetchLimit = getQueryFetchLimit();

final long startFetching = System.currentTimeMillis();
Expand Down Expand Up @@ -1322,7 +1325,7 @@ private void fetchFromTarget(final Iterator<? extends OIdentifiable> iTarget) {
}

if (!executeSearchRecord(next))
break;
return false;

if (queryScanThresholdWarning > 0 && browsed > queryScanThresholdWarning && compiledFilter != null) {
reportTip(String
Expand All @@ -1333,6 +1336,7 @@ private void fetchFromTarget(final Iterator<? extends OIdentifiable> iTarget) {
}
}
}
return true;

} finally {
context.setVariable("fetchingFromTargetElapsed", (System.currentTimeMillis() - startFetching));
Expand Down Expand Up @@ -1815,7 +1819,9 @@ private boolean searchForIndexes(final OClass iSchemaClass) {

uniqueResult = new HashSet<ORID>();
for (OIndexCursor cursor : cursors) {
fetchValuesFromIndexCursor(cursor);
if(!fetchValuesFromIndexCursor(cursor)){
break;
}
}
uniqueResult.clear();
uniqueResult = null;
Expand Down Expand Up @@ -1913,7 +1919,7 @@ private OIndexCursor getOptimizedSortCursor(OClass iSchemaClass) {
return null;
}

private void fetchValuesFromIndexCursor(final OIndexCursor cursor) {
private boolean fetchValuesFromIndexCursor(final OIndexCursor cursor) {
int needsToFetch;
if (fetchLimit > 0) {
needsToFetch = fetchLimit + skip;
Expand All @@ -1922,7 +1928,7 @@ private void fetchValuesFromIndexCursor(final OIndexCursor cursor) {
}

cursor.setPrefetchSize(needsToFetch);
fetchFromTarget(cursor);
return fetchFromTarget(cursor);
}

private void fetchEntriesFromIndexCursor(final OIndexCursor cursor) {
Expand Down

0 comments on commit b90e757

Please sign in to comment.