# BeeDB 

BeeDB is a software project that teaches students the architecture and implementation of DataBase Management Systems.
This project is related to the Basic Module *Architecture & Implementation of DBMS*. The course is usually teached every summer term, see [dbis page of TU Dortmund](http://dbis.cs.tu-dortmund.de/cms/en/teaching/index.html) for more information.

**Attention: Please do not publish and share your solution with other students!**

## Dependencies
* `git`
* `cmake` (at least version `3.9`)
* `build-essential`
* `bison` and `flex` 

## How to build
  * `cmake .`
  * `make`
  
**OR**, if you prefer a separate `build` folder:

  * `mkdir build && cd build`
  * `cmake ..`
  * `make`
  
Default build is in `Debug` mode.
If you want to build in `Release` mode use `cmake . -DCMAKE_BUILD_TYPE=Release` or set `CMAKE_BUILD_TYPE` in `CMakeLists.txt`.
  
## How to use

    Usage: beedb [options] db-file
    Positional arguments:
    db-file                 	File the database is stored in. Default: bee.db
    Optional arguments:
    -h --help               	show this help message and exit
    -l --load               	Load SQL file into database.
    -q --query              	Execute Query.
    -c --console            	Run console after loading file or executing query.
    --buffer-manager-frames 	Number of frames within the frame buffer.
    --scan-page-limit       	Number of pages the SCAN operator can pin at a time.
    --enable-index-scan     	Enable index scan and use whenever possible.
    --enable-hash-join      	Enable hash join and use whenever possible.
    --stats                 	Print all execution statistics

## Configuration
Some configuration outside the console arguments is stored in the file `beedb.ini`.
* The number of pages stored as frames in the buffer manager (`buffer manager.frames`)
* The replacement strategy of frames in the buffer manager (`buffer manager.strategy`)
* The `k` parameter for `LRU-K` replacement strategy (`buffer manager.k`)
* The number of how many pages can be pinned by a scan at a time (`scan.page-limit`)
* Enable or disable usage of index scan (`scan.enable-index-scan`)
* Enable or disable usage of hash join (`join.enable-hash-join`)

## Non-SQL Commands

* `:explain [plan,graph]`: Prints the query plan, either as a table or graph (a list of nodes and edges).
* `:get [option-name]`: Prints either all (when no additional argument is given) or the specified option of the database configuration.
* `:set option-name numerical-value`: Changes the specified option. Only numerical values are valid.
* `:show [tables,indices,columns]`: A quick way to show available tables, their columns or indices.

## Examples

##### Import
`./beedb -l movies.sql`

##### Run a single query
`./beedb -q "SELECT * FROM movie"`

##### Open the BeeDB Console
`./beedb`

##### Run a query and open console afterwards
`./beedb -q "SELECT * FROM movie" -c`

# For developers
* If you want to commit to the repository please `make git-hook` before commit.
  
# Credits
* Thanks to Hyrise for the SQL parser (MIT, [See on GitHub](https://github.com/hyrise/sql-parser))
* Thanks to p-ranav for argparse (MIT, [See on GitHub](https://github.com/p-ranav/argparse))