From b90e757f1d5d74005d385d02bf8330aa4141bee7 Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Mon, 16 Mar 2015 12:11:45 +0100 Subject: [PATCH] fixed issue #3627 - wrong number of result when limit is used --- .../core/sql/OCommandExecutorSQLSelect.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java index 3f1b3177973..c989d33b41d 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java @@ -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); @@ -571,6 +573,7 @@ protected int getTemporaryRIDCounter() { } protected boolean addResult(OIdentifiable iRecord) { + System.out.println("adding "+iRecord); if (iRecord == null) return true; @@ -1294,7 +1297,7 @@ public void initContext() { metricRecorder.setContext(context); } - private void fetchFromTarget(final Iterator iTarget) { + private boolean fetchFromTarget(final Iterator iTarget) { fetchLimit = getQueryFetchLimit(); final long startFetching = System.currentTimeMillis(); @@ -1322,7 +1325,7 @@ private void fetchFromTarget(final Iterator iTarget) { } if (!executeSearchRecord(next)) - break; + return false; if (queryScanThresholdWarning > 0 && browsed > queryScanThresholdWarning && compiledFilter != null) { reportTip(String @@ -1333,6 +1336,7 @@ private void fetchFromTarget(final Iterator iTarget) { } } } + return true; } finally { context.setVariable("fetchingFromTargetElapsed", (System.currentTimeMillis() - startFetching)); @@ -1815,7 +1819,9 @@ private boolean searchForIndexes(final OClass iSchemaClass) { uniqueResult = new HashSet(); for (OIndexCursor cursor : cursors) { - fetchValuesFromIndexCursor(cursor); + if(!fetchValuesFromIndexCursor(cursor)){ + break; + } } uniqueResult.clear(); uniqueResult = null; @@ -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; @@ -1922,7 +1928,7 @@ private void fetchValuesFromIndexCursor(final OIndexCursor cursor) { } cursor.setPrefetchSize(needsToFetch); - fetchFromTarget(cursor); + return fetchFromTarget(cursor); } private void fetchEntriesFromIndexCursor(final OIndexCursor cursor) {