Skip to content

Commit

Permalink
Merge branch 'master' of /afs/ir/users/n/a/nandu/git/redbase
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandu Jayakumar committed May 27, 2011
2 parents 1add15a + 304be32 commit 03951b6
Show file tree
Hide file tree
Showing 30 changed files with 1,392 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
src/mjVSnlij
src/mjVSnbj
src/redbase
src/dbdestroy
src/dbcreate
Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ QL_SOURCES = statistics.cc ql_manager.cc ql_error.cc file_scan.cc \
file_scan_gtest.cc index_scan.cc index_scan_gtest.cc \
nested_loop_join.cc nested_loop_join_gtest.cc \
ql_manager_gtest.cc projection.cc nested_block_join_gtest.cc \
merge_join.cc merge_join_gtest.cc sort_gtest.cc

UTILS_SOURCES = dbcreate.cc dbdestroy.cc redbase.cc
PARSER_SOURCES = scan.c parse.c nodes.c interp.c
Expand Down
47 changes: 0 additions & 47 deletions src/index_merge_join.h

This file was deleted.

3 changes: 2 additions & 1 deletion src/index_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

using namespace std;

class IndexScan: public Iterator {
class IndexScan: public SortedIterator {
public:
IndexScan(SM_Manager& smm,
RM_Manager& rmm,
Expand Down Expand Up @@ -42,6 +42,7 @@ class IndexScan: public Iterator {
virtual RC ReOpenScan(void* newData);
virtual string GetIndexAttr() const { return attrName; }
virtual string GetIndexRel() const { return relName; }
virtual bool IsDesc() const { return ifs.IsDesc(); }

private:
IX_IndexScan ifs;
Expand Down
41 changes: 37 additions & 4 deletions src/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static int mk_attr_infos(NODE *list, int max, AttrInfo attrInfos[]);
static int parse_format_string(char *format_string, AttrType *type, int *len);
static int mk_rel_attrs(NODE *list, int max, RelAttr relAttrs[]);
static void mk_rel_attr(NODE *node, RelAttr &relAttr);
static void mk_order_relattr(NODE *node, int& order, RelAttr &relAttr);
static int mk_relations(NODE *list, int max, char *relations[]);
static int mk_conditions(NODE *list, int max, Condition conditions[]);
static int mk_values(NODE *list, int max, Value values[]);
Expand All @@ -54,6 +55,7 @@ static void echo_query(NODE *n);
static void print_attrtypes(NODE *n);
static void print_op(CompOp op);
static void print_relattr(NODE *n);
static void print_orderattr(NODE *n);
static void print_value(NODE *n);
static void print_condition(NODE *n);
static void print_relattrs(NODE *n);
Expand Down Expand Up @@ -150,6 +152,8 @@ RC interp(NODE *n)
char *relations[MAXATTRS];
int nConditions = 0;
Condition conditions[MAXATTRS];
int order = 0; /* -1 desc, 0 no order, 1 asc */
RelAttr orderAttr;

/* Make a list of RelAttrs suitable for sending to Query */
nSelAttrs = mk_rel_attrs(n->u.QUERY.relattrlist, MAXATTRS,
Expand All @@ -174,12 +178,16 @@ RC interp(NODE *n)
break;
}

/* Make the order by attr suitable for sending to Query */
mk_order_relattr(n->u.QUERY.orderrelattr, order, orderAttr);

/* Make the call to Select */
errval = pQlm->Select(nSelAttrs, relAttrs,
nRelations, relations,
nConditions, conditions);
nRelations, relations,
nConditions, conditions,
order, orderAttr);
break;
}
}

case N_INSERT: /* for Insert() */
{
Expand Down Expand Up @@ -332,6 +340,18 @@ static int mk_rel_attrs(NODE *list, int max, RelAttr relAttrs[])
return i;
}

/*
* mk_order_relattr: converts an int and a single relation-attribute (<relation,
* attribute> pair) into a RelAttr
*/
static void mk_order_relattr(NODE *node, int& order, RelAttr &relAttr)
{
order = node->u.ORDERATTR.order;
if(order != 0)
mk_rel_attr(node->u.ORDERATTR.relattr, relAttr);
}


/*
* mk_rel_attr: converts a single relation-attribute (<relation,
* attribute> pair) into a RelAttr
Expand Down Expand Up @@ -611,11 +631,15 @@ static void echo_query(NODE *n)
print_relattrs(n -> u.QUERY.relattrlist);
printf("\n from ");
print_relations(n -> u.QUERY.rellist);
printf("\n");
if (n->u.QUERY.conditionlist) {
printf("\n");
printf("where ");
print_conditions(n->u.QUERY.conditionlist);
}
if (n->u.QUERY.orderrelattr) {
print_orderattr(n->u.QUERY.orderrelattr);
}

printf(";\n");
break;
case N_INSERT: /* for Insert() */
Expand Down Expand Up @@ -698,6 +722,15 @@ static void print_op(CompOp op)
}
}

static void print_orderattr(NODE *n)
{
if (n->u.ORDERATTR.order != 0) {
printf("\norder by");
print_relattr(n->u.ORDERATTR.relattr);
printf(" %s", (n->u.ORDERATTR.order == 1 ? "ASC" : "DESC"));
}
}

static void print_relattr(NODE *n)
{
printf(" ");
Expand Down
18 changes: 17 additions & 1 deletion src/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DataAttrInfo;

// abstraction to hide details of offsets and type conversions
class Tuple {
public:
public:
Tuple(int ct, int length_): count(ct), length(length_), rid(-1, -1) {
data = new char[length];
}
Expand All @@ -26,6 +26,14 @@ class Tuple {
SetAttr(rhs.GetAttributes());
}

Tuple& operator=(const Tuple& rhs) {
if (this != &rhs) {
memcpy(data, rhs.data, length);
SetAttr(rhs.GetAttributes());
}
return *this;
}

~Tuple() { delete [] data; }
int GetLength() const { return length; }
int GetAttrCount() const { return count; }
Expand Down Expand Up @@ -133,6 +141,7 @@ namespace {
}
};


class Iterator {
public:
Iterator():bIterOpen(false), indent("") {}
Expand Down Expand Up @@ -175,4 +184,11 @@ class Iterator {
string indent;
};

class SortedIterator : public virtual Iterator {
public:
virtual bool IsDesc() const { return desc; }
protected:
bool desc;
};

#endif // ITERATOR_H
1 change: 1 addition & 0 deletions src/ix_indexscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class IX_IndexScan {
RC ResetState();

bool IsOpen() const { return (bOpen && pred != NULL && pixh != NULL); }
bool IsDesc() const { return desc; }
private:
RC OpOptimize(); // Optimizes based on value of c, value and resets state
RC EarlyExitOptimize(void* now);
Expand Down
Loading

0 comments on commit 03951b6

Please sign in to comment.