Skip to content

Instantly share code, notes, and snippets.

@alphaCoder
Forked from kellabyte/DazzleBenchmark.cs
Created October 2, 2012 00:27
Show Gist options
  • Save alphaCoder/3815441 to your computer and use it in GitHub Desktop.
Save alphaCoder/3815441 to your computer and use it in GitHub Desktop.
// TRY HARD SHIT.
// I did and I'm learning a lot.
//
// 2 days ago I had no idea what I was doing but I decided I was going to create
// a database. I figured this would be a great way to learn even more about the
// databases I use today. I will write better software because I will know how they are
// designed and the optimizations and limitations they have to work with.
//
// After two days I have:
// - Modelled column based data model (like Cassandra) on top of a key/value store (SQLite4 does I think).
// - Created an inverted index stored in the key/value store for fast seeking at query time.
// - Parse an SQL-like query syntax into an AST (abstract syntax tree).
// - Process the AST to generate a query execution plan to compose a database operation.
// - Execute the operation and return results.
//
// I had no idea how to model a column based data model or how to use an AST.
// I didn't even know I needed them.
// I didn't think it would work. I got stuck. I asked for help. I kept trying.
//
// After 2 days this now works:
using System;
using Dazzle.Database;
using Dazzle.Database.Query;
namespace Dazzle.Benchmark.Embedded
{
class Program
{
static void Main(string[] args)
{
// The database is pre-loaded with 1 million rows each with 50 columns of gibberish data.
// This means 50+ million keys have been inserted into the key/value storage backend.
var db = new DazzleDatabase(path);
db.Open();
var result = db.ExecuteQuery("select * from users where userid = 'kelly900000'");
}
}
}
/*
OUTPUT
-------------------------------------
Rows: 1,000,000.00 Columns per row: 50 Total keys in DB: 50,000,000.00 DB Size: 2.36GB
Query: select * from users where userid = 'kelly900000'
Returned Rows: 1 Columns per row: 50
Query executed in 00:00:00.0035229
I can't believe this worked without any tuning in 3.5ms!
You can find Dazzle on GitHub here
https://github.com/kellabyte/Dazzle
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment