HBASE-14221 Reduce the number of time row comparison is done in a Scan

(Ram)
This commit is contained in:
ramkrishna 2016-01-06 10:38:27 +05:30
parent 7cd09bfb91
commit 073e00c005
2 changed files with 27 additions and 20 deletions

View File

@ -283,27 +283,33 @@ public class ScanQueryMatcher {
if (filter != null && filter.filterAllRemaining()) {
return MatchCode.DONE_SCAN;
}
int ret = this.rowComparator.compareRows(curCell, cell);
if (!this.isReversed) {
if (ret <= -1) {
return MatchCode.DONE;
} else if (ret >= 1) {
// could optimize this, if necessary?
// Could also be called SEEK_TO_CURRENT_ROW, but this
// should be rare/never happens.
return MatchCode.SEEK_NEXT_ROW;
if (curCell != null) {
int ret = this.rowComparator.compareRows(curCell, cell);
if (!this.isReversed) {
if (ret <= -1) {
return MatchCode.DONE;
} else if (ret >= 1) {
// could optimize this, if necessary?
// Could also be called SEEK_TO_CURRENT_ROW, but this
// should be rare/never happens.
return MatchCode.SEEK_NEXT_ROW;
}
} else {
if (ret <= -1) {
return MatchCode.SEEK_NEXT_ROW;
} else if (ret >= 1) {
return MatchCode.DONE;
}
}
} else {
if (ret <= -1) {
return MatchCode.SEEK_NEXT_ROW;
} else if (ret >= 1) {
return MatchCode.DONE;
}
// Since the curCell is null it means we are already sure that we have moved over to the next row
return MatchCode.DONE;
}
// optimize case.
if (this.stickyNextRow)
if (this.stickyNextRow) {
return MatchCode.SEEK_NEXT_ROW;
}
if (this.columns.done()) {
stickyNextRow = true;

View File

@ -507,8 +507,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
// If no limits exists in the scope LimitScope.Between_Cells then we are sure we are changing
// rows. Else it is possible we are still traversing the same row so we must perform the row
// comparison.
if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.curCell == null
|| !CellUtil.matchingRow(cell, matcher.curCell)) {
if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.curCell == null) {
this.countPerRow = 0;
matcher.setToNewRow(cell);
}
@ -534,7 +533,6 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
if (prevCell != cell) ++kvsScanned; // Do object compare - we set prevKV from the same heap.
checkScanOrder(prevCell, cell, comparator);
prevCell = cell;
ScanQueryMatcher.MatchCode qcode = matcher.match(cell);
qcode = optimize(qcode, cell);
switch (qcode) {
@ -553,6 +551,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
if (!matcher.moreRowsMayExistAfter(cell)) {
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
}
matcher.curCell = null;
seekToNextRow(cell);
break LOOP;
}
@ -580,6 +579,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
if (!matcher.moreRowsMayExistAfter(cell)) {
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
}
matcher.curCell = null;
seekToNextRow(cell);
} else if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL) {
seekAsDirection(matcher.getKeyForNextColumn(cell));
@ -596,6 +596,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
continue;
case DONE:
matcher.curCell = null;
return scannerContext.setScannerState(NextState.MORE_VALUES).hasMoreValues();
case DONE_SCAN:
@ -608,7 +609,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
if (!matcher.moreRowsMayExistAfter(cell)) {
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
}
matcher.curCell = null;
seekToNextRow(cell);
break;
@ -751,7 +752,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
}
if ((matcher.curCell == null) || !CellUtil.matchingRows(cell, matcher.curCell)) {
this.countPerRow = 0;
matcher.reset();
// The setToNewRow will call reset internally
matcher.setToNewRow(cell);
}
}