A simple SQL database implemented in Golang, supporting transactions and MVCC (Multi-Version Concurrency Control) features. The storage layer uses a KV storage engine based on the BitCask model.
- Go 1.23 or higher
- Terminal/Command line tool
Navigate to the project bin directory and start the SQL server:
cd bin
go run server.go model.go -d /path/to/data -p 8888Parameters:
-d: Data storage path (e.g.,./dataor/tmp/trainsql)-p: Server port number (default: 8888)
Open a new terminal window and start the client:
cd bin
go run client.go model.go -s 127.0.0.1:8888Parameters:
-s: Server address (format:IP:Port)
After successful connection, you can execute the following example commands:
-- Create three test tables
CREATE TABLE haj1 (a INT PRIMARY KEY);
CREATE TABLE haj2 (b INT PRIMARY KEY);
CREATE TABLE haj3 (c INT PRIMARY KEY);-- Insert test data into tables
INSERT INTO haj1 VALUES (1), (2), (3);
INSERT INTO haj2 VALUES (2), (3), (4);
INSERT INTO haj3 VALUES (3), (1), (9);-- Multi-table JOIN query
SELECT * FROM haj1
JOIN haj2 ON a = b
JOIN haj3 ON a = c;Expected Result:
a | b | c
--+---+--
3 | 3 | 3
-- View SQL execution plan (for performance analysis)
EXPLAIN SELECT * FROM haj1
JOIN haj2 ON a = b
JOIN haj3 ON a = c;-- Manual transaction control
BEGIN;
INSERT INTO haj1 VALUES (10);
COMMIT;
-- Transaction rollback
BEGIN;
DELETE FROM haj1 WHERE a = 10;
ROLLBACK;-- Create table with index
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR NOT NULL,
age INT INDEX
);
-- Query using index
SELECT * FROM users WHERE age = 25;-- GROUP BY and aggregate functions
SELECT age, COUNT(id), AVG(age)
FROM users
GROUP BY age
HAVING COUNT(id) > 1;| Issue | Solution |
|---|---|
| Port in use | Change -p parameter to use another port |
| Connection failed | Check if server is running, firewall settings |
| Data loss | Ensure -d path has write permission |
- ✅ DDL:
CREATE TABLE,DROP TABLE - ✅ DML:
INSERT,UPDATE,DELETE,SELECT - ✅ JOIN:
INNER JOIN,LEFT JOIN,RIGHT JOIN,CROSS JOIN - ✅ Aggregation:
COUNT,SUM,AVG,MAX,MIN - ✅ Clauses:
WHERE,GROUP BY,HAVING,ORDER BY,LIMIT,OFFSET - ✅ Transaction:
BEGIN,COMMIT,ROLLBACK - ✅ Others:
EXPLAIN,SHOW TABLE,SHOW DATABASE
The following are known limitations and features to be implemented in the current version
| Limitation | Description | Example |
|---|---|---|
| Table qualifier | JOIN ON conditions do not support table.column format |
❌ ON users.id = orders.user_id |
| Constant comparison | ON conditions do not support comparison with constants | ❌ ON users.id = 3 |
| Comparison operators | WHERE only supports =, >, <, not >=, <=, != |
❌ WHERE id >= 11 |
| Limitation | Description |
|---|---|
| STRING length | No maximum length limit for STRING/VARCHAR types |
| Limitation | Description |
|---|---|
| Range query | Range queries using > or < degrade to full table scan, cannot utilize index |
| Lock granularity | Only supports transaction-level concurrency control, no fine-grained row-level locks |
| Limitation | Description |
|---|---|
| Crash recovery | When uncommitted transactions exist during abnormal database shutdown, intermediate state data of uncommitted transactions is not automatically cleaned up after restart |
- Support table qualifiers (
table.column) - Support
>=,<=,!=,<>comparison operators - Support
ORlogical operator - Support
IN,LIKEoperators - Implement index optimization for range queries
- Optimizer, query tree efficiency analysis
- Add VARCHAR type length constraints
- Use B+Tree as storage engine
- Implement row-level locks