Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore old size calculation behaviour #1566

Closed
wants to merge 5 commits into from
Closed
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
18 changes: 14 additions & 4 deletions src/engine/ExportQueryExecutionTrees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,16 +784,17 @@ ExportQueryExecutionTrees::computeResultAsQLeverJSON(
qet, query.constructClause().triples_, query._limitOffset,
std::move(result), std::move(cancellationHandle));

size_t resultSize = 0;
size_t numBindingsYielded = 0;
for (const std::string& b : bindings) {
if (resultSize > 0) [[likely]] {
if (numBindingsYielded > 0) [[likely]] {
co_yield ",";
}
co_yield b;
++resultSize;
++numBindingsYielded;
}

RuntimeInformation runtimeInformation = qet.getRootOperation()->runtimeInfo();
size_t resultSizeBeforeImplicitLimit = runtimeInformation.numRows_;
runtimeInformation.addLimitOffsetRow(query._limitOffset, false);

auto timeResultComputation =
Expand All @@ -805,7 +806,16 @@ ExportQueryExecutionTrees::computeResultAsQLeverJSON(
qet.getRootOperation()->getRuntimeInfoWholeQuery());
jsonSuffix["runtimeInformation"]["query_execution_tree"] =
nlohmann::ordered_json(runtimeInformation);
jsonSuffix["resultsize"] = resultSize;
// TODO: This is a simple hack to get the result size for typical SELECT
// queries. When the final operation is lazy, it will be the size of the
// blocks produced by that operation (which is a lower bound on the size of
// the full result). For CONSTRUCT queries, it will be at most the implicit
// limit. The proper solution is to reinstate the `send` parameter
// (independently from the LIMIT), and if it is set, send only that many
// results but compute the full result size.
jsonSuffix["resultsize"] = query.hasSelectClause()
? resultSizeBeforeImplicitLimit
: numBindingsYielded;
jsonSuffix["time"]["total"] =
absl::StrCat(requestTimer.msecs().count(), "ms");
jsonSuffix["time"]["computeResult"] =
Expand Down
5 changes: 3 additions & 2 deletions test/ExportQueryExecutionTreesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ TEST(ExportQueryExecutionTrees, LimitOffset) {
<binding name="s"><uri>g</uri></binding>
</result>)" + xmlTrailer;
TestCaseSelectQuery testCaseLimitOffset{
kg, objectQuery, 2,
kg, objectQuery, 4,
// TSV
"?s\n"
"<d>\n"
Expand Down Expand Up @@ -1421,7 +1421,8 @@ TEST(ExportQueryExecutionTrees, verifyQleverJsonContainsValidMetadata) {
auto& runtimeInformation = runtimeInformationWrapper["query_execution_tree"];
EXPECT_EQ(runtimeInformation["result_cols"], 3);
EXPECT_EQ(runtimeInformation["result_rows"], 4);
EXPECT_EQ(json["resultsize"], 4);
// This number is an implementation detail for lazy results and may change.
EXPECT_EQ(json["resultsize"], 6);
auto& timingInformation = json["time"];
EXPECT_GE(toChrono(timingInformation["total"].get<std::string_view>()), 1ms);
// Ensure result is not returned in microseconds and subsequently interpreted
Expand Down
Loading