souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Attributes | Private Attributes
souffle::ram::analysis::IndexAnalysis Class Reference

#include <Index.h>

Inheritance diagram for souffle::ram::analysis::IndexAnalysis:
Inheritance graph
Collaboration diagram for souffle::ram::analysis::IndexAnalysis:
Collaboration graph

Public Member Functions

MinIndexSelectiongetIndexes (const std::string &relName)
 @Brief get the minimal index cover for a relation More...
 
SearchSignature getSearchSignature (const ExistenceCheck *existCheck) const
 @Brief Get the index signature for an existence check More...
 
SearchSignature getSearchSignature (const IndexOperation *search) const
 @Brief Get index signature for an Ram IndexOperation operation More...
 
SearchSignature getSearchSignature (const ProvenanceExistenceCheck *existCheck) const
 @Brief Get the index signature for a provenance existence check More...
 
SearchSignature getSearchSignature (const Relation *ramRel) const
 @Brief Get the default index signature for a relation (the total-order index) More...
 
 IndexAnalysis (const char *id)
 
bool isTotalSignature (const AbstractExistenceCheck *existCheck) const
 @Brief index signature of existence check resembles a total index More...
 
void print (std::ostream &os) const override
 Print the analysis result in HTML format. More...
 
void run (const TranslationUnit &translationUnit) override
 Run analysis for a RAM translation unit. More...
 
- Public Member Functions inherited from souffle::ram::analysis::Analysis
 Analysis (const char *id)
 
virtual const std::string & getName () const
 get name of the analysis More...
 
virtual ~Analysis ()=default
 

Static Public Attributes

static constexpr const char * name = "index-analysis"
 

Private Attributes

std::map< std::string, MinIndexSelectionminIndexCover
 minimal index cover for relations, i.e., maps a relation to a set of indexes More...
 
RelationAnalysisrelAnalysis
 relation analysis for looking up relations by name More...
 

Additional Inherited Members

- Protected Attributes inherited from souffle::ram::analysis::Analysis
std::string identifier
 name of analysis instance More...
 

Detailed Description

Definition at line 413 of file Index.h.

Constructor & Destructor Documentation

◆ IndexAnalysis()

souffle::ram::analysis::IndexAnalysis::IndexAnalysis ( const char *  id)
inline

Definition at line 415 of file Index.h.

415 : Analysis(id), relAnalysis(nullptr) {}

Member Function Documentation

◆ getIndexes()

MinIndexSelection & souffle::ram::analysis::IndexAnalysis::getIndexes ( const std::string &  relName)

@Brief get the minimal index cover for a relation

Parameters
relationname
Returns
set of indexes of the minimal index cover

Definition at line 549 of file Index.cpp.

