Skip to content

Commit

Permalink
A first round of reviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
joka921 committed Jun 13, 2024
1 parent 5c66d2e commit b740866
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/engine/IndexScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ Permutation::IdTableGenerator IndexScan::getLazyScan(
// If there is a LIMIT or OFFSET clause that constrains the scan
// (which can happen with an explicit subquery), we cannot use the prefiltered
// blocks, as we currently have no mechanism to include limits and offsets
// into the prefiltering.
// into the prefiltering (`std::nullopt` means `scan all blocks`).
auto actualBlocks = s.getLimit().isUnconstrained()
? std::optional{std::move(blocks)}
: std::nullopt;
Expand Down
18 changes: 11 additions & 7 deletions src/index/CompressedRelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ using namespace std::chrono_literals;
static auto getBeginAndEnd(auto& range) {
return std::pair{std::ranges::begin(range), std::ranges::end(range)};
}

// modify the `block` according to the `limitOffset`. Also modify the
// `limitOffset` to reflect the parts of the LIMIT and OFFSET that have been
// performed by pruning this `block`.
static void pruneBlock(auto& block, LimitOffsetClause& limitOffset) {
auto& offset = limitOffset._offset;
auto relevantOffset = std::min(static_cast<size_t>(offset), block.size());
if (relevantOffset == block.size()) {
auto offsetInBlock = std::min(static_cast<size_t>(offset), block.size());
if (offsetInBlock == block.size()) {
block.clear();
} else {
block.erase(block.begin(), block.begin() + relevantOffset);
block.erase(block.begin(), block.begin() + offsetInBlock);
}
offset -= relevantOffset;
offset -= offsetInBlock;
auto& limit = limitOffset._limit;
auto relevantLimit =
auto limitInBlock =
std::min(block.size(), static_cast<size_t>(limit.value_or(block.size())));
block.resize(relevantLimit);
block.resize(limitInBlock);
if (limit.has_value()) {
limit.value() -= relevantLimit;
limit.value() -= limitInBlock;
}
}

Expand Down
5 changes: 1 addition & 4 deletions test/CompressedRelationsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void testCompressedRelations(const auto& inputs, std::string testCaseName,
const auto& col1And2 = inputs[i].col1And2_;
checkThatTablesAreEqual(col1And2, table);
table.clear();
// Check that the scans also work with various values for LIMIT and OFFSET
// Check that the scans also work with various values for LIMIT and OFFSET.
std::vector<LimitOffsetClause> limitOffsetClauses{
{std::nullopt, 5}, {5, 0}, {std::nullopt, 12}, {12, 0}, {7, 5}};
for (const auto& limitOffset : limitOffsetClauses) {
Expand All @@ -192,9 +192,6 @@ void testCompressedRelations(const auto& inputs, std::string testCaseName,
col1And2.erase(
col1And2.begin(),
col1And2.begin() + limitOffset.actualOffset(col1And2.size()));
if (col1And2.size() != table.numRows()) {
std::cerr << "mismatch " << std::endl;
}
checkThatTablesAreEqual(col1And2, table);
}
for (const auto& block : reader.lazyScan(
Expand Down

0 comments on commit b740866

Please sign in to comment.