mirror of https://gitee.com/bigwinds/arangodb
optimize lookups by shard key for smart vertex collections (#8641)
This commit is contained in:
parent
7cd84a785a
commit
0764e045fe
|
@ -150,12 +150,25 @@ std::shared_ptr<std::vector<std::string>> Collection::shardIds(
|
|||
}
|
||||
|
||||
/// @brief returns the shard keys of a collection
|
||||
std::vector<std::string> Collection::shardKeys() const {
|
||||
std::vector<std::string> Collection::shardKeys(bool normalize) const {
|
||||
auto coll = getCollection();
|
||||
std::vector<std::string> keys;
|
||||
for (auto const& x : coll->shardKeys()) {
|
||||
keys.emplace_back(x);
|
||||
auto const& originalKeys = coll->shardKeys();
|
||||
|
||||
if (normalize &&
|
||||
coll->isSmart() && coll->type() == TRI_COL_TYPE_DOCUMENT) {
|
||||
// smart vertex collection always has ["_key:"] as shard keys
|
||||
TRI_ASSERT(originalKeys.size() == 1);
|
||||
TRI_ASSERT(originalKeys[0] == "_key:");
|
||||
// now normalize it this to _key
|
||||
return std::vector<std::string>{ StaticStrings::KeyString };
|
||||
}
|
||||
|
||||
std::vector<std::string> keys;
|
||||
keys.reserve(originalKeys.size());
|
||||
for (auto const& key : originalKeys) {
|
||||
keys.emplace_back(key);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,9 @@ struct Collection {
|
|||
std::shared_ptr<std::vector<std::string>> shardIds(std::unordered_set<std::string> const& includedShards) const;
|
||||
|
||||
/// @brief returns the shard keys of a collection
|
||||
std::vector<std::string> shardKeys() const;
|
||||
/// if "normalize" is true, then the shard keys for a smart vertex collection
|
||||
/// will be reported as "_key" instead of "_key:"
|
||||
std::vector<std::string> shardKeys(bool normalize) const;
|
||||
|
||||
size_t numberOfShards() const;
|
||||
|
||||
|
|
|
@ -599,7 +599,7 @@ std::string getSingleShardId(arangodb::aql::ExecutionPlan const* plan,
|
|||
}
|
||||
|
||||
// note for which shard keys we need to look for
|
||||
auto shardKeys = collection->shardKeys();
|
||||
auto shardKeys = collection->shardKeys(true);
|
||||
std::unordered_set<std::string> toFind;
|
||||
for (auto const& it : shardKeys) {
|
||||
if (it.find('.') != std::string::npos) {
|
||||
|
@ -1462,7 +1462,7 @@ class PropagateConstantAttributesHelper {
|
|||
// don't remove a smart join attribute access!
|
||||
return;
|
||||
} else {
|
||||
std::vector<std::string> const& shardKeys = logical->shardKeys();
|
||||
std::vector<std::string> shardKeys = collection->shardKeys(true);
|
||||
if (std::find(shardKeys.begin(), shardKeys.end(), nameAttribute->getString()) != shardKeys.end()) {
|
||||
// don't remove equality lookups on shard keys, as this may prevent
|
||||
// the restrict-to-single-shard rule from being applied later!
|
||||
|
@ -4812,7 +4812,7 @@ class RemoveToEnumCollFinder final : public WalkerWorker<ExecutionNode> {
|
|||
break; // abort . . .
|
||||
}
|
||||
// check the remove node's collection is sharded over _key
|
||||
std::vector<std::string> shardKeys = rn->collection()->shardKeys();
|
||||
std::vector<std::string> shardKeys = rn->collection()->shardKeys(false);
|
||||
if (shardKeys.size() != 1 || shardKeys[0] != StaticStrings::KeyString) {
|
||||
break; // abort . . .
|
||||
}
|
||||
|
@ -4833,7 +4833,7 @@ class RemoveToEnumCollFinder final : public WalkerWorker<ExecutionNode> {
|
|||
}
|
||||
|
||||
// note for which shard keys we need to look for
|
||||
auto shardKeys = rn->collection()->shardKeys();
|
||||
auto shardKeys = rn->collection()->shardKeys(false);
|
||||
std::unordered_set<std::string> toFind;
|
||||
for (auto const& it : shardKeys) {
|
||||
toFind.emplace(it);
|
||||
|
|
Loading…
Reference in New Issue