souffle  2.0.2-371-g6315b36
IndexScan.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. 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 IndexScan.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Expression.h"
18 #include "ram/IndexOperation.h"
19 #include "ram/Operation.h"
20 #include "ram/Relation.h"
23 #include <iosfwd>
24 #include <memory>
25 #include <ostream>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ram {
31 
32 /** Pattern type for lower/upper bound */
33 using RamBound = VecOwn<Expression>;
34 using RamPattern = std::pair<RamBound, RamBound>;
35 
36 /**
37  * @class IndexScan
38  * @brief Search for tuples of a relation matching a criteria
39  *
40  * For example:
41  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
42  * QUERY
43  * ...
44  * FOR t1 IN X ON INDEX t1.c = t0.0
45  * ...
46  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
47  */
48 class IndexScan : public IndexOperation {
49 public:
50  IndexScan(std::string rel, int ident, RamPattern queryPattern, Own<Operation> nested,
51  std::string profileText = "")
52  : IndexOperation(rel, ident, std::move(queryPattern), std::move(nested), std::move(profileText)) {
53  }
54 
55  IndexScan* clone() const override {
56  RamPattern resQueryPattern;
57  for (const auto& i : queryPattern.first) {
58  resQueryPattern.first.emplace_back(i->clone());
59  }
60  for (const auto& i : queryPattern.second) {
61  resQueryPattern.second.emplace_back(i->clone());
62  }
63  return new IndexScan(relation, getTupleId(), std::move(resQueryPattern),
65  }
66 
67 protected:
68  void print(std::ostream& os, int tabpos) const override {
69  os << times(" ", tabpos);
70  os << "FOR t" << getTupleId() << " IN " << relation;
71  printIndex(os);
72  os << std::endl;
73  IndexOperation::print(os, tabpos + 1);
74  }
75 };
76 
77 } // namespace souffle::ram
souffle::ram::NestedOperation::profileText
const std::string profileText
Text used by the profiler.
Definition: NestedOperation.h:93
souffle::ram::IndexOperation
Definition: IndexOperation.h:48
souffle::ram::RamBound
VecOwn< Expression > RamBound
Pattern type for lower/upper bound.
Definition: IndexOperation.h:41
souffle::ram::NestedOperation::getOperation
Operation & getOperation() const
Get nested operation.
Definition: NestedOperation.h:62
MiscUtil.h
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::RelationOperation::relation
const std::string relation
Search relation.
Definition: RelationOperation.h:60
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
i
size_t i
Definition: json11.h:663
souffle::ram::NestedOperation::getProfileText
const std::string & getProfileText() const
Get profile text.
Definition: NestedOperation.h:67
Relation.h
souffle::ram::IndexScan::IndexScan
IndexScan(std::string rel, int ident, RamPattern queryPattern, Own< Operation > nested, std::string profileText="")
Definition: IndexScan.h:54
souffle::ram::TupleOperation::getTupleId
int getTupleId() const
Get identifier.
Definition: TupleOperation.h:43
souffle::ram::IndexOperation::printIndex
void printIndex(std::ostream &os) const
Helper method for printing.
Definition: IndexOperation.h:108
souffle::ram::IndexScan
Search for tuples of a relation matching a criteria.
Definition: IndexScan.h:52
souffle::ram::IndexScan::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: IndexScan.h:72
IndexOperation.h
souffle::ram::IndexScan::clone
IndexScan * clone() const override
Create a clone (i.e.
Definition: IndexScan.h:59
std
Definition: Brie.h:3053
Operation.h
souffle::ram::IndexOperation::queryPattern
RamPattern queryPattern
Values of index per column of table (if indexable)
Definition: IndexOperation.h:161
souffle::ram::RamPattern
std::pair< RamBound, RamBound > RamPattern
Definition: IndexOperation.h:42
StreamUtil.h
Expression.h
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ram::NestedOperation::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedOperation.h:80