Skip to content

Commit 54fda38

Browse files
committed
Deliver 0.7.0
1 parent a331dd1 commit 54fda38

39 files changed

+1881
-522
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Change Log
22

3+
## 0.7.0 <small>(2024-08-26)</small>
4+
5+
**Features**
6+
7+
- `UPDATE` SET clause supports simple expression, ex: `SET val=val+5` `SET val=a-b`
8+
- `UPDATE` SET supports prepared statement
9+
- `INSERT` supports prepared statement
10+
- New APIs: `xdb_bexec`, `xdb_vbexec`, `xdb_stmt_bexec`, `xdb_stmt_vexec`, `xdb_clear_bindings`
11+
12+
**Improvements**
13+
14+
- `INSERT` parser avoids malloc
15+
- `UPDATE` only updates affected indexes
16+
- Optimize `INSERT` `UPDATE` `DELETE` auto-commit performance for `IMDB`
17+
18+
**Test**
19+
20+
- Improve benchmark test
21+
- Add `SQLite` benchmark test
22+
23+
**Bug Fixes**
24+
25+
- Fix hash index infinite loop issue
26+
- Fix bench test time unit `ns` to `us`
27+
28+
329
## 0.6.0 <small>(2024-08-15)</small>
430

531
- **Initial refactor release**

Makefile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,34 @@ help:
55
@echo "make clean Clean build result"
66
@echo "make install Install crossdb(lib&tool&header) to Linux/FreeBSD"
77
@echo "make uninstall Uninstall crossdb from Linux/FreeBSD"
8-
@echo "make installmacos Install crossdb(lib&tool&header) to MacOS"
9-
@echo "make uninstallmacos Uninstall crossdb from MacOS"
8+
@echo "make installmac Install crossdb(lib&tool&header) to MacOS"
9+
@echo "make uninstallmac Uninstall crossdb from MacOS"
1010
@echo "make example Build and run example (need to install crossdb first)"
1111
@echo "make bench Build and run bench test (need to install crossdb first)"
12+
@echo "make bench-sqlite Build and run sqlite bench test (need to install sqlite3 first)"
1213

1314
.PHONY: build
1415
build:
1516
mkdir -p build
1617
$(CC) -o build/libcrossdb.so -fPIC -shared -lpthread -O2 src/crossdb.c
1718
$(CC) -o build/crossdb src/main.c -lpthread -O2
18-
cp src/crossdb.h build/
19+
cp include/crossdb.h build/
1920

2021
debug:
2122
$(CC) -o build/libcrossdb.so -fPIC -lpthread -shared -g src/crossdb.c
2223
$(CC) -o build/crossdb src/main.c -lpthread -g
23-
cp src/crossdb.h build/
24+
cp include/crossdb.h build/
2425

2526
run:
2627
build/crossdb
2728

