souffle  2.0.2-371-g6315b36
IndexedInequality.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 IndexedInequality.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Program.h"
18 #include "ram/TranslationUnit.h"
19 #include "ram/analysis/Index.h"
20 #include "ram/analysis/Relation.h"
22 #include <string>
23 
24 namespace souffle::ram::transform {
25 
26 /**
27  * @class IndexedInequalityTransformer
28  * @brief Removes Inequalities from Indexed Operations and replaces them with a Filter Operation
29  * and empty Indexed Operations are coverted to their Non-Indexed semantic equivalent
30  *
31  * If there exists inequality constraints in an Indexed Operation, these constraints will be
32  * replaced with a semantically equivalent nested Filter Operation.
33  *
34  * Furthermore, if after removing all of these inequality constraints from the Indexed Operation
35  * we may find that the Indexed Operation is empty (no constraints).
36  * This occurs in the case where an Indexed Operation is composed entirely of inequality constraints.
37  * In this situation, the Indexed Operation is empty and replaced with a semantically equivalent Operation.
38  * i.e. IndexScan -> Scan
39  *
40  * For example,
41  *
42  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
43  * QUERY
44  * ...
45  * FOR t1 IN X ON INDEX t1.x < 10 AND t1.y > 20
46  * ... // t1 only has inequality constraints placed on it
47  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
48  *
49  * will be rewritten to
50  *
51  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
52  * QUERY
53  * ...
54  * FOR t1 in X ON INDEX // empty index since all inequalities have been removed
55  * IF t1.x < 10 AND t1.y > 20
56  * // replaced with a semantically equivalent filter
57  * ...
58  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
59  *
60  * will be rewritten to
61  *
62  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
63  * QUERY
64  * ...
65  * FOR t1 in X // Scan instead of IndexScan
66  * IF t1.x < 10 AND t1.y > 20
67  * // replaced with a semantically equivalent filter
68  * ...
69  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
70  *
71  */
72 class IndexedInequalityTransformer : public Transformer {
73 public:
74  std::string getName() const override {
75  return "IndexedInequalityTransformer";
76  }
77 
78  /** Converts a box query into a corresponding partial box query operation.
79  * This will turn every box query into a filter operation.
80  */
81  bool transformIndexToFilter(Program& program);
82 
83 protected:
84  bool transform(TranslationUnit& translationUnit) override {
85  idxAnalysis = translationUnit.getAnalysis<analysis::IndexAnalysis>();
87  return transformIndexToFilter(translationUnit.getProgram());
88  }
89 
92 };
93 
94 } // namespace souffle::ram::transform
souffle::ram::transform
Definition: ChoiceConversion.cpp:30
souffle::ram::transform::IndexedInequalityTransformer::transform
bool transform(TranslationUnit &translationUnit) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: IndexedInequality.h:88
souffle::ram::Program
RAM program relation declaration and functions.
Definition: Program.h:58
souffle::ram::TranslationUnit::getAnalysis
Analysis * getAnalysis() const
Get an analysis.
Definition: TranslationUnit.h:66
Index.h
souffle::ram::transform::IndexedInequalityTransformer::idxAnalysis
analysis::IndexAnalysis * idxAnalysis
Definition: IndexedInequality.h:94
souffle::ram::transform::IndexedInequalityTransformer::relAnalysis
analysis::RelationAnalysis * relAnalysis
Definition: IndexedInequality.h:95
Program.h
souffle::ram::TranslationUnit::getProgram
Program & getProgram() const
Get the RAM Program of the translation unit
Definition: TranslationUnit.h:107
souffle::ram::TranslationUnit
Translating a RAM program.
Definition: TranslationUnit.h:55
Relation.h
souffle::ram::analysis::IndexAnalysis
Definition: Index.h:413
TranslationUnit.h
Transformer.h
souffle::ram::transform::IndexedInequalityTransformer::getName
std::string getName() const override
@Brief get name of the transformer
Definition: IndexedInequality.h:78
souffle::ram::transform::IndexedInequalityTransformer::transformIndexToFilter
bool transformIndexToFilter(Program &program)
Converts a box query into a corresponding partial box query operation.
Definition: IndexedInequality.cpp:41
souffle::ram::analysis::RelationAnalysis
A RAM Analysis for finding relations by name.
Definition: Relation.h:36