Live data from Hacker News

Writing a SQL database from scratch in Go

notes.eatonphil.com

51–55 of 55 posts

Re: Writing a SQL database from scratch in Go

#51

Curious - would Rust be more appropriate than Go for such a task?

rust would be more appropriate if your intention was to use this in production. Databases ad GC don't mix well. (its done but it makes tuning a nightmare) As much as I love rust, its learning curve is high and I'm sure Op doesn't want to spend half his article teaching all the intricacies of types and the borrow checker. Go is easy to learn over a weekend so its probably a better medium for illustrating the concepts…

A garbage collector is not inherently incompatible with a low-latency database. I was generally very happy with the performance of Go's garbage collector enough to have built Prometheus, the time series database, on it back in 2012, when the collector was considerably more naive.

https://blog.golang.org/ismmkeynote

Re: Writing a SQL database from scratch in Go

#52

Earlier quoted context omitted.

Having standards like that and keeping them helps a lot. Next time you have a different keyword, you don't have to think "does it deserve a constant?" - all of them do. Similar to how linters stop you from overthinking indentation in specific cases, or some naming standards, and later rename/reformat-wars.

all of them do. That's what leads to dogmatic cargo-culting. Good software is written by thinking about the circumstances and doing what makes the most sense, not by mindless rule-following that don't always make sense. I don't know why someone would be so worried about typos and introduce more verbosity and redundancy in the process; but then again, I don't use an IDE and I've never had this problem.

I'm not sure you're really making the argument you think here...

Good software may mean thinking about circumstances like "we're dealing with lots of text parsing and have seen bugs from typos in common keywords" and doing what makes most sense: "let's prevent those in the future, but using constants for keywords". It's only cargo culting if you don't know why you're doing something.

Setting a rule so you don't have to debate something later is a valid solution and may still offset some redundancies introduced this way.

Re: Writing a SQL database from scratch in Go

#54
post #27

Earlier quoted context omitted.

Golang works too. There is a few databases written in Golang, such as Prometheus, InfluxDB, CockroachDB, or tidb. https://github.com/topics/database?l=go&o=desc&s=stars

Note that neither CockroachDB or TiDB use Golang for their actual storage engine, which is in both cases written in C (RocksDB). They do use Golang for SQL parsing though, which is what this post was mostly about.

VictoriaMetrics [1] is written entirely in Go. By default it uses canonical zstd library for compression (the library is written in C), but it supports pure Go mode when built with `make victoria-metrics-pure`. In this mode it uses zstd implementation written in Go [2].

[1] https://github.com/VictoriaMetrics/VictoriaMetrics

[2] https://github.com/klauspost/compress/tree/master/zstd#zstd

Re: Writing a SQL database from scratch in Go

#55
post #53
post #49

Do you know about a tutorial or a book that helps write Database from scratch either in Java or C?

Check out this (in C): https://cstack.github.io/db_tutorial/ also a list here https://github.com/danistefanovic/build-your-own-x

Thanks!
Post reply on HN