554  {
555  for (auto& cur : minIndexCover) {
556  const std::string& relName = cur.first;
557  const MinIndexSelection& indexes = cur.second;
558 

Referenced by run().

◆ getSearchSignature() [1/4]

SearchSignature souffle::ram::analysis::IndexAnalysis::getSearchSignature ( const ExistenceCheck existCheck) const

@Brief Get the index signature for an existence check

Parameters
Existencecheck
Returns
index signature of existence check

Definition at line 655 of file Index.cpp.

658  {

◆ getSearchSignature() [2/4]

SearchSignature souffle::ram::analysis::IndexAnalysis::getSearchSignature ( const IndexOperation search) const

@Brief Get index signature for an Ram IndexOperation operation

Parameters
Index-relation-searchoperation
Returns
Index signature of operation

Definition at line 612 of file Index.cpp.

613  {
614  // if both bounds are undefined
615  if (isUndefValue(lower[i]) && isUndefValue(upper[i])) {
617  // if bounds are equal we have an equality
618  } else if (*lower[i] == *upper[i]) {
620  } else {
622  }
623  }
624  return keys;
625 }
626 
627 SearchSignature IndexAnalysis::getSearchSignature(const ProvenanceExistenceCheck* provExistCheck) const {
628  const auto values = provExistCheck->getValues();
629  const Relation* rel = &relAnalysis->lookup(provExistCheck->getRelation());
630  auto auxiliaryArity = rel->getAuxiliaryArity();
631 

Referenced by run().

◆ getSearchSignature() [3/4]

SearchSignature souffle::ram::analysis::IndexAnalysis::getSearchSignature ( const ProvenanceExistenceCheck existCheck) const

@Brief Get the index signature for a provenance existence check

Parameters
Provenance-existencecheck
Returns
index signature of provenance-existence check

Definition at line 633 of file Index.cpp.

635  {
636  if (!isUndefValue(values[i])) {
638  }
639  }
640 
641  // all auxiliary attributes should be free
642  for (size_t i = values.size() - auxiliaryArity; i < values.size(); i++) {
644  }
645 
646  return keys;
647 }
648 
649 SearchSignature IndexAnalysis::getSearchSignature(const ExistenceCheck* existCheck) const {
650  const Relation* rel = &relAnalysis->lookup(existCheck->getRelation());
651  return searchSignature(rel->getArity(), existCheck->getValues());
652 }
653 

References souffle::ram::analysis::Equal, i, and souffle::ram::isUndefValue().

Here is the call graph for this function:

◆ getSearchSignature() [4/4]

SearchSignature souffle::ram::analysis::IndexAnalysis::getSearchSignature ( const Relation ramRel) const

@Brief Get the default index signature for a relation (the total-order index)

Parameters
ramRelRAM-relation
Returns
total full-signature of the relation

Definition at line 660 of file Index.cpp.

660  {
661  return false;
662  }

◆ isTotalSignature()

bool souffle::ram::analysis::IndexAnalysis::isTotalSignature ( const AbstractExistenceCheck existCheck) const

@Brief index signature of existence check resembles a total index

Parameters
(provenance)existence check

isTotalSignature returns true if all elements of a tuple are used for the the existence check.

Definition at line 664 of file Index.cpp.

◆ print()

void souffle::ram::analysis::IndexAnalysis::print ( std::ostream &  ) const
overridevirtual

Print the analysis result in HTML format.

Reimplemented from souffle::ram::analysis::Analysis.

Definition at line 560 of file Index.cpp.

561  : " << indexes.getSearches().size() << "\n";
562 
563  /* print searches */
564  for (auto& search : indexes.getSearches()) {
565  os << "\t\t";
566  os << search;
567  os << "\n";
568  }
569 
570  /* print chains */
571  for (auto& chain : indexes.getAllChains()) {
572  os << join(chain, "-->") << "\n";
573  }
574  os << "\n";
575 
576  os << "\tNumber of Indexes: " << indexes.getAllOrders().size() << "\n";
577  for (auto& order : indexes.getAllOrders()) {
578  os << "\t\t";
579  os << join(order, "<") << "\n";
580  os << "\n";
581  }
582  }
583 }
584 
585 namespace {
586 // handles equality constraints
587 template <typename Iter>
588 SearchSignature searchSignature(size_t arity, Iter const& bgn, Iter const& end) {
589  SearchSignature keys(arity);

◆ run()

void souffle::ram::analysis::IndexAnalysis::run ( const TranslationUnit translationUnit)
overridevirtual

Run analysis for a RAM translation unit.

Implements souffle::ram::analysis::Analysis.

Definition at line 480 of file Index.cpp.

489  {
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)) {
494  MinIndexSelection& indexes = getIndexes(exists->getRelation());
495  indexes.addSearch(getSearchSignature(exists));
496  } else if (const auto* provExists = dynamic_cast<const ProvenanceExistenceCheck*>(&node)) {
497  MinIndexSelection& indexes = getIndexes(provExists->getRelation());
498  indexes.addSearch(getSearchSignature(provExists));
499  } else if (const auto* ramRel = dynamic_cast<const Relation*>(&node)) {
500  MinIndexSelection& indexes = getIndexes(ramRel->getName());
501  indexes.addSearch(getSearchSignature(ramRel));
502  }
503  });
504 
505  // A swap happen between rel A and rel B indicates A should include all indices of B, vice versa.
506  visitDepthFirst(translationUnit.getProgram(), [&](const Swap& swap) {
507  // Note: this naive approach will not work if there exists chain or cyclic swapping.
508  // e.g. swap(relA, relB) swap(relB, relC) swap(relC, relA)
509  // One need to keep merging the search set until a fixed point where no more index is introduced
510  // in any of the relation in a complete iteration.
511  //
512  // Currently RAM does not have such situation.
513  const std::string& relA = swap.getFirstRelation();
514  const std::string& relB = swap.getSecondRelation();
515  MinIndexSelection& indexesA = getIndexes(relA);
516  MinIndexSelection& indexesB = getIndexes(relB);
517  // Add all searchSignature of A into B
518  for (const auto& signature : indexesA.getSearches()) {
519  indexesB.addSearch(signature);
520  }
521 
522  // Add all searchSignature of B into A
523  for (const auto& signature : indexesB.getSearches()) {
524  indexesA.addSearch(signature);
525  }
526  });
527 
528  // find optimal indexes for relations
529  for (auto& cur : minIndexCover) {
530  MinIndexSelection& indexes = cur.second;
531  indexes.solve();
532  }
533 
534  // Only case where indexSet is still empty is when relation has arity == 0
535  for (auto& cur : minIndexCover) {
536  MinIndexSelection& indexes = cur.second;
537  if (indexes.getAllOrders().empty()) {
538  indexes.insertDefaultTotalIndex(0);
539  }
540  }
541 }
542 
543 MinIndexSelection& IndexAnalysis::getIndexes(const std::string& relName) {
544  auto pos = minIndexCover.find(relName);
545  if (pos != minIndexCover.end()) {
546  return pos->second;
547  } else {

References souffle::ram::analysis::MinIndexSelection::addSearch(), getIndexes(), and getSearchSignature().

Here is the call graph for this function:

Field Documentation

◆ minIndexCover

std::map<std::string, MinIndexSelection> souffle::ram::analysis::IndexAnalysis::minIndexCover
private

minimal index cover for relations, i.e., maps a relation to a set of indexes

Definition at line 474 of file Index.h.

◆ name

constexpr const char* souffle::ram::analysis::IndexAnalysis::name = "index-analysis"
staticconstexpr

Definition at line 417 of file Index.h.

◆ relAnalysis

RelationAnalysis* souffle::ram::analysis::IndexAnalysis::relAnalysis
private

relation analysis for looking up relations by name

Definition at line 469 of file Index.h.


The documentation for this class was generated from the following files:
souffle::ram::isUndefValue
bool isUndefValue(const Expression *expr)
Determines if an expression represents an undefined value.
Definition: Utils.h:40
souffle::ram::analysis::AttributeConstraint::Inequal
@ Inequal
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
n
var n
Definition: htmlJsChartistMin.h:15
souffle::ram::analysis::AttributeConstraint::None
@ None
i
size_t i
Definition: json11.h:663
souffle::ram::analysis::Analysis::Analysis
Analysis(const char *id)
Definition: Analysis.h:40
souffle::ram::analysis::AttributeConstraint::Equal
@ Equal
souffle::ram::analysis::IndexAnalysis::relAnalysis
RelationAnalysis * relAnalysis
relation analysis for looking up relations by name
Definition: Index.h:469
souffle::ram::analysis::RelationAnalysis::lookup
const ram::Relation & lookup(const std::string &name) const
Definition: Relation.cpp:33
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::visitDepthFirst
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...
Definition: Visitor.h:357
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086