00001
00002
00003
00004
00005
00006
00007
00008 #ifndef QUERYENGINE_H_
00009 #define QUERYENGINE_H_
00010
00011 #include "Common.h"
00012 #include "IQueryOperator.h"
00013 #include "RecordFileScan.h"
00014 #include "SystemManager.h"
00015
00023 struct RelationAttribute {
00024 char relName[MAX_RELATION_NAME];
00025 char attrName[MAX_ATTRIBUTE_NAME];
00026 };
00027
00034 struct TypedValue {
00035 AttributeType type;
00036 union {
00037 int i;
00038 float f;
00039 const char* str;
00040 };
00041 };
00042
00050 struct AttributeOrValue {
00051 bool isAttribute;
00052 union {
00053 RelationAttribute attribute;
00054 TypedValue value;
00055 };
00056 };
00057
00064 struct Condition {
00065 RelationAttribute left;
00066 ComparisonOp op;
00067 AttributeOrValue right;
00068 };
00069
00081 class QueryEngine {
00082 public:
00086 static QueryEngine* getInstance();
00087
00113 ReturnCode select(int nAttributes, const RelationAttribute attributes[],
00114 int nRelations, const char* relations[],
00115 int nConditions, const Condition conditions[]);
00116
00134 ReturnCode insert(const char* relName, int nValues,
00135 const TypedValue values[]);
00136
00162 ReturnCode remove(const char* relName, int nConditions,
00163 const Condition conditions[]);
00164
00191 ReturnCode update(const char* relName, const RelationAttribute* left,
00192 const AttributeOrValue* right, int nConditions,
00193 const Condition conditions[]);
00194
00195 private:
00196
00197
00198
00199 ReturnCode buildScanNode(const char* relation, IQueryOperator** scan);
00200
00201 ReturnCode buildProjectNode(IQueryOperator* child, int nAttributes,
00202 const RelationAttribute attributes[],
00203 IQueryOperator** project);
00204
00205 ReturnCode buildExecutionPlan(int nAttributes, const RelationAttribute attributes[],
00206 int nRelations, const char* relations[],
00207 int nConditions, const Condition conditions[],
00208 IQueryOperator** root);
00209 uint getRecordSize(int nAttributes, const RelationAttributeInfo attributes[]);
00210
00211 SystemManager* sm_;
00212 RecordManager* rm_;
00213
00214
00215 bool isQueryPlansOn();
00216
00217 QueryEngine();
00218 ~QueryEngine();
00219
00220 };
00221
00222 #endif