Gaia
queryoptimizer.h
1 /*
2  * Copyright (C) 2006-2013 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Gaia
5  *
6  * Gaia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef GAIA_QUERYOPTIMIZER_H
21 #define GAIA_QUERYOPTIMIZER_H
22 
23 #include "dataset.h"
24 #include "searchspacepool.h"
25 #include "parser/filter.h"
26 #include "parser/parsertypes.h"
27 
28 namespace gaia2 {
29 
37 template <typename SearchPointType, typename DataSetType>
38 class BaseQueryOptimizer {
39 
40  public:
41 
42  typedef BaseSearchSpacePool<SearchPointType, DataSetType> SearchSpacePoolType;
43  typedef BaseSearchSpace<SearchPointType, DataSetType> SearchSpaceType;
44 
45  BaseQueryOptimizer(SearchSpacePoolType* spool) : _spool(spool) {}
46 
54  SearchSpaceType* optimize(Filter* filter);
55 
56 
57  protected:
58  SearchSpacePoolType* _spool;
59 
60  SearchSpaceType* optimize(parser::Predicate* pred);
61 
62 
63  static parser::PredLabelIsIn* findPointID(parser::Predicate* pred);
64 
65  template <typename PredicateType>
66  static PredicateType* findPredicate(parser::Predicate* pred);
67 
72  static bool swapPredicate(Filter* filter, parser::Predicate* swapOut, parser::Predicate* swapIn);
73 
78  static bool swapPredicate(parser::Predicate* parent, parser::Predicate* swapOut, parser::Predicate* swapIn);
79 
83  static void deletePredicate(Filter* filter, parser::Predicate* pred);
84 
90  static void reduceFilter(Filter* filter);
91 
97  static parser::Predicate* reducePredicate(parser::Predicate* pred);
98 
99 
100 };
101 
102 typedef BaseQueryOptimizer<SearchPoint, DataSet> QueryOptimizer;
103 
104 } // namespace gaia2
105 
106 // we need to include our implementation here as we have a templated class
107 #include "queryoptimizer_impl.h"
108 
109 #endif // GAIA_QUERYOPTIMIZER_H
static parser::Predicate * reducePredicate(parser::Predicate *pred)
Tries to apply simplification on the predicate, such as replacing "X and True" by "X"...
Definition: queryoptimizer_impl.h:159
static void reduceFilter(Filter *filter)
Tries to apply simplification on the filter, such as replacing "X and True" by "X", etc...
Definition: queryoptimizer_impl.h:149
static void deletePredicate(Filter *filter, parser::Predicate *pred)
Deletes given predicate inside filter (replaces it with the always true predicate).
Definition: queryoptimizer_impl.h:142
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
SearchSpaceType * optimize(Filter *filter)
Ownership of the SearchSpace is yielded to the caller of the function.
Definition: queryoptimizer_impl.h:255
static bool swapPredicate(Filter *filter, parser::Predicate *swapOut, parser::Predicate *swapIn)
Swaps predicate swapOut inside of filter for predicate swapIn.
Definition: queryoptimizer_impl.h:102