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

Improved the check that determines if the pattern trick should be used. #118

Merged

Conversation

floriankramer
Copy link
Member

This pr removes some bugs that occurred when triples restricted the object of a ql:has-predicate, when filters filter on any part of a ql:has-predicate triple or when optional parts of a query create results for the object of ql:has-predicate.
This also fixes a bug that caused the order by operation created when constructing the CountAvailablePredicates operation being setup wrongly, leading to a segfault. This may solve #84.

@floriankramer
Copy link
Member Author

This pr should also affect #104, leading to the filter being applied at the cost of using the more efficient CountAvailablePredicates operation.

Copy link
Member

@niklas88 niklas88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for this contribution! I still have a couple of questions and nitpicks but overall this looks good and turning the check into a method is much cleaner so that's good too.

@@ -201,4 +201,6 @@ class QueryPlanner {
SubtreePlan getTextLeafPlan(const TripleGraph::Node& node) const;

SubtreePlan optionalJoin(const SubtreePlan& a, const SubtreePlan& b) const;
bool checkUsePatternTrick(ParsedQuery& pq,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a method comment here. Also Google's C++ style guide, which we try to follow, forbids non-const reference parameters and they aren't really used in the rest of the code base. So these need to be pointers instead.

alias._function.find("DISTINCT") == std::string::npos &&
alias._function.find("distinct") == std::string::npos &&
(ad_utility::startsWith(alias._function, "COUNT") ||
ad_utility::startsWith(alias._function, "count"))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do these checks on the lowercase aliass._function so it's actually case insensitive?

// Check for triples containing the has predicates triples object.
for (size_t j = 0;
j < pq._rootGraphPattern._whereClauseTriples.size() &&
usePatternTrick;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap the two sides of the && so one immediately sees that this only applies if usePatternTrick == true

usePatternTrick = false;
}
}
// Check for filters on the has predicate triples subject or object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write "ql:has-predicate triple's" without the "-" the English sounds a bit weird

for (const SparqlFilter& filter : pq._rootGraphPattern._filters) {
if (filter._lhs == t._o || filter._lhs == t._s ||
filter._rhs == t._o || filter._rhs == t._s) {
usePatternTrick = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but in this case we still have a a ql:has-predicate in the query, am I assuming correctly that without the userPatternTrick flag bein set this will be computed in the classic SPARQL way and will still work or does the query fail?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the usePatternTrick flag is not set the query should still work the normal way.

break;
}
}
// Check for optional parts containing the has predicate triples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a "-" here too

pattern->_children.end());
for (const SparqlTriple& other : pattern->_whereClauseTriples) {
if (other._s == t._o || other._p == t._o || other._o == t._o) {
usePatternTrick = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above

@@ -408,18 +408,20 @@ QueryExecutionTree QueryPlanner::createExecutionTree(ParsedQuery& pq) const {
}

bool QueryPlanner::checkUsePatternTrick(
ParsedQuery& pq, SparqlTriple& patternTrickTriple) const {
ParsedQuery& pq, SparqlTriple* patternTrickTriple) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParsedQuery is also passed as a non-const reference

/**
* @brief Determines if the pattern trick (and in turn the
* CountAvailablePredicates operation) are applicable to the given
* parsed query. If a has predicate triple is found and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a ql:has-predicate triple"

* @brief Determines if the pattern trick (and in turn the
* CountAvailablePredicates operation) are applicable to the given
* parsed query. If a has predicate triple is found and
* CountAvailblePredicates can be used for it the triple is removed from the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for it, the"

Also can you add the information from your comment that if the check fails the ql:has-predicate part of the query will still be computed just without the pattern trick

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the comment that the query will still be computed to the function call instead, as it is not directly a part of the checkUsePatternTrick function.

@niklas88 niklas88 added this to Needs review in QLever Aug 31, 2018
@niklas88
Copy link
Member

niklas88 commented Aug 31, 2018

Ok I'm running the Clueweb+ Freebase instance with this change now and it definitely fixes the original test cases in #104 and #84. So I think after addressing the current set of comments this will be ready to merge. Well done!

@niklas88 niklas88 merged commit 23a8bad into ad-freiburg:master Sep 1, 2018
QLever automation moved this from Review to Done Sep 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
QLever
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants