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()) { if (filter != null && filter.filterAllRemaining()) {
return MatchCode.DONE_SCAN; return MatchCode.DONE_SCAN;
} }
int ret = this.rowComparator.compareRows(curCell, cell); if (curCell != null) {
if (!this.isReversed) { int ret = this.rowComparator.compareRows(curCell, cell);
if (ret <= -1) { if (!this.isReversed) {
return MatchCode.DONE; if (ret <= -1) {
} else if (ret >= 1) { return MatchCode.DONE;
// could optimize this, if necessary? } else if (ret >= 1) {
// Could also be called SEEK_TO_CURRENT_ROW, but this // could optimize this, if necessary?
// should be rare/never happens. // Could also be called SEEK_TO_CURRENT_ROW, but this
return MatchCode.SEEK_NEXT_ROW; // 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 { } else {
if (ret <= -1) { // Since the curCell is null it means we are already sure that we have moved over to the next row
return MatchCode.SEEK_NEXT_ROW; return MatchCode.DONE;
} else if (ret >= 1) {
return MatchCode.DONE;
}
} }
// optimize case. // optimize case.
if (this.stickyNextRow) if (this.stickyNextRow) {
return MatchCode.SEEK_NEXT_ROW; return MatchCode.SEEK_NEXT_ROW;
}
if (this.columns.done()) { if (this.columns.done()) {
stickyNextRow = true; 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 // 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 // rows. Else it is possible we are still traversing the same row so we must perform the row
// comparison. // comparison.
if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.curCell == null if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.curCell == null) {
|| !CellUtil.matchingRow(cell, matcher.curCell)) {
this.countPerRow = 0; this.countPerRow = 0;
matcher.setToNewRow(cell); 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. if (prevCell != cell) ++kvsScanned; // Do object compare - we set prevKV from the same heap.
checkScanOrder(prevCell, cell, comparator); checkScanOrder(prevCell, cell, comparator);
prevCell = cell; prevCell = cell;
ScanQueryMatcher.MatchCode qcode = matcher.match(cell); ScanQueryMatcher.MatchCode qcode = matcher.match(cell);
qcode = optimize(qcode, cell); qcode = optimize(qcode, cell);
switch (qcode) { switch (qcode) {
@ -553,6 +551,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
if (!matcher.moreRowsMayExistAfter(cell)) { if (!matcher.moreRowsMayExistAfter(cell)) {
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues(); return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
} }
matcher.curCell = null;
seekToNextRow(cell); seekToNextRow(cell);
break LOOP; break LOOP;
} }
@ -580,6 +579,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
if (!matcher.moreRowsMayExistAfter(cell)) { if (!matcher.moreRowsMayExistAfter(cell)) {
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues(); return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
} }
matcher.curCell = null;
seekToNextRow(cell); seekToNextRow(cell);
} else if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL) { } else if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL) {
seekAsDirection(matcher.getKeyForNextColumn(cell)); seekAsDirection(matcher.getKeyForNextColumn(cell));
@ -596,6 +596,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
continue; continue;
case DONE: case DONE:
matcher.curCell = null;
return scannerContext.setScannerState(NextState.MORE_VALUES).hasMoreValues(); return scannerContext.setScannerState(NextState.MORE_VALUES).hasMoreValues();
case DONE_SCAN: case DONE_SCAN:
@ -608,7 +609,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
if (!matcher.moreRowsMayExistAfter(cell)) { if (!matcher.moreRowsMayExistAfter(cell)) {
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues(); return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
} }
matcher.curCell = null;
seekToNextRow(cell); seekToNextRow(cell);
break; break;
@ -751,7 +752,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner
} }
if ((matcher.curCell == null) || !CellUtil.matchingRows(cell, matcher.curCell)) { if ((matcher.curCell == null) || !CellUtil.matchingRows(cell, matcher.curCell)) {
this.countPerRow = 0; this.countPerRow = 0;
matcher.reset(); // The setToNewRow will call reset internally
matcher.setToNewRow(cell); matcher.setToNewRow(cell);
} }
} }