[fix](query-cache) fix query cache with empty set (#24147)

If the query result set is empty, the query cache will not cache the result.
This PR fix it.
This commit is contained in:
Mingyu Chen
2023-09-12 20:11:20 +08:00
committed by GitHub
parent c926e8ff9d
commit c402d48f97
4 changed files with 547 additions and 9 deletions

View File

@ -1248,6 +1248,8 @@ public class StmtExecutor {
boolean isSend = isSendFields;
for (InternalService.PCacheValue value : cacheValues) {
TResultBatch resultBatch = new TResultBatch();
// need to set empty list first, to support empty result set.
resultBatch.setRows(Lists.newArrayList());
for (ByteString one : value.getRowsList()) {
resultBatch.addToRows(ByteBuffer.wrap(one.toByteArray()));
}
@ -1424,11 +1426,11 @@ public class StmtExecutor {
profile.getSummaryProfile().freshFetchResultConsumeTime();
// for outfile query, there will be only one empty batch send back with eos flag
// call `copyRowBatch()` first, because batch.getBatch() may be null, it result set is empty
if (cacheAnalyzer != null && !isOutfileQuery) {
cacheAnalyzer.copyRowBatch(batch);
}
if (batch.getBatch() != null) {
if (cacheAnalyzer != null) {
cacheAnalyzer.copyRowBatch(batch);
}
// register send field result time.
profile.getSummaryProfile().setTempStartTime();
// For some language driver, getting error packet after fields packet

View File

@ -22,6 +22,7 @@ import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Type;
import org.apache.doris.proto.InternalService;
import org.apache.doris.qe.RowBatch;
import org.apache.doris.thrift.TResultBatch;
import com.google.common.collect.Lists;
import com.google.protobuf.ByteString;
@ -95,11 +96,15 @@ public class RowBatchBuilder {
public void copyRowData(RowBatch rowBatch) {
batchSize++;
rowSize += rowBatch.getBatch().getRowsSize();
for (ByteBuffer buf : rowBatch.getBatch().getRows()) {
byte[] bytes = Arrays.copyOfRange(buf.array(), buf.position(), buf.limit());
dataSize += bytes.length;
rowList.add(bytes);
TResultBatch resultBatch = rowBatch.getBatch();
// for empty result set, the resultBatch will be null
rowSize += resultBatch == null ? 0 : resultBatch.getRowsSize();
if (resultBatch != null) {
for (ByteBuffer buf : rowBatch.getBatch().getRows()) {
byte[] bytes = Arrays.copyOfRange(buf.array(), buf.position(), buf.limit());
dataSize += bytes.length;
rowList.add(bytes);
}
}
}