Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
41ff0f2
operators return a pointer to tuple
toppyy Mar 4, 2025
07407e8
filter uses Tuple
toppyy Mar 4, 2025
ec8bd36
free tuples after use
toppyy Mar 5, 2025
d2ec056
fix aggregate; clean bufferpool stuff
toppyy Mar 5, 2025
cf3cb68
tuplebuffer added; some joins work now
toppyy Mar 5, 2025
386a228
fix join memory leaks (and logic)
toppyy Mar 5, 2025
c9356f7
all tests pass again
toppyy Mar 6, 2025
b1fe932
fix memleak on aggregates
toppyy Mar 6, 2025
53bc9f4
refactor aggregate-operator
toppyy Mar 9, 2025
8e375ce
cleanup
toppyy Mar 9, 2025
d878047
pass pointers to tpls
toppyy Mar 9, 2025
500e85f
do not allocate on every call..
toppyy Mar 9, 2025
52ad7fb
add EXPLAIN; use single alloc for join buffering
toppyy Mar 9, 2025
e58c8c2
remove bufferpool entirely
toppyy Mar 10, 2025
e6a2927
explain and test
toppyy Mar 10, 2025
18803bd
hashjoin started
toppyy Mar 11, 2025
442cf93
hashjoin sort of works
toppyy Mar 11, 2025
ef00fbb
hashmap without collision detection
toppyy Mar 11, 2025
0d7d459
minor changes
toppyy Mar 13, 2025
c5196f5
fix join memleaks; start collision handling
toppyy Mar 13, 2025
6994367
actually fix memleak
toppyy Mar 13, 2025
55acfc7
cont hashjoin collisions
toppyy Mar 14, 2025
ac37de8
introduce options
toppyy Mar 16, 2025
049a188
handle collisions in hashmap
toppyy Mar 16, 2025
c17a722
hashjoin with small ht-size
toppyy Mar 16, 2025
20e2893
update perf-stats
toppyy Mar 16, 2025
a772d13
add bats submodules
toppyy Mar 16, 2025
a73f4c7
use assert_output
toppyy Mar 16, 2025
e2bdf66
use csv-files for tests
toppyy Mar 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "bats"]
path = test/bats-core
url = https://github.com/bats-core/bats-core
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
[submodule "test/test_helper/bats-support"]
path = test/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(ODIR)/%.o: $(SRC)%.c
$(CC) -g -c $< -o $@ $(CFLAGS)

dirs:
mkdir -p data build/parser build/planner/operators build/binder build/io build/executor build/executor/statements build/bufferpool build/operators
mkdir -p data build/parser build/planner/operators build/binder build/io build/executor build/executor/statements build/operators build/util/hashmap

clean:
rm -f ./build/squel $(OBJ)
Expand Down
8 changes: 4 additions & 4 deletions perf/results/count.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
filetype;records;time
CSV;100000;0:00.05
CSV;100000;0:00.03
TDB;100000;0:00.00
CSV;1000000;0:00.46
CSV;1000000;0:00.30
TDB;1000000;0:00.04
Command terminated by signal 2
CSV;10000000;0:01.30
CSV;10000000;0:03.36
TDB;10000000;0:00.36
16 changes: 8 additions & 8 deletions perf/results/join.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
filetype;records_left;records_right;time
CSV;10000;100;0:00.06
TDB;10000;100;0:00.04
CSV;10000;1000;0:00.40
TDB;10000;1000;0:00.39
CSV;100000;100;0:00.45
TDB;100000;100;0:00.38
CSV;100000;1000;0:03.93
TDB;100000;1000;0:03.80
CSV;10000;100;0:00.05
TDB;10000;100;0:00.05
CSV;10000;1000;0:00.50
TDB;10000;1000;0:00.51
CSV;100000;100;0:00.55
TDB;100000;100;0:00.50
CSV;100000;1000;0:05.08
TDB;100000;1000;0:05.01
84 changes: 0 additions & 84 deletions src/bufferpool/bufferpool.c

This file was deleted.

