-
Notifications
You must be signed in to change notification settings - Fork 857
ZKD Indexes #13650
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
Merged
Merged
ZKD Indexes #13650
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
c19d549
Bootstrap zkd indexes. Now fill in the details.
60d6ceb
Added prototype for condition finder.
63fd0b7
Added helper for Range.
a43cf14
Fixed double conversion.
9305dbc
Added wrong but working nextImpl
14ba135
Extract bounds for iterator.
3d7d5fc
Fixed extraction logic with reversed operator usage.
db52b6d
Detect equal operator correctly.
ede46db
Implemented nextImpl
goedderz 5c78b96
Removed log devel for hot path.
0b73dcf
Cleanup
goedderz 4fb378c
Added support for partially unbounded queries.
6948eb6
Do not use index for full collection scans.
34117f4
Merge branch 'feature/zkd-index' of github.com:arangodb/arangodb into…
59fd78e
Added tests for ZkdHelper.
db392e3
Added functional test suite skeleton for zkd index
goedderz 811e660
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
91f5651
Some fixes to double conversions
goedderz 5be1cd2
Fixed bug in double to byte_string conversion.
34c4324
Added support for denormalized doubles and infinity.
e2977ff
Test all interesting double values.
c9042d2
Disallow Nan.
dd3b8f2
Added more js tests.
7b879dc
Added a lot of tests.
6fcf4d1
Cleaned up test.
5697c52
[zkd] Strict comparsion (#13673)
1d3522d
[zkd] Cluster support (#13677)
94dd02e
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
3d1ce4b
Added support for nested fields - excluding expansions. (#13681)
7618470
[zkd] Unique Constraints (#13691)
1d4928b
[zkd] Forward Compat (#13694)
8cabd6f
[zkd] Column Family (#13692)
bbf25b4
Added zkd index docu block. (#13698)
caa87ae
Fixed bug in RocksDBKeyBounds and using default cost estimation
6c6a34e
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
b81f948
[zkd] testInBox speedup (#13798)
aaddb71
Feature/zkd index speedup getnextzvalue (#13799)
goedderz 10ed61a
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
5a1adc3
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
584f524
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
d650d3f
Updated CHANGELOG.
265ed5c
Merge branch 'devel' of github.com:arangodb/arangodb into feature/zkd…
goedderz 3c73e3d
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
41ea5e2
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
fa7d8b0
Fixing iterator.
5f83c9f
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
dd48bf9
Added review suggestions.
a55c4c6
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
60473c5
Applied suggestions from review.
a185712
Merge branch 'devel' into feature/zkd-index
mchacki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Feature/zkd index speedup getnextzvalue (#13799)
* Avoid interleave&transpose in getNextZValue() * Change order of actual/expected in test assertion * Minor improvements * Removed superfluous transpose calls
- Loading branch information
commit aaddb716d2c35a73da3aa6cf43ca232be01e0efd
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#include "ZkdHelper.h" | ||
|
||
#include <Basics/debugging.h> | ||
#include <Containers/SmallVector.h> | ||
#include "Basics/ScopeGuard.h" | ||
#include "Basics/debugging.h" | ||
#include "Containers/SmallVector.h" | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cmath> | ||
|
@@ -113,7 +115,7 @@ auto zkd::ByteReader::next() -> std::optional<std::byte> { | |
|
||
void zkd::BitWriter::append(Bit bit) { | ||
if (bit == Bit::ONE) { | ||
_value |= std::byte{1} << (7u - _nibble); | ||
_value |= std::byte{1} << (7U - _nibble); | ||
} | ||
_nibble += 1; | ||
if (_nibble == 8) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small performance improvement: |
||
|
@@ -143,51 +145,59 @@ void zkd::BitWriter::reserve(std::size_t amount) { | |
_buffer.reserve(amount); | ||
} | ||
|
||
zkd::RandomBitReader::RandomBitReader(byte_string_view ref) : ref(ref) {} | ||
zkd::RandomBitReader::RandomBitReader(byte_string_view ref) : _ref(ref) {} | ||
|
||
auto zkd::RandomBitReader::getBit(std::size_t index) -> Bit { | ||
auto zkd::RandomBitReader::getBit(std::size_t index) const -> Bit { | ||
auto byte = index / 8; | ||
auto nibble = index % 8; | ||
|
||
if (byte >= ref.size()) { | ||
if (byte >= _ref.size()) { | ||
return Bit::ZERO; | ||
} | ||
|
||
auto b = ref[byte] & (1_b << (7 - nibble)); | ||
auto b = _ref[byte] & (1_b << (7 - nibble)); | ||
return b != 0_b ? Bit::ONE : Bit::ZERO; | ||
} | ||
|
||
zkd::RandomBitManipulator::RandomBitManipulator(byte_string& ref) : ref(ref) {} | ||
auto zkd::RandomBitReader::bits() const -> std::size_t { | ||
return 8 * _ref.size(); | ||
} | ||
|
||
zkd::RandomBitManipulator::RandomBitManipulator(byte_string& ref) : _ref(ref) {} | ||
|
||
auto zkd::RandomBitManipulator::getBit(std::size_t index) -> Bit { | ||
auto zkd::RandomBitManipulator::getBit(std::size_t index) const -> Bit { | ||
auto byte = index / 8; | ||
auto nibble = index % 8; | ||
|
||
if (byte >= ref.size()) { | ||
if (byte >= _ref.size()) { | ||
return Bit::ZERO; | ||
} | ||
|
||
auto b = ref[byte] & (1_b << (7 - nibble)); | ||
auto b = _ref[byte] & (1_b << (7 - nibble)); | ||
return b != 0_b ? Bit::ONE : Bit::ZERO; | ||
} | ||
|
||
auto zkd::RandomBitManipulator::setBit(std::size_t index, Bit value) -> void { | ||
auto byte = index / 8; | ||
auto nibble = index % 8; | ||
|
||
if (byte >= ref.size()) { | ||
ref.resize(byte + 1); | ||
if (byte >= _ref.size()) { | ||
_ref.resize(byte + 1); | ||
} | ||
auto bit = 1_b << (7 - nibble); | ||
ref[byte] = (ref[byte] & ~bit) | (value == Bit::ONE ? bit : 0_b); | ||
_ref[byte] = (_ref[byte] & ~bit) | (value == Bit::ONE ? bit : 0_b); | ||
maierlars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
auto zkd::RandomBitManipulator::bits() const -> std::size_t { | ||
return 8 * _ref.size(); | ||
} | ||
|
||
auto zkd::interleave(std::vector<zkd::byte_string> const& vec) -> zkd::byte_string { | ||
std::size_t max_size = 0; | ||
std::vector<BitReader> reader; | ||
reader.reserve(vec.size()); | ||
|
||
for (auto& str : vec) { | ||
for (auto const& str : vec) { | ||
if (str.size() > max_size) { | ||
max_size = str.size(); | ||
} | ||
|
@@ -255,9 +265,13 @@ void zkd::compareWithBoxInto(byte_string_view cur, byte_string_view min, byte_st | |
BitReader cur_reader(cur); | ||
BitReader min_reader(min); | ||
BitReader max_reader(max); | ||
::arangodb::containers::SmallVector<std::pair<bool, bool>>::allocator_type::arena_type a; | ||
::arangodb::containers::SmallVector<std::pair<bool, bool>> isLargerLowerThanMinMax{a}; | ||
isLargerLowerThanMinMax.resize(dimensions); | ||
|
||
auto const isLargerThanMin = [&result](auto const dim) { | ||
return result[dim].saveMin != CompareResult::max; | ||
}; | ||
auto const isLowerThanMax = [&result](auto const dim) { | ||
return result[dim].saveMax != CompareResult::max; | ||
}; | ||
|
||
unsigned step = 0; | ||
unsigned dim = 0; | ||
maierlars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -271,22 +285,20 @@ void zkd::compareWithBoxInto(byte_string_view cur, byte_string_view min, byte_st | |
auto max_bit = max_reader.next().value_or(Bit::ZERO); | ||
|
||
if (result[dim].flag == 0) { | ||
if (!isLargerLowerThanMinMax[dim].first) { | ||
if (!isLargerThanMin(dim)) { | ||
if (cur_bit == Bit::ZERO && min_bit == Bit::ONE) { | ||
result[dim].outStep = step; | ||
result[dim].flag = -1; | ||
} else if (cur_bit == Bit::ONE && min_bit == Bit::ZERO) { | ||
isLargerLowerThanMinMax[dim].first = true; | ||
result[dim].saveMin = step; | ||
} | ||
} | ||
|
||
if (!isLargerLowerThanMinMax[dim].second) { | ||
if (!isLowerThanMax(dim)) { | ||
if (cur_bit == Bit::ONE && max_bit == Bit::ZERO) { | ||
result[dim].outStep = step; | ||
result[dim].flag = 1; | ||
} else if (cur_bit == Bit::ZERO && max_bit == Bit::ONE) { | ||
isLargerLowerThanMinMax[dim].second = true; | ||
result[dim].saveMax = step; | ||
} | ||
} | ||
|
@@ -374,84 +386,81 @@ auto zkd::getNextZValue(byte_string_view cur, byte_string_view min, byte_string_ | |
} | ||
return a.outStep < b.outStep; | ||
}); | ||
assert(minOutstepIter->flag != 0); | ||
TRI_ASSERT(minOutstepIter->flag != 0); | ||
auto const d = std::distance(cmpResult.begin(), minOutstepIter); | ||
|
||
RandomBitReader nisp(cur); | ||
|
||
std::size_t changeBP = dims * minOutstepIter->outStep + d; | ||
|
||
if (minOutstepIter->flag > 0) { | ||
while (changeBP != 0) { | ||
bool update_dims = false; | ||
while (changeBP != 0 && !update_dims) { | ||
--changeBP; | ||
if (nisp.getBit(changeBP) == Bit::ZERO) { | ||
auto dim = changeBP % dims; | ||
auto step = changeBP / dims; | ||
if (cmpResult[dim].saveMax <= step) { | ||
cmpResult[dim].saveMin = step; | ||
cmpResult[dim].flag = 0; | ||
goto update_dims; | ||
update_dims = true; | ||
} | ||
} | ||
} | ||
|
||
return std::nullopt; | ||
if (!update_dims) { | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
update_dims: | ||
RandomBitManipulator rbm(result); | ||
assert(rbm.getBit(changeBP) == Bit::ZERO); | ||
rbm.setBit(changeBP, Bit::ONE); | ||
assert(rbm.getBit(changeBP) == Bit::ONE); | ||
|
||
auto min_trans = transpose(min, dims); | ||
auto next_v = transpose(result, dims); | ||
{ | ||
RandomBitManipulator rbm(result); | ||
TRI_ASSERT(rbm.getBit(changeBP) == Bit::ZERO); | ||
rbm.setBit(changeBP, Bit::ONE); | ||
TRI_ASSERT(rbm.getBit(changeBP) == Bit::ONE); | ||
} | ||
auto resultManipulator = RandomBitManipulator{result}; | ||
auto minReader = RandomBitReader{min}; | ||
|
||
// Calculate the next bit position in dimension `dim` (regarding dims) | ||
// after `bitPos` | ||
auto const nextGreaterBitInDim = [dims](std::size_t const bitPos, std::size_t const dim) { | ||
auto const posRem = bitPos % dims; | ||
auto const posFloor = bitPos - posRem; | ||
auto const result = dim > posRem ? (posFloor + dim) : posFloor + dims + dim; | ||
// result must be a bit of dimension `dim` | ||
TRI_ASSERT(result % dims == dim); | ||
// result must be strictly greater than bitPos | ||
TRI_ASSERT(bitPos < result); | ||
// and the lowest bit with the above properties | ||
TRI_ASSERT(result <= bitPos + dims); | ||
return result; | ||
}; | ||
|
||
for (unsigned dim = 0; dim < dims; dim++) { | ||
maierlars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
auto& cmpRes = cmpResult[dim]; | ||
if (cmpRes.flag >= 0) { | ||
auto bp = dims * cmpRes.saveMin + dim; | ||
if (changeBP >= bp) { | ||
// “set all bits of dim with bit positions > changeBP to 0” | ||
BitReader br(next_v[dim]); | ||
BitWriter bw; | ||
size_t i = 0; | ||
while (auto bit = br.next()) { | ||
if (i * dims + dim > changeBP) { | ||
break; | ||
} | ||
bw.append(bit.value()); | ||
i++; | ||
for (std::size_t i = nextGreaterBitInDim(changeBP, dim); i < resultManipulator.bits(); i += dims) { | ||
resultManipulator.setBit(i, Bit::ZERO); | ||
} | ||
next_v[dim] = std::move(bw).str(); | ||
} else { | ||
// “set all bits of dim with bit positions > changeBP to the minimum of the query box in this dim” | ||
BitReader br(next_v[dim]); | ||
BitWriter bw; | ||
size_t i = 0; | ||
while (auto bit = br.next()) { | ||
if (i * dims + dim > changeBP) { | ||
break; | ||
} | ||
bw.append(bit.value()); | ||
i++; | ||
for (std::size_t i = nextGreaterBitInDim(changeBP, dim); i < resultManipulator.bits(); i += dims) { | ||
resultManipulator.setBit(i, minReader.getBit(i)); | ||
} | ||
BitReader br_min(min_trans[dim]); | ||
for (size_t j = 0; j < i; ++j) { | ||
br_min.next(); | ||
} | ||
for (; auto bit = br_min.next(); ++i) { | ||
bw.append(bit.value()); | ||
} | ||
next_v[dim] = std::move(bw).str(); | ||
} | ||
} else { | ||
// load the minimum for that dimension | ||
next_v[dim] = min_trans[dim]; | ||
for (std::size_t i = dim; i < resultManipulator.bits(); i += dims) { | ||
resultManipulator.setBit(i, minReader.getBit(i)); | ||
} | ||
} | ||
} | ||
|
||
return interleave(next_v); | ||
return result; | ||
} | ||
|
||
template<typename T> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.