-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.h
executable file
·126 lines (105 loc) · 6.41 KB
/
query.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef QUERY_H
#define QUERY_H
#include "heapfile.h"
#include "index.h"
//
// Prototypes for query layer functions
//
//
// The class for encapsulating the query operators: selects and joins
// Projections are folded into the selects and joins
//
class Operators
{
public:
// The select operator
static Status Select(const string & result, // Name of the output relation
const int projCnt, // Number of attributes in the projection
const attrInfo projNames[], // List of projection attributes
const attrInfo *attr, // Attribute used in the selection predicate
#ifdef BTREE_INDEX
const Operator op,
const void *attrValue,
const Operator op2 = NOTSET,
const void *attrValue2 = 0);
#else // hash index only
const Operator op, // Predicate operator
const void *attrValue); // Literal value in the predicate
#endif // BTREE_INDEX
// The join operator
static Status Join(const string& result, // Name of the output relation
const int projCnt, // Number of attributes in the projection
const attrInfo projNames[], // List of projection attributes
const attrInfo* attr1, // Left attr in the join predicate
const Operator op, // Predicate operator
const attrInfo* attr2); // Right attr in the join predicate
private:
// A simple scan select using a heap file scan
static Status ScanSelect(const string & result, // Name of the output relation
const int projCnt, // Number of attributes in the projection
const AttrDesc projNames[], // Projection list (as AttrDesc)
const AttrDesc *attrDesc, // Attribute in the selection predicate
const Operator op, // Predicate operator
const void *attrValue, // Pointer to the literal value in the predicate
const int reclen); // Length of a tuple in the result relation
// Select using an index
static Status IndexSelect(const string& result, // Name of the output relation
const int projCnt, // Number of attributes in the projection
const AttrDesc projNames[], // Projection list (as AttrDesc)
const AttrDesc* attrDesc, // Attribute in the selection predicate
const Operator op, // Predicate operator
const void* attrValue, // Pointer to the literal value in the predicate
#ifdef BTREE_INDEX
const Operator op2,
const void *attrValue2,
#endif // BTREE_INDEX
const int reclen); // Length of a tuple in the result relation
// Function to match two record based on the predicate. Returns 0 if the two attributes
// are equal, a negative number if the left (attrDesc1) attribute is less that the right
// attribute, otherwise this function returns a positive number.
static double matchRec(const Record & outerRec, // Left record
const Record & innerRec, // Right record
const AttrDesc & attrDesc1, // Left attribute in the predicate
const AttrDesc & attrDesc2); // Right attribute in the predicate
// The various join algorithms are declared below.
// Simple nested loops
static Status SNL(const string& result, // Output relation name
const int projCnt, // Number of attributes in the projection
const AttrDesc attrDescArray[], // Projection list (as AttrDesc)
const AttrDesc& attrDesc1, // The left attribute in the join predicate
const Operator op, // Predicate operator
const AttrDesc& attrDesc2, // The left attribute in the join predicate
const int reclen); // The length of a tuple in the result relation
// indexed nested loops
static Status INL(const string& result, // Output relation name
const int projCnt, // Number of attributes in the projection
const AttrDesc attrDescArray[], // Projection list (as AttrDesc)
const AttrDesc& attrDesc1, // The left attribute in the join predicate
const Operator op, // Predicate operator
const AttrDesc& attrDesc2, // The left attribute in the join predicate
const int reclen); // The length of a tuple in the result relation
// Sort-merge join algorithm
static Status SMJ(const string& result, // Output relation name
const int projCnt, // Number of attributes in the projection
const AttrDesc attrDescArray[], // Projection list (as AttrDesc)
const AttrDesc& attrDesc1, // The left attribute in the join predicate
const Operator op, // Predicate operator
const AttrDesc& attrDesc2, // The left attribute in the join predicate
const int reclen); // The length of a tuple in the result relation
};
// The class encapsulating the insert and delete operators
class Updates
{
public:
// The insert operator
static Status Insert(const string& relation, // The relation into which to insert the tuple
const int attrCnt, // Number of attributes in the attrList
const attrInfo attrList[]); // The attribute list (with the attribute name and value)
// The delete operator
static Status Delete(const string& relation, // The relation into which to insert the tuple
const string& attrName, // The attribute in the predicate
const Operator op, // The predicate operation
const Datatype type, // The predicate type
const void* attrValue); // The literal used in the predicate
};
#endif