3 changes: 3 additions & 0 deletions src/executor/executeStatement.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ void executeStatement(Node* node) {
case STMTINSERT:
executeInsert(node);
break;
case STMTEXPLAIN:
executeExplain(node);
break;
default:
printf("Don't know how execute statement of type %d\n", node->type);
exit(1);
Expand Down
31 changes: 14 additions & 17 deletions src/executor/executor.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../include/executor/executor.h"
#include "../include/executor/tuple.h"


Bufferpool* buffpool;

void assignGetTupleFunction(Operator *op) {

Expand All @@ -25,19 +25,19 @@ void assignGetTupleFunction(Operator *op) {
case (OP_JOIN):
op->getTuple = &joinGetTuple;
break;
case (OP_HASHJOIN):
op->getTuple = &hashjoinGetTuple;
break;
case (OP_AGGREGATE):
op->getTuple = &aggregateGetTuple;
break;
default:
printf("Don't know how to handle op-type %d\n", op->type);
printf("EXECUTOR-error: Don't know how to handle op-type %d\n", op->type);
exit(1);
}
}





void doAssignGetTupleFunction(Operator* p_op) {

if (p_op == NULL) {
Expand All @@ -50,23 +50,19 @@ void doAssignGetTupleFunction(Operator* p_op) {
doAssignGetTupleFunction(p_op->child);
}

if (p_op->type == OP_JOIN) {
if (p_op->type == OP_JOIN || p_op->type == OP_HASHJOIN) {
doAssignGetTupleFunction(p_op->info.join.left);
doAssignGetTupleFunction(p_op->info.join.right);
}
}


void execute(Operator* op, bool printColNames, void (*tupleHandler)(int pooloffset)) {
void execute(Operator* op, bool printColNames, void (*tupleHandler)(Tuple* tpl)) {

if (op == NULL) {
return;
}

buffpool = calloc(1, sizeof(Bufferpool));
buffpool->pool = calloc(BUFFERPOOLSIZE, 1);
buffpool->capacity = BUFFERPOOLSIZE;
buffpool->used = 0;

doAssignGetTupleFunction(op);

Expand All @@ -86,14 +82,15 @@ void execute(Operator* op, bool printColNames, void (*tupleHandler)(int pooloffs
}

// Get tuples one by one
int offset;
Tuple* tpl = initTupleOfSize(TUPLESIZE);
for (;;) {
offset = op->getTuple(op);
if (offset == -1) break;
op->getTuple(op, tpl);
if (isTupleEmpty(tpl)) break;

tupleHandler(tpl);

tupleHandler(offset);
};
freeTuple(tpl);


free(buffpool->pool);
free(buffpool);
}
69 changes: 69 additions & 0 deletions src/executor/statements/explain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "../../include/executor/executor.h"

void printOp(Operator* op) {

switch (op->type) {
case OP_SCANTDB:
printf("OP_SCANTDB");
break;
case OP_SCAN:
printf("OP_SCAN");
break;
case OP_PROJECT:
printf("OP_PROJECT");
break;
case OP_FILTER:
printf("OP_FILTER");
break;
case OP_JOIN:
printf("OP_JOIN");
break;
case OP_AGGREGATE:
printf("OP_AGGREGATE");
break;
case OP_HASHJOIN:
printf("OP_HASHJOIN");
break;
default:
printf("EXPLAIN-error: Unknown operation type");
break;
}

}

void explainOp(Operator* op) {

if (!op) return;

printOp(op);
printf("\n");

if (op->type == OP_FILTER) {
explainOp(op->info.filter.next);
}

if (op->type == OP_JOIN || op->type == OP_HASHJOIN) {
explainOp(op->info.join.filter);
explainOp(op->info.join.left);
explainOp(op->info.join.right);
}

if (op->child) {
explainOp(op->child);
}
}


void executeExplain(Node* node) {

/* Plan the query */
Operator* queryplan = planQuery(node->next);

/* Print the query plan */
printf("******* EXPLAIN **********\n");
explainOp(queryplan);
printf("**************************\n");

freeQueryplan(queryplan);
}

4 changes: 2 additions & 2 deletions src/executor/statements/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ size_t tupleSize = 0;
FILE* f = NULL;


void handleTupleInsert(int offset) {
void handleTupleInsert(Tuple* tpl) {

if (f == NULL) {
printf("No file to insert to\n");
exit(1);
}

size_t bytesWritten = fwrite(getTuple(offset), tupleSize, 1, f);
size_t bytesWritten = fwrite(tpl->data, tupleSize, 1, f);
assert(bytesWritten > 0);
}

Expand Down
36 changes: 36 additions & 0 deletions src/executor/tuple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "../include/executor/tuple.h"


Tuple* initTuple() {
Tuple* tpl = malloc(sizeof(Tuple));
tpl->size = 0;
return tpl;
}


Tuple* initTupleOfSize(size_t p_size) {
Tuple* tpl = malloc(sizeof(Tuple));
tpl->data = calloc(1, p_size);
tpl->size = p_size;
return tpl;
}


void* getTupleCol(Tuple* tpl, size_t colOffset) {
return tpl->data + colOffset;
}

void freeTuple(Tuple* tpl) {
if (tpl->data) {
free(tpl->data);
}
free(tpl);
}

size_t isTupleEmpty(Tuple* tpl) {
return tpl->size == 0 ? 1 : 0;
}

void markTupleAsEmpty(Tuple* tpl) {
tpl->size = 0;
}
Loading