Skip to content

Commit

Permalink
fix index scan bug (#995) (#1024)
Browse files Browse the repository at this point in the history
(cherry picked from commit 911e890)
  • Loading branch information
marsishandsome authored Aug 15, 2019
1 parent 987f899 commit 72136f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,7 @@ private DAGRequest.Builder buildScan(boolean buildIndexScan) {
if (pos != null) {
TiColumnInfo columnInfo = columnInfoList.get(indexColOffsets.get(pos));
if (col.getColumnInfo().equals(columnInfo)) {
dagRequestBuilder.addOutputOffsets(pos);
colOffsetInFieldMap.put(col, pos);
addRequiredIndexDataType(col.getType());
}
// TODO: primary key may also be considered if pkIsHandle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.pingcap.tikv.util.RangeSplitter.RegionTask;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

public abstract class CoprocessIterator<T> implements Iterator<T> {
protected final TiSession session;
Expand Down Expand Up @@ -80,11 +79,7 @@ public static CoprocessIterator<Row> getRowIterator(
dagRequest.getPushDownType()) {
@Override
public Row next() {
if (hasNext()) {
return rowReader.readRow(schemaInfer.getTypes().toArray(new DataType[0]));
} else {
throw new NoSuchElementException();
}
return rowReader.readRow(schemaInfer.getTypes().toArray(new DataType[0]));
}
};
}
Expand All @@ -109,11 +104,7 @@ public static CoprocessIterator<Long> getHandleIterator(
req.getPushDownType()) {
@Override
public Long next() {
if (hasNext()) {
return rowReader.readRow(handleTypes).getLong(handleTypes.length - 1);
} else {
throw new NoSuchElementException();
}
return rowReader.readRow(handleTypes).getLong(handleTypes.length - 1);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ public void staleEpochTest() {
server.put("key1", cdo.toByteString());
List<RegionTask> tasks = ImmutableList.of(RegionTask.newInstance(region, store, keyRanges));
CoprocessIterator<Row> iter = CoprocessIterator.getRowIterator(req, tasks, session);
Row r = iter.next();
SchemaInfer infer = SchemaInfer.create(req);
assertEquals(r.get(0, infer.getType(0)), 666L);
assertEquals(r.get(1, infer.getType(1)), "value1");
if (!iter.hasNext()) {
assertEquals("iterator has next should be true", true, false);
} else {
Row r = iter.next();
SchemaInfer infer = SchemaInfer.create(req);
assertEquals(r.get(0, infer.getType(0)), 666L);
assertEquals(r.get(1, infer.getType(1)), "value1");
}
}

private static KeyRange createByteStringRange(ByteString sKey, ByteString eKey) {
Expand Down

0 comments on commit 72136f6

Please sign in to comment.