souffle  2.0.2-371-g6315b36
ParallelIndexChoice.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 ParallelIndexChoice.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "AggregateOp.h"
18 #include "ram/AbstractParallel.h"
19 #include "ram/Condition.h"
20 #include "ram/Expression.h"
21 #include "ram/IndexChoice.h"
22 #include "ram/IndexOperation.h"
23 #include "ram/NestedOperation.h"
24 #include "ram/Node.h"
25 #include "ram/Relation.h"
26 #include "ram/utility/NodeMapper.h"
27 #include "ram/utility/Utils.h"
31 #include <cassert>
32 #include <cstddef>
33 #include <iosfwd>
34 #include <memory>
35 #include <ostream>
36 #include <string>
37 #include <utility>
38 #include <vector>
39 
40 namespace souffle::ram {
41 
42 /**
43  * @class ParallelIndexChoice
44  * @brief Use an index to find a tuple in a relation such that a given condition holds in parallel.
45  *
46  * For example:
47  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
48  * QUERY
49  * ...
50  * PARALLEL CHOICE A AS t1 ON INDEX t1.x=10 AND t1.y = 20
51  * WHERE (t1.x, t1.y) NOT IN A
52  * ...
53  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
54  */
55 class ParallelIndexChoice : public IndexChoice, public AbstractParallel {
56 public:
57  ParallelIndexChoice(std::string rel, int ident, Own<Condition> cond, RamPattern queryPattern,
58  Own<Operation> nested, std::string profileText = "")
60  rel, ident, std::move(cond), std::move(queryPattern), std::move(nested), profileText) {}
61 
62  ParallelIndexChoice* clone() const override {
63  RamPattern resQueryPattern;
64  for (const auto& i : queryPattern.first) {
65  resQueryPattern.first.emplace_back(i->clone());
66  }
67  for (const auto& i : queryPattern.second) {
68  resQueryPattern.second.emplace_back(i->clone());
69  }
71  std::move(resQueryPattern), souffle::clone(&getOperation()), getProfileText());
72  return res;
73  }
74 
75 protected:
76  void print(std::ostream& os, int tabpos) const override {
77  os << times(" ", tabpos);
78  os << "PARALLEL CHOICE " << relation << " AS t" << getTupleId();
79  printIndex(os);
80  os << " WHERE " << getCondition();
81  os << std::endl;
82  IndexOperation::print(os, tabpos + 1);
83  }
84 };
85 
86 } // namespace souffle::ram
souffle::ram::NestedOperation::profileText
const std::string profileText
Text used by the profiler.
Definition: NestedOperation.h:93
souffle::ram::ParallelIndexChoice::ParallelIndexChoice
ParallelIndexChoice(std::string rel, int ident, Own< Condition > cond, RamPattern queryPattern, Own< Operation > nested, std::string profileText="")
Definition: ParallelIndexChoice.h:61
NestedOperation.h
AggregateOp.h
souffle::ram::ParallelIndexChoice
Use an index to find a tuple in a relation such that a given condition holds in parallel.
Definition: ParallelIndexChoice.h:59
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
NodeMapper.h
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
IndexChoice.h
i
size_t i
Definition: json11.h:663
ContainerUtil.h
souffle::ram::NestedOperation::getProfileText
const std::string & getProfileText() const
Get profile text.
Definition: NestedOperation.h:67
souffle::ram::ParallelIndexChoice::clone
ParallelIndexChoice * clone() const override
Create a clone (i.e.
Definition: ParallelIndexChoice.h:66
Relation.h
Condition.h
souffle::ram::IndexChoice
Use an index to find a tuple in a relation such that a given condition holds.
Definition: IndexChoice.h:58
souffle::ram::TupleOperation::getTupleId
int getTupleId() const
Get identifier.
Definition: TupleOperation.h:43
Utils.h
souffle::ram::IndexOperation::printIndex
void printIndex(std::ostream &os) const
Helper method for printing.
Definition: IndexOperation.h:108
IndexOperation.h
AbstractParallel.h
Node.h
std
Definition: Brie.h:3053
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
souffle::ram::AbstractChoice::condition
Own< Condition > condition
Condition for which a tuple in the relation may hold.
Definition: AbstractChoice.h:65
souffle::ram::ParallelIndexChoice::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: ParallelIndexChoice.h:80
Expression.h
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ram::AbstractChoice::getCondition
const Condition & getCondition() const
Getter for the condition.
Definition: AbstractChoice.h:45
souffle::ram::NestedOperation::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedOperation.h:80