Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,11 @@ public List<ShowDevicesResult> getDevices(ShowDevicesPlan plan) throws MetadataE
// do not use limit and offset in sub-queries unless offset is 0, otherwise the results are
// not combinable
if (offset != 0) {
plan.setLimit(0);
if (limit > Integer.MAX_VALUE - offset) {
plan.setLimit(0);
} else {
plan.setLimit(limit + offset);
}
plan.setOffset(0);
}

Expand Down Expand Up @@ -1693,7 +1697,11 @@ public List<ShowTimeSeriesResult> showTimeseries(ShowTimeSeriesPlan plan, QueryC
// do not use limit and offset in sub-queries unless offset is 0, otherwise the results are
// not combinable
if (offset != 0) {
plan.setLimit(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be removed. Consider this case:
The offset is 10000, the limit is 10, and the results are distributed on 3 nodes. If you keep the limit, each of the 3 nodes will only return 10 results, 30 results in total, which will all be filtered when the offset is applied.
You may set the limit to limit + offset so the unnecessary fetch can be reduced.

if (limit > Integer.MAX_VALUE - offset) {
plan.setLimit(0);
} else {
plan.setLimit(limit + offset);
}
plan.setOffset(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public ShowPlan(
this.limit = limit;
this.offset = offset;
if (limit == 0) {
this.limit = fetchSize;
this.hasLimit = false;
} else {
this.hasLimit = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.apache.iotdb.tsfile.utils.Binary;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -43,16 +42,7 @@ protected ShowDataSet(List<Path> paths, List<TSDataType> dataTypes) {
}

@Override
public boolean hasNextWithoutConstraint() throws IOException {
if (index == result.size() && !hasLimit && result.size() == plan.getLimit()) {
plan.setOffset(plan.getOffset() + plan.getLimit());
try {
result = getQueryDataSet();
index = 0;
} catch (MetadataException e) {
throw new IOException(e);
}
}
public boolean hasNextWithoutConstraint() {
return index < result.size();
}

Expand Down
25 changes: 25 additions & 0 deletions testcontainer/src/test/java/org/apache/iotdb/db/sql/Cases.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,29 @@ public void multiCasesTest() throws SQLException {
resultSet.close();
}
}

// test https://issues.apache.org/jira/browse/IOTDB-1266
@Test
public void showTimeseriesRowsTest() throws SQLException {

int n = 3000;
String timeSeriesPrefix = "root.ln.wf01.wt";
String timeSeriesSuffix = ".temperature WITH DATATYPE=DOUBLE, ENCODING=RLE";
String timeSeries;
for (int i = 0; i < n; i++) {
timeSeries = timeSeriesPrefix + String.valueOf(i) + timeSeriesSuffix;
writeStatement.execute(String.format("create timeseries %s ", timeSeries));
}

// try to read data on each node.
for (Statement readStatement : readStatements) {
ResultSet resultSet = readStatement.executeQuery("SHOW TIMESERIES");
int cnt = 0;
while (resultSet.next()) {
cnt++;
}
Assert.assertEquals(n, cnt);
resultSet.close();
}
}
}