souffle  2.0.2-371-g6315b36
Index.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018, The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /***************************************************************************
10  *
11  * @file Index.h
12  *
13  * Computes indexes for relations in a translation unit
14  *
15  ***************************************************************************/
16 
17 #pragma once
18 
20 #include "ram/ExistenceCheck.h"
21 #include "ram/IndexOperation.h"
23 #include "ram/Relation.h"
24 #include "ram/TranslationUnit.h"
25 #include "ram/analysis/Analysis.h"
26 #include "ram/analysis/Relation.h"
28 #include <algorithm>
29 #include <cassert>
30 #include <cstdint>
31 #include <iostream>
32 #include <list>
33 #include <map>
34 #include <memory>
35 #include <set>
36 #include <string>
37 #include <unordered_map>
38 #include <unordered_set>
39 #include <utility>
40 #include <vector>
41 
42 // define if enable unit tests
43 #define M_UNIT_TEST
44 
45 namespace souffle::ram::analysis {
46 
48 
49 /** search signature of a RAM operation; each bit represents an attribute of a relation.
50  * A one represents that the attribute has an assigned value; a zero represents that
51  * no value exists (i.e. attribute is unbounded) in the search. */
53 public:
54  explicit SearchSignature(size_t arity);
55  size_t arity() const;
56 
57  // array subscript operator
58  AttributeConstraint& operator[](std::size_t pos);
59  const AttributeConstraint& operator[](std::size_t pos) const;
60 
61  // comparison operators
62  bool operator<(const SearchSignature& other) const;
63  bool operator==(const SearchSignature& other) const;
64  bool operator!=(const SearchSignature& other) const;
65 
66  bool empty() const;
67  bool containsEquality() const;
68 
69  static bool isComparable(const SearchSignature& lhs, const SearchSignature& rhs);
70  static bool isSubset(const SearchSignature& lhs, const SearchSignature& rhs);
73  static SearchSignature getDischarged(const SearchSignature& signature);
74 
75  friend std::ostream& operator<<(std::ostream& out, const SearchSignature& signature);
76 
77  // hashing class
78  class Hasher {
79  public:
80  size_t operator()(const SearchSignature& searchSignature) const {
81  std::size_t seed = searchSignature.arity();
82  for (auto& constraint : searchSignature.constraints) {
83  seed ^= static_cast<size_t>(constraint) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
84  }
85  return seed;
86  }
87  };
88 
89 private:
90  std::vector<AttributeConstraint> constraints;
91 };
92 
93 std::ostream& operator<<(std::ostream& out, const SearchSignature& signature);
94 
95 /**
96  * @class MaxMatching
97  * @Brief Computes a maximum matching with Hopcroft-Karp algorithm
98  *
99  * This class is a helper class for RamIndex.
100  *
101  * This implements a standard maximum matching algorithm for a bi-partite graph
102  * also known as a marriage problem. Given a set of edges in a bi-partite graph
103  * select a subset of edges that each node in the bi-partite graph has at most
104  * one adjacent edge associated with.
105  *
106  * The nodes of the bi-partite graph represent index-signatures stemming from
107  * RAM operations and RAM existence checks for a relation. A relation between
108  * two nodes represent whether an index operation subsumes another operation.
109  *
110  * Source: http://en.wikipedia.org/wiki/Hopcroft%E2%80%93Karp_algorithm#Pseudocode
111  */
112 class MaxMatching {
113 public:
114  using Node = uint32_t;
115  /* The nodes of the bi-partite graph are index signatures of RAM operation */
116  using Nodes = std::unordered_set<Node>;
117  /* Distance between nodes */
118  using Distance = int;
119  /**
120  * Matching represent a solution of the matching, i.e., which node in the bi-partite
121  * graph maps to another node. If no map exist for a node, there is no adjacent edge
122  * exists for that node.
123  */
124  using Matchings = std::unordered_map<Node, Node>;
125 
126  /* Node constant representing no match */
127  const Node NullVertex = 0;
128 
129  /* Infinite distance */
131 
132  /**
133  * @Brief solve the maximum matching problem
134  * @result returns the matching
135  */
136  const Matchings& solve();
137 
138  /**
139  * @Brief get number of matches in the solution
140  * @return number of matches
141  */
142  int getNumMatchings() const {
143  return match.size() / 2;
144  }
145 
146  /**
147  * @Brief add an edge to the bi-partite graph
148  * @param u search signature
149  * @param v subsuming search signature
150  */
151  void addEdge(Node u, Node v);
152 
153 protected:
154  /**
155  * @Brief get match for a search signature
156  * @param v search signature
157  */
158  Node getMatch(Node v);
159 
160  /**
161  * @Brief get distance of a node
162  */
164 
165  /**
166  * @Brief perform a breadth first search in the graph
167  */
168  bool bfSearch();
169 
170  /**
171  * @Brief perform a depth first search in the graph
172  * @param u search signature
173  */
174  bool dfSearch(Node u);
175 
176 private:
177  /**
178  * Edges in the bi-partite graph
179  */
180  using Edges = std::unordered_set<Node>;
181  /**
182  * Bi-partite graph of instance
183  */
184  using Graph = std::unordered_map<Node, Edges>;
185  /**
186  * distance function of nodes
187  */
188  using DistanceMap = std::map<Node, Distance>;
189 
193 };
194 
195 /**
196  * @class MinIndexSelection
197  * @Brief computes the minimal index cover for a relation
198  * in a RAM Program.
199  *
200  * If the indexes of a relation can cover several searches, the minimal
201  * set of indexes is computed by Dilworth's problem. See
202  *
203  * "Automatic Index Selection for Large-Scale Datalog Computation"
204  * http://www.vldb.org/pvldb/vol12/p141-subotic.pdf
205  *
206  */
207 
209 public:
210  using AttributeIndex = uint32_t;
211  using AttributeSet = std::unordered_set<AttributeIndex>;
212  using SignatureMap = std::unordered_map<SearchSignature, SearchSignature, SearchSignature::Hasher>;
213  using SignatureIndexMap = std::unordered_map<SearchSignature, AttributeIndex, SearchSignature::Hasher>;
214  using IndexSignatureMap = std::unordered_map<AttributeIndex, SearchSignature>;
215  using DischargeMap = std::unordered_map<SearchSignature, AttributeSet, SearchSignature::Hasher>;
216  using LexOrder = std::vector<AttributeIndex>;
217  using OrderCollection = std::vector<LexOrder>;
218  using Chain = std::vector<SearchSignature>;
219  // A chain is a vector of SearchSignature to support inserting incomparable elements later
220  // E.g. 1 --> 2 we don't have 1 and 2 as comparable but they form a valid lex-order
221  using ChainOrderMap = std::list<Chain>;
222 
224  public:
225  bool operator()(const SearchSignature& s1, const SearchSignature& s2) const {
226  auto hasher = SearchSignature::Hasher();
227  return hasher(s1) < hasher(s2);
228  }
229  };
230 
231  using SearchSet = std::set<SearchSignature, SearchComparator>;
232  // SearchSignatures only have a partial order, however we need to produce a unique ordering of searches
233  // when we output the name of the index and therefore we order the SearchSignatures arbitrarily by their
234  // hashes
235 
236  /** @Brief Add new key to an Index Set */
237  inline void addSearch(SearchSignature cols) {
238  if (!cols.empty()) {
239  searches.insert(cols);
240  }
241  }
242 
243  MinIndexSelection() = default;
244  ~MinIndexSelection() = default;
245 
246  /** @Brief Get searches **/
247  const SearchSet& getSearches() const {
248  return searches;
249  }
250 
251  /** @Brief Get index for a search */
252  const LexOrder& getLexOrder(SearchSignature cols) const {
253  int idx = map(cols);
254  return orders[idx];
255  }
256 
257  /** @Brief Get index for a search */
258  int getLexOrderNum(SearchSignature cols) const {
259  return map(cols);
260  }
261 
262  /** @Brief Get all indexes */
264  return orders;
265  }
266 
267  /** @Brief Get all chains */
268  const ChainOrderMap getAllChains() const {
269  return chainToOrder;
270  }
271 
272  /**
273  * Check whether number of constraints in k is not equal to number of columns in lexicographical
274  * order
275  * */
276  bool isSubset(SearchSignature cols) const {
277  int idx = map(cols);
278  return card(cols) < orders[idx].size();
279  }
280 
281  /** @Brief map the keys in the key set to lexicographical order */
282  void solve();
283 
284  /** @Brief insert a total order index
285  * @param size of the index
286  */
287  void insertDefaultTotalIndex(size_t arity) {
288  Chain chain = std::vector<SearchSignature>();
290  chain.push_back(fullIndexKey);
291  chainToOrder.push_back(std::move(chain));
292  LexOrder totalOrder;
293  for (size_t i = 0; i < arity; ++i) {
294  totalOrder.push_back(i);
295  }
296  orders.push_back(std::move(totalOrder));
297  }
298  /** Return the attribute position for each indexed operation that should be discharged.
299  */
301 
302  void print(std::ostream& os) {
303  /* Print searches */
304  os << "\tNumber of Searches: " << getSearches().size() << "\n";
305 
306  /* print searches */
307  for (auto& search : getSearches()) {
308  os << "\t\t";
309  os << search;
310  os << "\n";
311  }
312 
313  /* print chains */
314  for (auto& chain : getAllChains()) {
315  os << join(chain, "-->") << "\n";
316  }
317  os << "\n";
318 
319  os << "\tNumber of Indexes: " << getAllOrders().size() << "\n";
320  for (auto& order : getAllOrders()) {
321  os << "\t\t";
322  os << join(order, "<") << "\n";
323  os << "\n";
324  }
325  }
326 
327 protected:
328  SignatureIndexMap signatureToIndexA; // mapping of a SearchSignature on A to its unique index
329  SignatureIndexMap signatureToIndexB; // mapping of a SearchSignature on B to its unique index
330  DischargeMap dischargedMap; // mapping of a SearchSignature to the attributes to discharge
331  IndexSignatureMap indexToSignature; // mapping of a unique index to its SearchSignature
332  SearchSet searches; // set of search patterns on table
333  OrderCollection orders; // collection of lexicographical orders
334  ChainOrderMap chainToOrder; // maps order index to set of searches covered by chain
335  MaxMatching matching; // matching problem for finding minimal number of orders
336 
337  /** @Brief count the number of constraints in key */
338  static size_t card(SearchSignature cols) {
339  size_t sz = 0;
340  for (size_t i = 0; i < cols.arity(); i++) {
341  if (cols[i] != AttributeConstraint::None) {
342  sz++;
343  }
344  }
345  return sz;
346  }
347 
348  /** @Brief maps search columns to an lexicographical order (labeled by a number) */
349  int map(SearchSignature cols) const {
350  assert(orders.size() == chainToOrder.size() && "Order and Chain Sizes do not match!!");
351  int i = 0;
352  for (auto it = chainToOrder.begin(); it != chainToOrder.end(); ++it, ++i) {
353  if (std::find(it->begin(), it->end(), cols) != it->end()) {
354  assert((size_t)i < orders.size());
355  return i;
356  }
357  }
358  fatal("cannot find matching lexicographical order");
359  }
360 
361  /** @Brief insert an index based on the delta */
363  LexOrder backlog; // add inequalities at the end
364  for (size_t pos = 0; pos < delta.arity(); pos++) {
365  if (delta[pos] == AttributeConstraint::Equal) {
366  ids.push_back(pos);
367  } else if (delta[pos] == AttributeConstraint::Inequal) {
368  backlog.push_back(pos);
369  }
370  }
371  ids.insert(ids.end(), backlog.begin(), backlog.end());
372  }
373 
374  /** @Brief get a chain from a matching
375  * @param Starting node of a chain
376  * @param Matching
377  * @result A minimal chain
378  * given an unmapped node from set A
379  * we follow it from set B until it cannot be matched from B
380  * if not matched from B then umn is a chain.
381  */
382  Chain getChain(const SearchSignature umn, const MaxMatching::Matchings& match);
383 
384  /** @Brief get all chains from the matching */
385  const ChainOrderMap getChainsFromMatching(const MaxMatching::Matchings& match, const SearchSet& nodes);
386 
387  /** @param OldSearch to be updated
388  * @param NewSearch to replace the OldSearch
389  */
390  void updateSearch(SearchSignature oldSearch, SearchSignature newSearch);
391 
392  /** @Brief remove arbitrary extra inequalities */
394 
395  /** @Brief get all nodes which are unmatched from A-> B */
396  const SearchSet getUnmatchedKeys(const MaxMatching::Matchings& match, const SearchSet& nodes) {
397  SearchSet unmatched;
398 
399  // For all nodes n such that n is not in match
400  for (auto node : nodes) {
401  if (match.find(signatureToIndexA[node]) == match.end()) {
402  unmatched.insert(node);
403  }
404  }
405  return unmatched;
406  }
407 };
408 
409 /**
410  * @class RamIndexAnalyis
411  * @Brief Analysis pass computing the index sets of RAM relations
412  */
413 class IndexAnalysis : public Analysis {
414 public:
415  IndexAnalysis(const char* id) : Analysis(id), relAnalysis(nullptr) {}
416 
417  static constexpr const char* name = "index-analysis";
418 
419  void run(const TranslationUnit& translationUnit) override;
420 
421  void print(std::ostream& os) const override;
422 
423  /**
424  * @Brief get the minimal index cover for a relation
425  * @param relation name
426  * @result set of indexes of the minimal index cover
427  */
428  MinIndexSelection& getIndexes(const std::string& relName);
429 
430  /**
431  * @Brief Get index signature for an Ram IndexOperation operation
432  * @param Index-relation-search operation
433  * @result Index signature of operation
434  */
436 
437  /**
438  * @Brief Get the index signature for an existence check
439  * @param Existence check
440  * @result index signature of existence check
441  */
442  SearchSignature getSearchSignature(const ExistenceCheck* existCheck) const;
443 
444  /**
445  * @Brief Get the index signature for a provenance existence check
446  * @param Provenance-existence check
447  * @result index signature of provenance-existence check
448  */
450 
451  /**
452  * @Brief Get the default index signature for a relation (the total-order index)
453  * @param ramRel RAM-relation
454  * @result total full-signature of the relation
455  */
456  SearchSignature getSearchSignature(const Relation* ramRel) const;
457 
458  /**
459  * @Brief index signature of existence check resembles a total index
460  * @param (provenance) existence check
461  *
462  * isTotalSignature returns true if all elements of a tuple are used for the
463  * the existence check.
464  */
465  bool isTotalSignature(const AbstractExistenceCheck* existCheck) const;
466 
467 private:
468  /** relation analysis for looking up relations by name */
470 
471  /**
472  * minimal index cover for relations, i.e., maps a relation to a set of indexes
473  */
474  std::map<std::string, MinIndexSelection> minIndexCover;
475 };
476 
477 } // namespace souffle::ram::analysis
souffle::ram::IndexOperation
Definition: IndexOperation.h:48
souffle::ram::analysis::MaxMatching::solve
const Matchings & solve()
@Brief solve the maximum matching problem
Definition: Index.cpp:248
souffle::ram::analysis::SearchSignature
search signature of a RAM operation; each bit represents an attribute of a relation.
Definition: Index.h:52
souffle::ram::analysis::MaxMatching::getDistance
Distance getDistance(Node v)
@Brief get distance of a node
Definition: Index.cpp:189
souffle::ram::analysis::SearchSignature::SearchSignature
SearchSignature(size_t arity)
Definition: Index.cpp:45
AbstractExistenceCheck.h
souffle::ram::analysis::MaxMatching::NullVertex
const Node NullVertex
Definition: Index.h:127
souffle::ram::analysis::AttributeConstraint
AttributeConstraint
Definition: Index.h:47
souffle::ram::analysis::MinIndexSelection::orders
OrderCollection orders
Definition: Index.h:333
souffle::ram::analysis::MaxMatching::Nodes
std::unordered_set< Node > Nodes
Definition: Index.h:116
souffle::ram::analysis::MinIndexSelection::matching
MaxMatching matching
Definition: Index.h:335
souffle::ram::analysis::MinIndexSelection::Chain
std::vector< SearchSignature > Chain
Definition: Index.h:218
souffle::ram::analysis::operator<<
std::ostream & operator<<(std::ostream &out, const SearchSignature &signature)
Definition: Index.cpp:158
souffle::id
A functor representing the identity function for a generic type T.
Definition: StreamUtil.h:136
souffle::ram::analysis::MinIndexSelection::searches
SearchSet searches
Definition: Index.h:332
souffle::ram::analysis::MinIndexSelection::SignatureIndexMap
std::unordered_map< SearchSignature, AttributeIndex, SearchSignature::Hasher > SignatureIndexMap
Definition: Index.h:213
souffle::ram::analysis::MaxMatching::getMatch
Node getMatch(Node v)
@Brief get match for a search signature
Definition: Index.cpp:181
souffle::ram::analysis::MinIndexSelection::isSubset
bool isSubset(SearchSignature cols) const
Check whether number of constraints in k is not equal to number of columns in lexicographical order.
Definition: Index.h:276
souffle::ram::analysis::MinIndexSelection::getUnmatchedKeys
const SearchSet getUnmatchedKeys(const MaxMatching::Matchings &match, const SearchSet &nodes)
@Brief get all nodes which are unmatched from A-> B
Definition: Index.h:396
souffle::ram::analysis::MinIndexSelection::SearchComparator
Definition: Index.h:223
souffle::ram::analysis::MinIndexSelection::insertIndex
void insertIndex(LexOrder &ids, SearchSignature delta)
@Brief insert an index based on the delta
Definition: Index.h:362
souffle::ram::analysis
Definition: Analysis.h:32
souffle::ram::analysis::AttributeConstraint::Inequal
@ Inequal
MiscUtil.h
souffle::ram::analysis::MinIndexSelection::updateSearch
void updateSearch(SearchSignature oldSearch, SearchSignature newSearch)
Definition: Index.cpp:409
souffle::ram::analysis::IndexAnalysis::print
void print(std::ostream &os) const override
Print the analysis result in HTML format.
Definition: Index.cpp:560
souffle::ram::analysis::MaxMatching::InfiniteDistance
const Distance InfiniteDistance
Definition: Index.h:130
souffle::ram::analysis::MinIndexSelection::DischargeMap
std::unordered_map< SearchSignature, AttributeSet, SearchSignature::Hasher > DischargeMap
Definition: Index.h:215
souffle::ram::ExistenceCheck
Existence check for a tuple(-pattern) in a relation.
Definition: ExistenceCheck.h:49
souffle::ram::analysis::MinIndexSelection::map
int map(SearchSignature cols) const
@Brief maps search columns to an lexicographical order (labeled by a number)
Definition: Index.h:349
souffle::ram::analysis::MinIndexSelection::~MinIndexSelection
~MinIndexSelection()=default
rhs
Own< Argument > rhs
Definition: ResolveAliases.cpp:185
souffle::ram::analysis::MinIndexSelection::IndexSignatureMap
std::unordered_map< AttributeIndex, SearchSignature > IndexSignatureMap
Definition: Index.h:214
souffle::ram::analysis::IndexAnalysis::minIndexCover
std::map< std::string, MinIndexSelection > minIndexCover
minimal index cover for relations, i.e., maps a relation to a set of indexes
Definition: Index.h:474
souffle::ram::analysis::MinIndexSelection::SearchSet
std::set< SearchSignature, SearchComparator > SearchSet
Definition: Index.h:231
souffle::ram::analysis::SearchSignature::arity
size_t arity() const
Definition: Index.cpp:47
souffle::ram::analysis::MaxMatching::Matchings
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...
Definition: Index.h:124
souffle::ram::analysis::SearchSignature::getDischarged
static SearchSignature getDischarged(const SearchSignature &signature)
Definition: Index.cpp:148
souffle::ram::analysis::MinIndexSelection::AttributeSet
std::unordered_set< AttributeIndex > AttributeSet
Definition: Index.h:211
souffle::ram::analysis::MaxMatching
Definition: Index.h:112
souffle::ram::analysis::MaxMatching::bfSearch
bool bfSearch()
@Brief perform a breadth first search in the graph
Definition: Index.cpp:197
souffle::ram::analysis::AttributeConstraint::None
@ None
souffle::ram::analysis::MinIndexSelection::LexOrder
std::vector< AttributeIndex > LexOrder
Definition: Index.h:216
souffle::ram::analysis::IndexAnalysis::run
void run(const TranslationUnit &translationUnit) override
Run analysis for a RAM translation unit.
Definition: Index.cpp:480
souffle::ram::analysis::MinIndexSelection::getLexOrder
const LexOrder & getLexOrder(SearchSignature cols) const
@Brief Get index for a search
Definition: Index.h:252
lhs
Own< Argument > lhs
Definition: ResolveAliases.cpp:184
souffle::ram::TranslationUnit
Translating a RAM program.
Definition: TranslationUnit.h:55
souffle::ram::ProvenanceExistenceCheck
Provenance Existence check for a relation.
Definition: ProvenanceExistenceCheck.h:42
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
ProvenanceExistenceCheck.h
Relation.h
souffle::ram::analysis::SearchSignature::constraints
std::vector< AttributeConstraint > constraints
Definition: Index.h:90
souffle::ram::analysis::MaxMatching::graph
Graph graph
Definition: Index.h:191
souffle::ram::analysis::SearchSignature::operator!=
bool operator!=(const SearchSignature &other) const
Definition: Index.cpp:73
i
size_t i
Definition: json11.h:663
souffle::ram::analysis::MinIndexSelection::removeExtraInequalities
void removeExtraInequalities()
@Brief remove arbitrary extra inequalities
Definition: Index.cpp:426
souffle::ram::analysis::IndexAnalysis
Definition: Index.h:413
souffle::ram::analysis::MaxMatching::Distance
int Distance
Definition: Index.h:118
souffle::ram::analysis::SearchSignature::operator[]
AttributeConstraint & operator[](std::size_t pos)
Definition: Index.cpp:52
souffle::ram::analysis::MinIndexSelection::ChainOrderMap
std::list< Chain > ChainOrderMap
Definition: Index.h:221
souffle::ram::analysis::IndexAnalysis::IndexAnalysis
IndexAnalysis(const char *id)
Definition: Index.h:415
souffle::ram::analysis::SearchSignature::Hasher::operator()
size_t operator()(const SearchSignature &searchSignature) const
Definition: Index.h:80
souffle::ram::Relation
An abstract class for performing indexed operations.
Definition: Relation.h:40
Relation.h
souffle::ram::analysis::MinIndexSelection::getAllChains
const ChainOrderMap getAllChains() const
@Brief Get all chains
Definition: Index.h:268
souffle::join
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...
Definition: StreamUtil.h:175
souffle::ram::analysis::SearchSignature::isSubset
static bool isSubset(const SearchSignature &lhs, const SearchSignature &rhs)
Definition: Index.cpp:115
souffle::ram::AbstractExistenceCheck
Abstract existence check for a tuple in a relation.
Definition: AbstractExistenceCheck.h:47
souffle::ram::analysis::MinIndexSelection::getLexOrderNum
int getLexOrderNum(SearchSignature cols) const
@Brief Get index for a search
Definition: Index.h:258
souffle::ram::analysis::MinIndexSelection
Definition: Index.h:208
souffle::ram::analysis::SearchSignature::isComparable
static bool isComparable(const SearchSignature &lhs, const SearchSignature &rhs)
Definition: Index.cpp:98
souffle::ram::analysis::MinIndexSelection::getChainsFromMatching
const ChainOrderMap getChainsFromMatching(const MaxMatching::Matchings &match, const SearchSet &nodes)
@Brief get all chains from the matching
Definition: Index.cpp:377
ExistenceCheck.h
souffle::ram::analysis::MinIndexSelection::indexToSignature
IndexSignatureMap indexToSignature
Definition: Index.h:331
souffle::ram::analysis::MinIndexSelection::card
static size_t card(SearchSignature cols)
@Brief count the number of constraints in key
Definition: Index.h:338
souffle::ram::analysis::MinIndexSelection::dischargedMap
DischargeMap dischargedMap
Definition: Index.h:330
souffle::ram::analysis::MinIndexSelection::chainToOrder
ChainOrderMap chainToOrder
Definition: Index.h:334
souffle::ram::analysis::MinIndexSelection::AttributeIndex
uint32_t AttributeIndex
Definition: Index.h:210
Analysis.h
souffle::ram::analysis::MaxMatching::DistanceMap
std::map< Node, Distance > DistanceMap
distance function of nodes
Definition: Index.h:188
souffle::ram::analysis::IndexAnalysis::isTotalSignature
bool isTotalSignature(const AbstractExistenceCheck *existCheck) const
@Brief index signature of existence check resembles a total index
Definition: Index.cpp:664
TranslationUnit.h
souffle::ram::analysis::MinIndexSelection::signatureToIndexB
SignatureIndexMap signatureToIndexB
Definition: Index.h:329
souffle::ram::analysis::MinIndexSelection::signatureToIndexA
SignatureIndexMap signatureToIndexA
Definition: Index.h:328
souffle::ram::analysis::SearchSignature::getFullSearchSignature
static SearchSignature getFullSearchSignature(size_t arity)
Definition: Index.cpp:140
souffle::ram::analysis::MinIndexSelection::solve
void solve()
@Brief map the keys in the key set to lexicographical order
Definition: Index.cpp:263
IndexOperation.h
souffle::ram::analysis::SearchSignature::operator==
bool operator==(const SearchSignature &other) const
Definition: Index.cpp:68
souffle::ram::analysis::MinIndexSelection::SearchComparator::operator()
bool operator()(const SearchSignature &s1, const SearchSignature &s2) const
Definition: Index.h:225
souffle::ram::analysis::AttributeConstraint::Equal
@ Equal
souffle::ram::analysis::MinIndexSelection::getAttributesToDischarge
AttributeSet getAttributesToDischarge(const SearchSignature &s, const Relation &rel)
Return the attribute position for each indexed operation that should be discharged.
Definition: Index.cpp:443
souffle::ram::analysis::IndexAnalysis::relAnalysis
RelationAnalysis * relAnalysis
relation analysis for looking up relations by name
Definition: Index.h:469
souffle::ram::analysis::SearchSignature::operator<
bool operator<(const SearchSignature &other) const
Definition: Index.cpp:63
souffle::ram::analysis::MinIndexSelection::addSearch
void addSearch(SearchSignature cols)
@Brief Add new key to an Index Set
Definition: Index.h:237
souffle::ram::analysis::SearchSignature::containsEquality
bool containsEquality() const
Definition: Index.cpp:87
souffle::ram::analysis::SearchSignature::getDelta
static SearchSignature getDelta(const SearchSignature &lhs, const SearchSignature &rhs)
Definition: Index.cpp:126
souffle::ram::analysis::Analysis
Abstract class for a RAM Analysis.
Definition: Analysis.h:38
souffle::ram::analysis::MinIndexSelection::insertDefaultTotalIndex
void insertDefaultTotalIndex(size_t arity)
@Brief insert a total order index
Definition: Index.h:287
souffle::ram::analysis::MaxMatching::distance
DistanceMap distance
Definition: Index.h:192
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
souffle::ram::analysis::SearchSignature::operator<<
friend std::ostream & operator<<(std::ostream &out, const SearchSignature &signature)
Definition: Index.cpp:158
souffle::ram::analysis::SearchSignature::Hasher
Definition: Index.h:78
souffle::ram::analysis::MaxMatching::Node
uint32_t Node
Definition: Index.h:114
souffle::ram::analysis::MinIndexSelection::getAllOrders
const OrderCollection getAllOrders() const
@Brief Get all indexes
Definition: Index.h:263
souffle::ram::analysis::MaxMatching::addEdge
void addEdge(Node u, Node v)
@Brief add an edge to the bi-partite graph
Definition: Index.cpp:170
souffle::ram::analysis::RelationAnalysis
A RAM Analysis for finding relations by name.
Definition: Relation.h:36
souffle::ram::analysis::MinIndexSelection::SignatureMap
std::unordered_map< SearchSignature, SearchSignature, SearchSignature::Hasher > SignatureMap
Definition: Index.h:212
souffle::ram::analysis::IndexAnalysis::name
static constexpr const char * name
Definition: Index.h:417
souffle::ram::analysis::MinIndexSelection::getSearches
const SearchSet & getSearches() const
@Brief Get searches
Definition: Index.h:247
souffle::ram::analysis::IndexAnalysis::getIndexes
MinIndexSelection & getIndexes(const std::string &relName)
@Brief get the minimal index cover for a relation
Definition: Index.cpp:549
souffle::ram::analysis::IndexAnalysis::getSearchSignature
SearchSignature getSearchSignature(const IndexOperation *search) const
@Brief Get index signature for an Ram IndexOperation operation
Definition: Index.cpp:612
souffle::ram::analysis::MaxMatching::Graph
std::unordered_map< Node, Edges > Graph
Bi-partite graph of instance.
Definition: Index.h:184
souffle::ram::analysis::MinIndexSelection::getChain
Chain getChain(const SearchSignature umn, const MaxMatching::Matchings &match)
@Brief get a chain from a matching
Definition: Index.cpp:348
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ram::analysis::MinIndexSelection::OrderCollection
std::vector< LexOrder > OrderCollection
Definition: Index.h:217
souffle::ram::analysis::MaxMatching::getNumMatchings
int getNumMatchings() const
@Brief get number of matches in the solution
Definition: Index.h:142
souffle::ram::analysis::MinIndexSelection::print
void print(std::ostream &os)
Definition: Index.h:302
souffle::ram::analysis::MinIndexSelection::MinIndexSelection
MinIndexSelection()=default
souffle::ram::analysis::SearchSignature::empty
bool empty() const
Definition: Index.cpp:77
souffle::ram::analysis::MaxMatching::match
Matchings match
Definition: Index.h:190
souffle::ram::analysis::MaxMatching::dfSearch
bool dfSearch(Node u)
@Brief perform a depth first search in the graph
Definition: Index.cpp:229
souffle::ram::analysis::MaxMatching::Edges
std::unordered_set< Node > Edges
Edges in the bi-partite graph.
Definition: Index.h:180