-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery_executor.h
71 lines (59 loc) · 1.78 KB
/
query_executor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Created by aris on 7/1/20.
//
#ifndef QUERY_JOINER__QUERY_EXECUTOR_H_
#define QUERY_JOINER__QUERY_EXECUTOR_H_
#include "stretchy_buf.h"
#include "array.h"
#include "intermediate_result.h"
struct TaskState {
TaskState() : query_index{0U} {
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(¬ify, NULL);
}
pthread_mutex_t mutex;
pthread_cond_t notify;
size_t query_index;
};
/**
* This class is used to perform query executions,
* with the predicates being executed at any order.
* TODO maybe later we keep statistics in here too.
*/
class QueryExecutor {
public:
explicit QueryExecutor(RelationStorage &rs);
/**
* Executes a query based on it's parse result.
* @param pqr Parse result.
* @return List of the sums.
*/
StretchyBuf<uint64_t> execute_query(ParseQueryResult pqr);
/**
* Executes a query and returns a future object that will yield it's result.
*
* @param pqr Parse result.
* @return Future list of the sums.
*/
Future<StretchyBuf<uint64_t>> execute_query_async(ParseQueryResult pqr, TaskState *state);
void free();
private:
StretchyBuf<IntermediateResult> intermediate_results;
RelationStorage relation_storage;
pthread_mutex_t ir_mutex;
/**
* Get's the index of the ir that contains relation 'r'
* @param r Relation index.
* @return The index of the target ir in the list. If none returns -1.
*/
int get_target_ir_index(size_t r);
/**
* Removes the intermediate result at the specified index
* from the list.
* @param i Index.
*/
void intermediate_results_remove_at(size_t i);
static StretchyBuf<uint64_t> execute_query_static(QueryExecutor *this_qe,
ParseQueryResult pqr, TaskState *state);
};
#endif //QUERY_JOINER__QUERY_EXECUTOR_H_