Skip to content

Commit

Permalink
query result cache: add fake stringify for some nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ObiWahn committed Aug 24, 2017
1 parent 4d2ba5e commit 08b80bf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
45 changes: 35 additions & 10 deletions arangod/Aql/ExecutionNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,24 @@ std::unordered_map<int, std::string const> const ExecutionNode::TypeNames{
{static_cast<int>(SHORTEST_PATH), "ShortestPathNode"}};


std::string ExecutionNode::fakeQueryString() const {
bool ExecutionNode::fakeQueryString(std::string& outString) const {
// returns fake querystring that is used to create a hash key
// for queries on DBServers in cluster-mode
std::string rv="";
std::string thisNode = fakeQueryStringThisNode();
if (thisNode.empty()) { return thisNode; }
bool rv = fakeQueryStringThisNode(outString);
if (!rv) { return false; }

else {
for(auto* node : this->getDependencies()){
std::string childString = node->fakeQueryString();
if(childString.empty()){ return childString; }
rv += childString;
rv = node->fakeQueryString(outString);
if(!rv){ return false; }
}
rv += thisNode;
}
return rv;
}

// protected - virtual
std::string ExecutionNode::fakeQueryStringThisNode() const {
return ""; // override in cache-able Nodes
bool ExecutionNode::fakeQueryStringThisNode(std::string&) const {
return false;
}

/// @brief returns the type name of the node
Expand Down Expand Up @@ -1155,6 +1152,11 @@ double SingletonNode::estimateCost(size_t& nrItems) const {
return 1.0;
}

bool SingletonNode::fakeQueryStringThisNode(std::string& outString) const {
outString.append("S");
return true;
}

EnumerateCollectionNode::EnumerateCollectionNode(
ExecutionPlan* plan, arangodb::velocypack::Slice const& base)
: ExecutionNode(plan, base),
Expand All @@ -1167,6 +1169,15 @@ EnumerateCollectionNode::EnumerateCollectionNode(
TRI_ASSERT(_collection != nullptr);
}

bool EnumerateCollectionNode::fakeQueryStringThisNode(std::string& outString) const {
if(_random) { return false; }
outString.append("EC");
outString.append(_collection->name);
outString.append(_outVariable->name); // is this ok?
//vocbase? do we alrady have the db context outside?!
return true;
}

/// @brief toVelocyPack, for EnumerateCollectionNode
void EnumerateCollectionNode::toVelocyPackHelper(VPackBuilder& nodes,
bool verbose) const {
Expand Down Expand Up @@ -1227,6 +1238,14 @@ EnumerateListNode::EnumerateListNode(ExecutionPlan* plan,
_inVariable(Variable::varFromVPack(plan->getAst(), base, "inVariable")),
_outVariable(Variable::varFromVPack(plan->getAst(), base, "outVariable")) {}

bool EnumerateListNode::fakeQueryStringThisNode(std::string& outString) const {
outString.append("EL");
outString.append(_outVariable->name);
outString.append(_inVariable->name);
//outString.append(_inVariable->);
return true;
}

/// @brief toVelocyPack, for EnumerateListNode
void EnumerateListNode::toVelocyPackHelper(VPackBuilder& nodes,
bool verbose) const {
Expand Down Expand Up @@ -1672,6 +1691,12 @@ ReturnNode::ReturnNode(ExecutionPlan* plan, arangodb::velocypack::Slice const& b
: ExecutionNode(plan, base),
_inVariable(Variable::varFromVPack(plan->getAst(), base, "inVariable")) {}

bool ReturnNode::fakeQueryStringThisNode(std::string& outString) const {
outString.append("R");
outString.append(_inVariable->name);
return true;
}

/// @brief toVelocyPack, for ReturnNode
void ReturnNode::toVelocyPackHelper(VPackBuilder& nodes, bool verbose) const {
ExecutionNode::toVelocyPackHelperGeneric(nodes,
Expand Down
12 changes: 9 additions & 3 deletions arangod/Aql/ExecutionNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ExecutionNode {
static ExecutionNode* fromVPackFactory(ExecutionPlan* plan,
arangodb::velocypack::Slice const& slice);

std::string fakeQueryString() const;
bool fakeQueryString(std::string&) const;

/// @brief return the node's id
inline size_t id() const { return _id; }
Expand Down Expand Up @@ -580,7 +580,7 @@ class ExecutionNode {

protected:
/// create sting representation of this node and its children
virtual std::string fakeQueryStringThisNode() const;
virtual bool fakeQueryStringThisNode(std::string&) const;

/// @brief factory for sort elements
static void getSortElements(SortElementVector& elements, ExecutionPlan* plan,
Expand Down Expand Up @@ -663,6 +663,7 @@ class SingletonNode : public ExecutionNode {
SingletonNode(ExecutionPlan* plan, arangodb::velocypack::Slice const& base)
: ExecutionNode(plan, base) {}

bool fakeQueryStringThisNode(std::string& outString) const override;
/// @brief return the type of the node
NodeType getType() const override final { return SINGLETON; }

Expand Down Expand Up @@ -706,7 +707,8 @@ class EnumerateCollectionNode : public ExecutionNode, public DocumentProducingNo

EnumerateCollectionNode(ExecutionPlan* plan,
arangodb::velocypack::Slice const& base);


virtual bool fakeQueryStringThisNode(std::string&) const override;
/// @brief return the type of the node
NodeType getType() const override final { return ENUMERATE_COLLECTION; }

Expand Down Expand Up @@ -770,6 +772,8 @@ class EnumerateListNode : public ExecutionNode {

EnumerateListNode(ExecutionPlan*, arangodb::velocypack::Slice const& base);

virtual bool fakeQueryStringThisNode(std::string&) const override;

/// @brief return the type of the node
NodeType getType() const override final { return ENUMERATE_LIST; }

Expand Down Expand Up @@ -1185,6 +1189,8 @@ class ReturnNode : public ExecutionNode {

ReturnNode(ExecutionPlan*, arangodb::velocypack::Slice const& base);

bool fakeQueryStringThisNode(std::string& outString) const override;

/// @brief return the type of the node
NodeType getType() const override final { return RETURN; }

Expand Down

0 comments on commit 08b80bf

Please sign in to comment.