| souffle
    2.0.2-371-g6315b36
    | 
 
 
 
Go to the documentation of this file.
   37 #include <unordered_map> 
   38 #include <unordered_set> 
   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);
 
  116     using Nodes = std::unordered_set<Node>;
 
  143         return match.size() / 2;
 
  180     using Edges = std::unordered_set<Node>;
 
  184     using Graph = std::unordered_map<Node, Edges>;
 
  212     using SignatureMap = std::unordered_map<SearchSignature, SearchSignature, SearchSignature::Hasher>;
 
  213     using SignatureIndexMap = std::unordered_map<SearchSignature, AttributeIndex, SearchSignature::Hasher>;
 
  215     using DischargeMap = std::unordered_map<SearchSignature, AttributeSet, SearchSignature::Hasher>;
 
  218     using Chain = std::vector<SearchSignature>;
 
  227             return hasher(s1) < hasher(s2);
 
  231     using SearchSet = std::set<SearchSignature, SearchComparator>;
 
  288         Chain chain = std::vector<SearchSignature>();
 
  290         chain.push_back(fullIndexKey);
 
  293         for (
size_t i = 0; 
i < arity; ++
i) {
 
  294             totalOrder.push_back(
i);
 
  296         orders.push_back(std::move(totalOrder));
 
  304         os << 
"\tNumber of Searches: " << 
getSearches().size() << 
"\n";
 
  315             os << 
join(chain, 
"-->") << 
"\n";
 
  319         os << 
"\tNumber of Indexes: " << 
getAllOrders().size() << 
"\n";
 
  322             os << 
join(order, 
"<") << 
"\n";
 
  340         for (
size_t i = 0; 
i < cols.
arity(); 
i++) {
 
  350         assert(
orders.size() == 
chainToOrder.size() && 
"Order and Chain Sizes do not match!!");
 
  353             if (std::find(it->begin(), it->end(), cols) != it->end()) {
 
  354                 assert((
size_t)
i < 
orders.size());
 
  358         fatal(
"cannot find matching lexicographical order");
 
  364         for (
size_t pos = 0; pos < delta.
arity(); pos++) {
 
  368                 backlog.push_back(pos);
 
  371         ids.insert(ids.end(), backlog.begin(), backlog.end());
 
  400         for (
auto node : nodes) {
 
  402                 unmatched.insert(node);
 
  417     static constexpr 
const char* 
name = 
"index-analysis";
 
  421     void print(std::ostream& os) 
const override;
 
  
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)
std::unordered_set< Node > Nodes
std::vector< SearchSignature > Chain
std::ostream & operator<<(std::ostream &out, const SearchSignature &signature)
A functor representing the identity function for a generic type T.
std::unordered_map< SearchSignature, AttributeIndex, SearchSignature::Hasher > SignatureIndexMap
Node getMatch(Node v)
@Brief get match for a search signature
bool isSubset(SearchSignature cols) const
Check whether number of constraints in k is not equal to number of columns in lexicographical order.
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
std::unordered_map< SearchSignature, AttributeSet, SearchSignature::Hasher > DischargeMap
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)
~MinIndexSelection()=default
std::unordered_map< AttributeIndex, SearchSignature > IndexSignatureMap
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
std::vector< AttributeIndex > LexOrder
void run(const TranslationUnit &translationUnit) override
Run analysis for a RAM translation unit.
const LexOrder & getLexOrder(SearchSignature cols) const
@Brief Get index for a search
Translating a RAM program.
Provenance Existence check for a relation.
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
IndexAnalysis(const char *id)
size_t operator()(const SearchSignature &searchSignature) const
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.
int getLexOrderNum(SearchSignature cols) const
@Brief Get index for a search
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
std::map< Node, Distance > DistanceMap
distance function of nodes
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
bool operator==(const SearchSignature &other) const
bool operator()(const SearchSignature &s1, const SearchSignature &s2) 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)
Abstract class for a RAM Analysis.
void insertDefaultTotalIndex(size_t arity)
@Brief insert a total order index
void fatal(const char *format, const Args &... args)
friend std::ostream & operator<<(std::ostream &out, const SearchSignature &signature)
const OrderCollection getAllOrders() const
@Brief Get all indexes
void addEdge(Node u, Node v)
@Brief add an edge to the bi-partite graph
A RAM Analysis for finding relations by name.
std::unordered_map< SearchSignature, SearchSignature, SearchSignature::Hasher > SignatureMap
static constexpr const char * name
const SearchSet & getSearches() const
@Brief Get searches
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
std::unordered_map< Node, Edges > Graph
Bi-partite graph of instance.
Chain getChain(const SearchSignature umn, const MaxMatching::Matchings &match)
@Brief get a chain from a matching
void rel(size_t limit, bool showLimit=true)
std::vector< LexOrder > OrderCollection
int getNumMatchings() const
@Brief get number of matches in the solution
void print(std::ostream &os)
MinIndexSelection()=default
bool dfSearch(Node u)
@Brief perform a depth first search in the graph
std::unordered_set< Node > Edges
Edges in the bi-partite graph.