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

Subqueries keep their orderBy clauses and the query optimizer is .. #305

Merged
merged 2 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engine/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ void Filter::computeFilterFixedValue(
// within the range.
rhs_array[lhs] = upperBound;
const auto& upper =
std::upper_bound(lower, input.end(), rhs_row,
std::lower_bound(lower, input.end(), rhs_row,
[lhs](const auto& l, const auto& r) {
return l[lhs] < r[lhs];
});
Expand Down
10 changes: 10 additions & 0 deletions src/engine/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class Filter : public Operation {
if (_type == SparqlFilter::FilterType::REGEX) {
return std::numeric_limits<Id>::max();
}
if (isLhsSorted()) {
// we can apply the very cheap binary sort filter
return getSizeEstimate() + _subtree->getCostEstimate();
}
// we have to look at each element of the result
return getSizeEstimate() + _subtree->getSizeEstimate() +
_subtree->getCostEstimate();
}
Expand Down Expand Up @@ -96,6 +101,11 @@ class Filter : public Operation {
bool _regexIgnoreCase;
bool _lhsAsString;

[[nodiscard]] bool isLhsSorted() const {
const auto& subresSortedOn = _subtree->resultSortedOn();
size_t lhsInd = _subtree->getVariableColumn(_lhs);
return !subresSortedOn.empty() && subresSortedOn[0] == lhsInd;
}
/**
* @brief Uses the result type and the filter type (_type) to apply the filter
* to subRes and store it in res.
Expand Down
29 changes: 18 additions & 11 deletions src/parser/SparqlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "./ParseException.h"
#include "PropertyPathParser.h"

using namespace std::literals::string_literals;

SparqlParser::SparqlParser(const string& query) : _lexer(query), _query(query) {
LOG(DEBUG) << "Parsing " << query << std::endl;
}
Expand Down Expand Up @@ -287,9 +289,6 @@ void SparqlParser::parseWhere(
ParsedQuery::GraphPatternOperation::Type::SUBQUERY);
u->_subquery = std::make_shared<ParsedQuery>();
parseQuery(u->_subquery.get());
// Remove all manual ordering from the subquery as it would be changed
// by the parent query.
u->_subquery->_orderBy.clear();
currentPattern->_children.push_back(u);
// The closing bracked } is consumed by the subquery
_lexer.accept(".");
Expand Down Expand Up @@ -694,7 +693,7 @@ bool SparqlParser::parseFilter(
f._rhs = _lexer.current().raw;
} else if (_lexer.accept(SparqlToken::Type::RDFLITERAL)) {
// Resolve escaped characters
f._rhs = parseLiteral(_lexer.current().raw, true);
f._rhs = _lexer.current().raw;
} else if (_lexer.accept(SparqlToken::Type::INTEGER)) {
f._rhs = _lexer.current().raw;
} else if (_lexer.accept(SparqlToken::Type::FLOAT)) {
Expand All @@ -716,7 +715,7 @@ bool SparqlParser::parseFilter(
_lexer.expect(")");
_lexer.expect(",");
_lexer.expect(SparqlToken::Type::RDFLITERAL);
std::string rhs = parseLiteral(_lexer.current().raw, true);
std::string rhs = _lexer.current().raw;
_lexer.expect(")");
addLangFilter(lhs, rhs, pattern);
return true;
Expand All @@ -735,7 +734,7 @@ bool SparqlParser::parseFilter(
}
_lexer.expect(",");
_lexer.expect(SparqlToken::Type::RDFLITERAL);
f._rhs = parseLiteral(_lexer.current().raw, true);
f._rhs = _lexer.current().raw;
// Remove the enlcosing quotation marks
f._rhs = f._rhs.substr(1, f._rhs.size() - 2);
if (_lexer.accept(",")) {
Expand Down Expand Up @@ -764,11 +763,19 @@ bool SparqlParser::parseFilter(
escaped = !escaped; // correctly deal with consecutive backslashes
continue;
}
if (!escaped) {
char c = f._rhs[i];
if (regexControlChars.find(c) != string::npos) {
isSimple = false;
}
char c = f._rhs[i];
bool isControlChar = regexControlChars.find(c) != string::npos;
if (!escaped && isControlChar) {
isSimple = false;
} else if (escaped && !isControlChar) {
const std::string error =
"Escaping the character "s + c +
Copy link
Member

Choose a reason for hiding this comment

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

Why do you have the std::literals::string_literals::operator""s only on the first literal?

" is not allowed in QLever's regex filters. (Regex was " +
f._rhs +
") Please note that "
"there are two levels of Escaping in place here: One for Sparql "
"and one for the regex engine";
throw ParseException(error);
}
escaped = false;
}
Expand Down