souffle
2.0.2-371-g6315b36
|
Go to the documentation of this file.
68 return !(*
this == other);
73 for (
size_t i = 0;
i < len; ++
i) {
93 assert(
lhs.arity() ==
rhs.arity());
98 bool withinDelta =
true;
99 for (
size_t i = 0;
i <
rhs.arity(); ++
i) {
110 assert(
lhs.arity() ==
rhs.arity());
111 size_t len =
lhs.arity();
112 for (
size_t i = 0;
i < len; ++
i) {
121 assert(
lhs.arity() ==
rhs.arity());
123 for (
size_t i = 0;
i <
lhs.arity(); ++
i) {
136 for (
size_t i = 0;
i <
arity; ++
i) {
144 for (
size_t i = 0;
i < res.
arity(); ++
i) {
154 for (
size_t i = 0;
i < len; ++
i) {
165 assert(u >= 1 && v >= 1 &&
"Nodes must be greater than or equal to 1");
169 graph.insert(make_pair(u, vals));
176 auto it =
match.find(v);
177 if (it ==
match.end()) {
193 std::queue<Node> bfQueue;
195 for (
auto& it :
graph) {
198 bfQueue.push(it.first);
205 while (!bfQueue.empty()) {
210 for (
auto it : children) {
226 for (
auto v : children) {
244 std::vector<Node> keys(
graph.size());
245 for (
auto& it :
graph) {
246 keys.push_back(it.first);
248 for (
auto node : keys) {
303 assert(!chains.empty());
304 for (
const auto& chain : chains) {
305 std::vector<uint32_t> ids;
307 SearchSignature initDelta = *(chain.begin());
311 for (
auto iit = chain.begin(); next(iit) != chain.end(); ++iit) {
316 assert(!ids.empty());
321 for (
auto chain : chains) {
322 for (
auto search : chain) {
323 int idx =
map(search);
324 size_t l =
card(search);
326 SearchSignature
k(search.arity());
327 for (
size_t i = 0;
i <
l;
i++) {
330 for (
size_t i = 0;
i < search.arity(); ++
i) {
332 assert(
"incorrect lexicographical order");
335 assert(
"incorrect lexicographical order");
344 SearchSignature start = umn;
354 if (std::find(chain.begin(), chain.end(), start) == chain.end()) {
355 chain.push_back(start);
358 if (mit == match.end()) {
359 std::reverse(chain.begin(), chain.end());
364 if (std::find(chain.begin(), chain.end(), a) == chain.end()) {
373 assert(!nodes.empty());
378 if (umKeys.empty()) {
379 for (
auto node : nodes) {
387 assert(!umKeys.empty());
393 for (
auto umKey : umKeys) {
405 for (
size_t i = 0;
i < delta.arity(); ++
i) {
412 for (
auto& search : chain) {
413 if (search == oldSearch) {
422 auto newSearch = oldSearch;
423 bool seenInequality =
false;
424 for (
size_t i = 0;
i < oldSearch.arity(); ++
i) {
426 if (seenInequality) {
429 seenInequality =
true;
438 const SearchSignature& s,
const Relation&
rel) {
441 for (
size_t i = 0;
i < s.arity(); ++
i) {
443 allInequalities.insert(
i);
450 return allInequalities;
455 return allInequalities;
461 for (
size_t i = 0;
i < s.arity(); ++
i) {
463 interpreterAttributesToDischarge.insert(
i);
468 return interpreterAttributesToDischarge;
475 relAnalysis = translationUnit.getAnalysis<RelationAnalysis>();
490 if (const auto* indexSearch = dynamic_cast<const IndexOperation*>(&node)) {
491 MinIndexSelection& indexes = getIndexes(indexSearch->getRelation());
492 indexes.addSearch(getSearchSignature(indexSearch));
493 }
else if (
const auto* exists =
dynamic_cast<const ExistenceCheck*
>(&node)) {
499 }
else if (
const auto* ramRel =
dynamic_cast<const Relation*
>(&node)) {
513 const std::string& relA = swap.getFirstRelation();
514 const std::string& relB = swap.getSecondRelation();
515 MinIndexSelection& indexesA = getIndexes(relA);
516 MinIndexSelection& indexesB = getIndexes(relB);
518 for (const auto& signature : indexesA.getSearches()) {
519 indexesB.addSearch(signature);
523 for (
const auto& signature : indexesB.getSearches()) {
524 indexesA.addSearch(signature);
529 for (
auto& cur : minIndexCover) {
530 MinIndexSelection& indexes = cur.second;
535 for (
auto& cur : minIndexCover) {
536 MinIndexSelection& indexes = cur.second;
537 if (indexes.getAllOrders().empty()) {
538 indexes.insertDefaultTotalIndex(0);
548 auto ret =
minIndexCover.insert(std::make_pair(relName, MinIndexSelection()));
550 return ret.first->second;
556 const std::string& relName = cur.first;
560 os <<
"Relation " << relName <<
"\n";
561 os <<
"\tNumber of Searches: " << indexes.
getSearches().size() <<
"\n";
572 os <<
join(chain,
"-->") <<
"\n";
576 os <<
"\tNumber of Indexes: " << indexes.
getAllOrders().size() <<
"\n";
579 os <<
join(order,
"<") <<
"\n";
587 template <
typename Iter>
588 SearchSignature searchSignature(
size_t arity, Iter
const& bgn, Iter
const& end) {
589 SearchSignature keys(arity);
592 for (
auto cur = bgn; cur != end; ++cur, ++
i) {
600 template <
typename Seq>
601 SearchSignature searchSignature(
size_t arity, Seq
const& xs) {
602 return searchSignature(arity, xs.begin(), xs.end());
608 size_t arity =
rel->getArity();
610 auto lower = search->getRangePattern().first;
611 auto upper = search->getRangePattern().second;
613 for (
size_t i = 0;
i < arity; ++
i) {
618 }
else if (*lower[
i] == *upper[
i]) {
628 const auto values = provExistCheck->getValues();
630 auto auxiliaryArity =
rel->getAuxiliaryArity();
632 SearchSignature keys(values.size());
635 for (
size_t i = 0;
i < values.size() - auxiliaryArity;
i++) {
642 for (
size_t i = values.size() - auxiliaryArity;
i < values.size();
i++) {
651 return searchSignature(
rel->getArity(), existCheck->getValues());
659 for (
const auto& cur : existCheck->
getValues()) {
const Matchings & solve()
@Brief solve the maximum matching problem
search signature of a RAM operation; each bit represents an attribute of a relation.
Distance getDistance(Node v)
@Brief get distance of a node
SearchSignature(size_t arity)
const std::vector< Expression * > getValues() const
Get arguments of the tuple/pattern A null pointer element in the vector denotes an unspecified patter...
std::vector< SearchSignature > Chain
bool isUndefValue(const Expression *expr)
Determines if an expression represents an undefined value.
std::ostream & operator<<(std::ostream &out, const SearchSignature &signature)
Node getMatch(Node v)
@Brief get match for a search signature
const SearchSet getUnmatchedKeys(const MaxMatching::Matchings &match, const SearchSet &nodes)
@Brief get all nodes which are unmatched from A-> B
void insertIndex(LexOrder &ids, SearchSignature delta)
@Brief insert an index based on the delta
void updateSearch(SearchSignature oldSearch, SearchSignature newSearch)
void print(std::ostream &os) const override
Print the analysis result in HTML format.
const Distance InfiniteDistance
Existence check for a tuple(-pattern) in a relation.
int map(SearchSignature cols) const
@Brief maps search columns to an lexicographical order (labeled by a number)
std::map< std::string, MinIndexSelection > minIndexCover
minimal index cover for relations, i.e., maps a relation to a set of indexes
std::set< SearchSignature, SearchComparator > SearchSet
std::unordered_map< Node, Node > Matchings
Matching represent a solution of the matching, i.e., which node in the bi-partite graph maps to anoth...
static SearchSignature getDischarged(const SearchSignature &signature)
std::unordered_set< AttributeIndex > AttributeSet
bool bfSearch()
@Brief perform a breadth first search in the graph
void run(const TranslationUnit &translationUnit) override
Run analysis for a RAM translation unit.
Provenance Existence check for a relation.
Object-oriented wrapper class for Souffle's templatized relations.
Node is a superclass for all RAM IR classes.
std::vector< AttributeConstraint > constraints
bool operator!=(const SearchSignature &other) const
void removeExtraInequalities()
@Brief remove arbitrary extra inequalities
AttributeConstraint & operator[](std::size_t pos)
std::list< Chain > ChainOrderMap
An abstract class for performing indexed operations.
const ChainOrderMap getAllChains() const
@Brief Get all chains
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
static bool isSubset(const SearchSignature &lhs, const SearchSignature &rhs)
Abstract existence check for a tuple in a relation.
static bool isComparable(const SearchSignature &lhs, const SearchSignature &rhs)
const ChainOrderMap getChainsFromMatching(const MaxMatching::Matchings &match, const SearchSet &nodes)
@Brief get all chains from the matching
IndexSignatureMap indexToSignature
static size_t card(SearchSignature cols)
@Brief count the number of constraints in key
DischargeMap dischargedMap
ChainOrderMap chainToOrder
bool isTotalSignature(const AbstractExistenceCheck *existCheck) const
@Brief index signature of existence check resembles a total index
SignatureIndexMap signatureToIndexB
SignatureIndexMap signatureToIndexA
static SearchSignature getFullSearchSignature(size_t arity)
void solve()
@Brief map the keys in the key set to lexicographical order
static MainConfig & config()
bool operator==(const SearchSignature &other) const
AttributeSet getAttributesToDischarge(const SearchSignature &s, const Relation &rel)
Return the attribute position for each indexed operation that should be discharged.
RelationAnalysis * relAnalysis
relation analysis for looking up relations by name
bool operator<(const SearchSignature &other) const
void addSearch(SearchSignature cols)
@Brief Add new key to an Index Set
bool containsEquality() const
static SearchSignature getDelta(const SearchSignature &lhs, const SearchSignature &rhs)
const OrderCollection getAllOrders() const
@Brief Get all indexes
void addEdge(Node u, Node v)
@Brief add an edge to the bi-partite graph
const SearchSet & getSearches() const
@Brief Get searches
const ram::Relation & lookup(const std::string &name) const
MinIndexSelection & getIndexes(const std::string &relName)
@Brief get the minimal index cover for a relation
SearchSignature getSearchSignature(const IndexOperation *search) const
@Brief Get index signature for an Ram IndexOperation operation
void visitDepthFirst(const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
A utility function visiting all nodes within the RAM fragments rooted by the given node recursively i...
Chain getChain(const SearchSignature umn, const MaxMatching::Matchings &match)
@Brief get a chain from a matching
void rel(size_t limit, bool showLimit=true)
bool dfSearch(Node u)
@Brief perform a depth first search in the graph
std::unordered_set< Node > Edges
Edges in the bi-partite graph.