2829
clean:
2930
rm -rf build/*
3031
make -C examples/c/ clean
31-
make -C bench/c/ clean
32+
make -C bench/basic/ clean
3233

3334
wall:
34-
$(CC) -o build/libcrossdb.so -fPIC -shared -lpthread -O2 -Wall src/crossdb.c
3535
$(CC) -o build/crossdb src/main.c -lpthread -O2 -Wall
36-
cp src/crossdb.h build/
3736

3837
gdb:
3938
$(CC) -o build/crossdb src/main.c -lpthread -g
@@ -49,13 +48,13 @@ uninstall:
4948
rm -rf /usr/include/crossdb.h
5049
rm -rf /usr/bin/crossdb
5150

52-
installmacos:
51+
installmac:
5352
$(CC) -o build/libcrossdb.so -dynamiclib -lpthread -O2 src/crossdb.c
5453
install -c build/libcrossdb.so /usr/local/lib/
5554
install -c build/crossdb.h /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
5655
install -c build/crossdb /usr/local/bin/
5756

58-
uninstallmacos:
57+
uninstallmac:
5958
rm -rf /usr/local/lib/libcrossdb.so
6059
rm -rf /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/crossdb.h
6160
rm -rf /usr/local/bin/crossdb
@@ -65,4 +64,7 @@ example:
6564

6665
.PHONY: bench
6766
bench:
68-
make -C bench/c/
67+
make -C bench/basic/
68+
69+
bench-sqlite:
70+
make -C bench/basic/ sqlite

README.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
</a>
55
</p>
66
<p align="center">
7-
<strong>Super High-performance Embedded and Server RDBMS</strong>
7+
<strong>Super High-performance Lightweight Embedded and Server OLTP RDBMS</strong>
88
</p>
99

1010
> **NOTE**
1111
> This project was redesigned and rewritten from scratch.
1212
> It's still in early development stage, so please DO NOT use in your project now.
1313
14-
# Introduction
15-
16-
**CrossDB** is a super high-performance lightweight embedded and server SQL RDBMS.
14+
**CrossDB** is a super high-performance lightweight embedded and server OLTP RDBMS.
1715
It's developed for high performance scenarios with main memory can hold whole DB.
1816

17+
1918
## Features
2019

2120
- Support Multiple OS Platforms: Linux/Windows/MacOS/FreeBSD etc
2221
- Support Multiple CPU ARCH: X86/ARM/PPC/MIPS etc
23-
- Support OnDisk/In-memory/RamDisk/Hybrid Storage
22+
- Support OnDisk/In-memory(IMDB)/RamDisk/Hybrid Storage
2423
- Support Standard RDBMS model
2524
- Support Standard SQL and many extensions from MySQL
2625
- Support Multiple databases
@@ -41,6 +40,7 @@ It's developed for high performance scenarios with main memory can hold whole DB
4140
- Very Simple: Simple header and library file
4241
- Zero Config: no complex config, real out-of-the-box
4342

43+
4444
## Use Cases
4545

4646
- High-frenquency trade (OLTP)
@@ -50,6 +50,7 @@ It's developed for high performance scenarios with main memory can hold whole DB
5050
- You can use CrossDB RamDisk DB to support Process Restartability, In-Service Software Upgrade(ISSU) easily.
5151
- You can use CrossDB to work as a super fast cache DB.
5252

53+
5354
## Build and Install
5455

5556
### Linux/FreeBSD
@@ -63,7 +64,7 @@ sudo make install
6364

6465
```bash
6566
make build
66-
sudo make installmacos
67+
sudo make installmac
6768
```
6869

6970
### Windows
@@ -72,7 +73,7 @@ You need to install [MINGW64](https://www.mingw-w64.org/) to build.
7273
Then set `gcc` path to `system environment variables` `Path` and make sure `gcc` can run.
7374

7475
```
75-
build.bat
76+
winbuild.bat
7677
```
7778

7879
## Contribution
@@ -82,5 +83,17 @@ Following contributions are welcome:
8283
- Language bindings: `Python`, `Java`, `Go`, `CSharp`, `Javascript`, `PHP`, etc
8384
- Test and report bugs
8485

85-
## Want to Lean More?
86-
https://crossdb.org
86+
87+
## Reference
88+
89+
### SQL Statements
90+
91+
https://crossdb.org/sql/statements/
92+
93+
### APIs
94+
95+
https://crossdb.org/client/api-c/
96+
97+
### Tutorial
98+
99+
https://crossdb.org/get-started/tutorial/

bench/basic/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
all:
2+
$(CC) -o bench-crossdb bench-crossdb.c -O2 -lcrossdb -lpthread
3+
./bench-crossdb
4+
5+
debug:
6+
$(CC) -o bench-crossdb bench-crossdb.c ../../src/crossdb.c -g -fsanitize=address
7+
./bench-crossdb
8+
9+
sqlite:
10+
$(CC) -o bench-sqlite bench-sqlite.c -O2 -lsqlite3
11+
./bench-sqlite
12+
13+
fast:
14+
$(CC) -o bench-crossdb bench-crossdb.c ../../src/crossdb.c -O3 -march=native
15+
./bench-crossdb
16+
17+
clean:
18+
rm -f a.out bench-crossdb bench-sqlite

bench/basic/bench-crossdb.c

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
2+
#define BENCH_DBNAME "CrossDB"
3+
4+
#define LKUP_COUNT 10000000
5+
#define SQL_LKUP_COUNT LKUP_COUNT/5
6+
#define UPD_COUNT LKUP_COUNT/10
7+
8+
#include "bench.h"
9+
#include <crossdb.h>
10+
11+
void* bench_create ()
12+
{
13+
xdb_conn_t* pConn = xdb_open (":memory:");
14+
XDB_CHECK (NULL != pConn, printf ("Can't open connection:\n"); return NULL;);
15+
16+
xdb_res_t* pRes = xdb_exec (pConn, "CREATE TABLE student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score INT)");
17+
XDB_RESCHK (pRes, printf ("Can't create table student\n"); xdb_close(pConn); return NULL;);
18+
19+
return pConn;
20+
}
21+
22+
void bench_close (void *pConn)
23+
{
24+
xdb_close (pConn);
25+
}
26+
27+
void bench_sql_test (void *pConn, int STU_COUNT, bool bRand, bench_result_t *pResult)
28+
{
29+
xdb_res_t* pRes;
30+
xdb_row_t *pRow;
31+
32+
bench_print ("\n[============= SQL Test =============]\n\n");
33+
34+
35+
bench_print ("------------ INSERT %d ------------\n", STU_COUNT);
36+
bench_ts_beg();
37+
for (int i = 0; i < STU_COUNT; ++i) {
38+
pRes = xdb_bexec (pConn, "INSERT INTO student (id,name,age,class,score) VALUES (?,?,?,?,?)",
39+
i, STU_NAME(i), STU_AGE(i), STU_CLASS(i), STU_SCORE(i));
40+
XDB_RESCHK (pRes, bench_print ("Can't insert table student id=%d\n", i); return;);
41+
}
42+
pResult->insert_qps += bench_ts_end (STU_COUNT);
43+
44+
45+
bench_print ("------------ %s LKUP %d ------------\n", ORDER_STR(bRand), SQL_LKUP_COUNT);
46+
uint64_t qps_sum = 0;
47+
for (int t = 0; t < 5; ++t) {
48+
int count = 0;
49+
bench_ts_beg();
50+
for (int i = 0; i < SQL_LKUP_COUNT; ++i) {
51+
pRes = xdb_bexec (pConn, "SELECT * FROM student WHERE id=?", STU_ID(i));
52+
pRow = xdb_fetch_row (pRes);
53+
if (NULL != pRow) {
54+
int id = *(int*)pRow[0];
55+
const char *name = (char*)pRow[1];
56+
int age = *(int*)pRow[2];
57+
const char *class = (char*)pRow[3];
58+
int score = *(int*)pRow[4];
59+
(void)id; (void)name; (void)age; (void)class; (void)score;
60+
count++;
61+
}
62+
xdb_free_result (pRes);
63+
}
64+
qps_sum += bench_ts_end (SQL_LKUP_COUNT);
65+
XDB_CHECK (count == SQL_LKUP_COUNT, bench_print ("OK %d != LKUP %d\n", count, SQL_LKUP_COUNT););
66+
}
67+
pResult->query_qps += qps_sum / 5;
68+
69+
70+
bench_print ("------------ %s UPDATE %d ------------\n", ORDER_STR(bRand), UPD_COUNT);
71+
bench_ts_beg();
72+
for (int i = 0; i < UPD_COUNT; ++i) {
73+
pRes = xdb_bexec (pConn, "UPDATE student SET age=age+? WHERE id=?", 1, STU_ID(i));
74+
XDB_RESCHK (pRes, bench_print ("Can't update table student id%d\n", STU_ID(i)); return;);
75+
}
76+
pResult->update_qps += bench_ts_end (UPD_COUNT);
77+
78+
79+
bench_print ("------------ %s DELETE %d ------------\n", ORDER_STR(bRand), STU_COUNT);
80+
bench_ts_beg();
81+
for (int i = 0; i < STU_COUNT; ++i) {
82+
pRes = xdb_bexec (pConn, "DELETE FROM student WHERE id=?", STU_ID(i));
83+
XDB_RESCHK (pRes, bench_print ("Can't delete table student id=%d\n", STU_ID(i)); return;);
84+
}
85+
pResult->delete_qps += bench_ts_end (STU_COUNT);
86+
}
87+
88+
void bench_pstmt_test (void *pConn, int STU_COUNT, bool bRand, bench_result_t *pResult)
89+
{
90+
xdb_res_t* pRes;
91+
xdb_row_t *pRow;
92+
xdb_stmt_t *pStmt = NULL;
93+
94+
bench_print ("\n[============= Prepared STMT Test =============]\n");
95+
96+
97+
bench_print ("\n------------ INSERT %d ------------\n", STU_COUNT);
98+
pStmt = xdb_stmt_prepare (pConn, "INSERT INTO student (id,name,age,class,score) VALUES (?,?,?,?,?)");
99+
bench_ts_beg();
100+
for (int i = 0; i < STU_COUNT; ++i) {
101+
pRes = xdb_stmt_bexec (pStmt, i, STU_NAME(i), STU_AGE(i), STU_CLASS(i), STU_SCORE(i));
102+
XDB_RESCHK (pRes, bench_print ("Can't insert table student id%d\n", i); goto error;);
103+
}
104+
pResult->insert_qps += bench_ts_end (STU_COUNT);
105+
xdb_stmt_close (pStmt);
106+
107+
108+
bench_print ("------------ %s LKUP %d ------------\n", ORDER_STR(bRand), LKUP_COUNT);
109+
pStmt = xdb_stmt_prepare (pConn, "SELECT * FROM student WHERE id=?");
110+
XDB_CHECK (pStmt != NULL, goto error);
111+
uint64_t qps_sum = 0;
112+
for (int t = 0; t < 5; ++t) {
113+
int count = 0;
114+
bench_ts_beg();
115+
for (int i = 0; i < LKUP_COUNT; ++i) {
116+
pRes = xdb_stmt_bexec (pStmt, STU_ID(i));
117+
pRow = xdb_fetch_row (pRes);
118+
if (NULL != pRow) {
119+
int id = *(int*)pRow[0];
120+
const char *name = (char*)pRow[1];
121+
int age = *(int*)pRow[2];
122+
const char *class = (char*)pRow[3];
123+
int score = *(int*)pRow[4];
124+
(void)id; (void)name; (void)age; (void)class; (void)score;
125+
count++;
126+
}
127+
xdb_free_result (pRes);
128+
}
129+
qps_sum += bench_ts_end (LKUP_COUNT);
130+
XDB_CHECK (count == LKUP_COUNT, bench_print ("OK %d != LKUP %d\n", count, LKUP_COUNT););
131+
}
132+
xdb_stmt_close (pStmt);
133+
pResult->query_qps += qps_sum / 5;
134+
135+
136+
bench_print ("------------ %s UPDATE %d ------------\n", ORDER_STR(bRand), UPD_COUNT);
137+
pStmt = xdb_stmt_prepare (pConn, "UPDATE student SET age=age+? WHERE id=?");
138+
XDB_CHECK (pStmt != NULL, goto error);
139+
bench_ts_beg();
140+
for (int i = 0; i < UPD_COUNT; ++i) {
141+
pRes = xdb_stmt_bexec (pStmt, 1, STU_ID(i));
142+
XDB_RESCHK (pRes, bench_print ("Can't update table student id%d\n", STU_ID(i)); goto error;);
143+
}
144+
pResult->update_qps = bench_ts_end (UPD_COUNT);
145+
xdb_stmt_close (pStmt);
146+
147+
148+
bench_print ("------------ %s DELETE %d ------------\n", ORDER_STR(bRand), STU_COUNT);
149+
pStmt = xdb_stmt_prepare (pConn, "DELETE FROM student WHERE id=?");
150+
XDB_CHECK (pStmt != NULL, goto error);
151+
bench_ts_beg();
152+
for (int i = 0; i < STU_COUNT; ++i) {
153+
pRes = xdb_stmt_bexec (pStmt, STU_ID(i));
154+
XDB_RESCHK (pRes, bench_print ("Can't delete table student id%d\n", STU_ID(i)); goto error;);
155+
}
156+
pResult->delete_qps += bench_ts_end (STU_COUNT);
157+
158+
error:
159+
xdb_stmt_close (pStmt);
160+
}

0 commit comments

Comments
 (0)