-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.cpp
More file actions
executable file
·70 lines (61 loc) · 1.76 KB
/
select.cpp
File metadata and controls
executable file
·70 lines (61 loc) · 1.76 KB
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
#include "catalog.h"
#include "query.h"
#include "index.h"
#include <string.h>
#include <cstdlib>
/*
* Selects records from the specified relation.
*
* Returns:
* OK on success
* an error code otherwise
*/
Status Operators::Select(const string & result, // name of the output relation
const int projCnt, // number of attributes in the projection
const attrInfo projNames[], // the list of projection attributes
const attrInfo *attr, // attribute used inthe selection predicate
const Operator op, // predicate operation
const void *attrValue) // literal value in the predicate
{
Status temp;
int tempLength=0;
AttrDesc Rattr;
AttrDesc TempProjNames[projCnt];
// get the length
for (int i = 0; i < projCnt; i++)
{
// get the correctness of attrInfo[]
temp=attrCat->getInfo(projNames[i].relName, projNames[i].attrName, Rattr);
if (temp != OK)
{
return temp;
}
TempProjNames[i]=Rattr;
tempLength+=Rattr.attrLen;
}
AttrDesc *tempD=NULL;
// determine which selection method to use
if(attr!=NULL)
{
temp=attrCat->getInfo(attr->relName, attr->attrName, Rattr);
if (temp != OK)
{
return temp;
}
// indexSelect, because there is predicate and op=EQ and there is index on the predicate
if(Rattr.indexed&&op == EQ)
{
return IndexSelect(result, projCnt, TempProjNames, &Rattr, op, attrValue, tempLength);
}
// scanSelect, because there is predicate but op is not EQ or there is no index
else
{
return ScanSelect(result, projCnt, TempProjNames, &Rattr, op, attrValue, tempLength);
}
}
else
{
// scanSelect, because there is no predicate
return ScanSelect(result, projCnt, TempProjNames, tempD, op, attrValue, tempLength);
}
}