|
4 | 4 | </a>
|
5 | 5 | </p>
|
6 | 6 | <p align="center">
|
7 |
| - <strong>The Fastest Embedded Database in the world</strong> |
| 7 | + <strong>Super High-performance Embedded and Server RDBMS</strong> |
8 | 8 | </p>
|
9 | 9 |
|
10 |
| -## [CrossDB vs. SQLite3 Benchmark](https://crossdb.org/blog/benchmark/crossdb-vs-sqlite3/) |
| 10 | +> **NOTE** |
| 11 | +> This project was redesigned and rewritten from scratch. |
| 12 | +> It's still in early development stage, so please DO NOT use in your project now. |
11 | 13 |
|
12 |
| -<a href="https://crossdb.org/blog/benchmark/crossdb-vs-sqlite3/"> |
13 |
| -<img src="https://crossdb.org/images/benchmark/crossdb-vs-sqlite-ramdisk-large.png"> |
14 |
| -</a> |
| 14 | +# Introduction |
15 | 15 |
|
16 |
| -## [CrossDB vs. CPP STL Map Benchmark](https://crossdb.org/blog/benchmark/crossdb-vs-stlmap/) |
| 16 | +**CrossDB** is a super high-performance embedded and server RDBMS. |
| 17 | +It's developed for high performance scenarios with main memory can hold whole DB. |
17 | 18 |
|
18 |
| -<a href="https://crossdb.org/blog/benchmark/crossdb-vs-stlmap/"> |
19 |
| -<img src="https://crossdb.org/images/benchmark/crossdb-vs-stlmap-large.png"> |
20 |
| -</a> |
| 19 | +## Features |
21 | 20 |
|
22 |
| -## [CrossDB vs. CPP STL Hashmap Benchmark](https://crossdb.org/blog/benchmark/crossdb-vs-stlhmap/) |
| 21 | +- Support Multiple OS Platforms: Linux/Windows/MacOS/FreeBSD etc |
| 22 | +- Support Multiple CPU ARCH: X86/ARM/PPC/MIPS etc |
| 23 | +- Support OnDisk/In-memory/RamDisk/Hybrid Storage |
| 24 | +- Support Standard RDBMS model |
| 25 | +- Support MySQL like SQL |
| 26 | +- Support Multiple databases |
| 27 | +- Support Primary Key and multiple Secondary Indexes |
| 28 | +- Support HASH and RBTREE(TBD) Index |
| 29 | +- Support Multi-columns Index |
| 30 | +- Support Exact Match, Leftmost Match(TBD), Range Match(TBD) |
| 31 | +- Support Standard ACID Transaction (begin/commit/rollback) |
| 32 | +- Support WAL for OnDisk storage(TBD) |
| 33 | +- Support Multiple Threads and Multiple Processes Access |
| 34 | +- Support Table level read-write lock |
| 35 | +- Support Reader-Writer MVCC |
| 36 | +- Support Embedded CrossDB Shell |
| 37 | +- Support Multi-Statments APIs |
| 38 | +- Support Prepared Statments APIs |
| 39 | +- Super High Performance |
| 40 | +- Very Simple: Simple header and library file |
| 41 | +- Zero Config: no complex config, real out-of-the-box |
23 | 42 |
|
24 |
| -<a href="https://crossdb.org/blog/benchmark/crossdb-vs-stlhmap/"> |
25 |
| -<img src="https://crossdb.org/images/benchmark/crossdb-vs-stlhmap-large.png"> |
26 |
| -</a> |
| 43 | +## Use Cases |
27 | 44 |
|
28 |
| -## CrossDB CLI |
| 45 | +- You can use CrossDB In-Memory DB to manage Process Runtime Data to replace STL or hand-wrting data structures. |
| 46 | +- You can use CrossDB RamDisk DB to support Process Restartability, In-Service Software Upgrade(ISSU) easily. |
| 47 | +- You can use CrossDB OnDisk DB to store data on Disk/Flash/SDD. |
| 48 | +- You can use CrossDB to work as a super fast cache DB. |
29 | 49 |
|
30 |
| - |
| 50 | +## Build and Install |
31 | 51 |
|
32 |
| -## CrossDB Model |
| 52 | +make |
| 53 | +make install |
33 | 54 |
|
34 |
| - |
| 55 | +## Contribution |
| 56 | +In order to keep CrossDB quality and high-performance, this project does not |
| 57 | +accept patches. |
35 | 58 |
|
36 |
| -## Learn CrossDB in 5 Minutes |
| 59 | +If you would like to suggest a change and you include a patch as a proof-of- |
| 60 | +concept, that would be great. |
37 | 61 |
|
38 |
| -### 🛶 Define Schema |
| 62 | +However, please do not be offended if we rewrite your patch from scratch. |
39 | 63 |
|
40 |
| -``` c linenums="1" |
41 |
| -typedef struct { |
42 |
| - uint32_t prefix; |
43 |
| - uint8_t mask; |
44 |
| - uint32_t nexthop; |
45 |
| - uint8_t metric; |
46 |
| - char intf[16]; |
47 |
| - uint32_t birth; |
48 |
| - uint32_t flags; |
49 |
| -} route_t; |
| 64 | +Following contributions are welcome: |
50 | 65 |
|
51 |
| -#undef CROSS_STRUCT_NAME |
52 |
| -#define CROSS_STRUCT_NAME route_t |
53 |
| -cross_field_t route_schema[] = { |
54 |
| - CROSS_FIELD (prefix, UINT, IPv4, 0), |
55 |
| - CROSS_FIELD (mask, UINT, DFT, 0), |
56 |
| - CROSS_FIELD (nexthop, UINT, IPv4, 0), |
57 |
| - CROSS_FIELD (metric, UINT, DFT, 0), |
58 |
| - CROSS_FIELD (intf, CHAR, DFT, 0), |
59 |
| - CROSS_FIELD (birth, UINT, TS, 0), |
60 |
| - CROSS_FIELD (flags, UINT, HEX, 0), |
61 |
| - CROSS_END (route_t) |
62 |
| -}; |
63 |
| -``` |
64 |
| - |
65 |
| -### ⚙️ Create DB |
66 |
| - |
67 |
| -``` c linenums="1" |
68 |
| -#define CHECK(ret,str) if (ret < 0) { printf (str": %s\n", cross_errMsg(ret)); return -1; } |
69 |
| - |
70 |
| -cross_db_h hDb; |
71 |
| -cross_tbl_h hRtTbl; |
72 |
| -cross_ret ret; |
73 |
| -route_t route; |
74 |
| -cross_rowid count; |
75 |
| - |
76 |
| -// Create database |
77 |
| -ret = cross_dbCreate (&hDb, "db_data/example", 0); |
78 |
| -CHECK (ret, "Failed to create db: example"); |
79 |
| - |
80 |
| -// Create table: route (Primary Key: prefix,mask) |
81 |
| -ret = cross_dbTblCreate (hDb, &hRtTbl, "route", route_schema, "prefix,mask", 0); |
82 |
| -CHECK (ret, "Failed to create table: route table"); |
83 |
| - |
84 |
| -// Create index on nexthop: idx_nexthop |
85 |
| -ret = cross_dbIdxCreate (hRtTbl, "idx_nexthop", "nexthop", 0); |
86 |
| -CHECK (ret, "Failed to create index: idx_nexthop"); |
87 |
| -``` |
88 |
| -
|
89 |
| -### ⚜️ Insert Rows |
90 |
| -
|
91 |
| -``` c linenums="1" |
92 |
| -#define IP4ADDR(a,b,c,d) ((a)<<24|(b)<<16|(c)<<8|(d)) |
93 |
| -
|
94 |
| -// Insert route 192.168.1.0/24->192.168.1.254 |
95 |
| -route.prefix = IP4ADDR(192,168,1,0); |
96 |
| -route.mask = 24; |
97 |
| -route.nexthop = IP4ADDR(192,168,1,254); |
98 |
| -route.metric = 1; |
99 |
| -route.flags = 0; |
100 |
| -strcpy (route.intf, "eth1"); |
101 |
| -route.birth = time (NULL); |
102 |
| -ret = cross_dbInsertRow (hRtTbl, &route, 0); |
103 |
| -CHECK (ret, "Failed to insert route 192.168.1.0/24"); |
104 |
| -``` |
105 |
| - |
106 |
| -### 🚀 Query Rows |
107 |
| - |
108 |
| -``` c linenums="1" |
109 |
| -#define IP4STR(ip) ip>>24,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff |
110 |
| - |
111 |
| -// Get single route 192.168.1.0/24 by Primary Key |
112 |
| -route.prefix = IP4ADDR(192,168,1,0); |
113 |
| -route.mask = 24; |
114 |
| -ret = cross_dbGetRowByPK (hRtTbl, &route, &route, 0); |
115 |
| -CHECK (ret, "Failed to get route 192.168.1.0/24 by Primary Key"); |
116 |
| -printf ("Get single route: %d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n", |
117 |
| - IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags); |
118 |
| - |
119 |
| -// Get one row where nexthop=192.168.1.254 |
120 |
| -route.nexthop = IP4ADDR(192,168,1,254); |
121 |
| -ret = cross_dbGetOneRow (hRtTbl, "nexthop", &route, &route, 0); |
122 |
| -CHECK (ret, "Failed to get one route where nexthop=192.168.1.254"); |
123 |
| -printf ("Get one route where nexthop=192.168.1.254: " |
124 |
| - "%d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n", |
125 |
| - IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags); |
126 |
| -``` |
127 |
| -
|
128 |
| -## 🔫 Update Rows |
129 |
| -
|
130 |
| -``` c linenums="1" |
131 |
| -// Update single route 192.168.1.0/24 by Primary Key: set flags 0->1 metric 1->3 |
132 |
| -route.prefix = IP4ADDR(192,168,1,0); |
133 |
| -route.mask = 24; |
134 |
| -route.metric = 3; |
135 |
| -route.flags = 1; |
136 |
| -ret = cross_dbUpdRowByPK (hRtTbl, &route, "flags,metric", &route, 0); |
137 |
| -CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key"); |
138 |
| -
|
139 |
| -// Update routes where nexthop=192.168.1.254: set flags 0->3 |
140 |
| -route.nexthop = IP4ADDR(192,168,1,254); |
141 |
| -route.flags = 3; |
142 |
| -count = cross_dbUpdateRows (hRtTbl, "nexthop", &route, "flags", &route, 0); |
143 |
| -printf ("Update %d routes where nexthop=10.1.2.254\n", count); |
144 |
| -``` |
145 |
| - |
146 |
| -## 🎡 Cursor Query |
147 |
| - |
148 |
| -``` c linenums="1" |
149 |
| -// Use cursor to get routes where nexthop=192.168.1.254 |
150 |
| -cross_cursor_h hCursor; |
151 |
| -route.nexthop = IP4ADDR(192,168,1,254); |
152 |
| -count = cross_dbQueryRows (hRtTbl, &hCursor, "nexthop", &route, 0); |
153 |
| -printf ("Query %d routes where nexthop=192.168.1.254\n", count); |
154 |
| -while (CROSS_OK == cross_cursorGetNextRow (hCursor, &route, 0)) { |
155 |
| - printf (" route: %d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n", |
156 |
| - IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags); |
157 |
| -} |
158 |
| -cross_cursorClose (hCursor, 0); |
159 |
| -``` |
160 |
| -
|
161 |
| -## ✂️ Delete Rows |
162 |
| -
|
163 |
| -``` c linenums="1" |
164 |
| -// Delete single route 192.168.1.0/24 by Primary Key |
165 |
| -route.prefix = IP4ADDR(192,168,1,0); |
166 |
| -route.mask = 24; |
167 |
| -ret = cross_dbDelRowByPK (hRtTbl, &route, 0); |
168 |
| -CHECK (ret, "Failed to delete route 192.168.1.0/24 by Primary Key"); |
169 |
| -
|
170 |
| -// Delete routes where nexthop=192.168.1.254 |
171 |
| -route.nexthop = IP4ADDR(192,168,1,254); |
172 |
| -count = cross_dbDeleteRows (hRtTbl, "nexthop", &route, 0); |
173 |
| -printf ("Delete %d routes where nexthop=192.168.1.254\n", count); |
174 |
| -``` |
175 |
| - |
176 |
| -## 🌄 Transaction |
177 |
| - |
178 |
| -``` c linenums="1" |
179 |
| -ret = cross_dbTransBegin (hDb, 0); |
180 |
| -CHECK (ret, "Failed to begin transaction"); |
181 |
| -// Update single route 192.168.1.0/24 by Primary Key: set flags 0->5 |
182 |
| -route.prefix = IP4ADDR(192,168,1,0); |
183 |
| -route.mask = 24; |
184 |
| -route.flags = 5; |
185 |
| -ret = cross_dbUpdRowByPK (hRtTbl, &route, "flags", &route, 0); |
186 |
| -CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key"); |
187 |
| -ret = cross_dbTransCommit (hDb, 0); |
188 |
| -CHECK (ret, "Failed to commit transaction"); |
189 |
| -``` |
| 66 | +- Language bindings: `Python`, `Java`, `Go`, `CSharp`, `Javascript`, `PHP`, etc |
| 67 | +- Test and report bugs |
190 | 68 |
|
191 | 69 | ## Want to Lean More?
|
192 |
| -https://crossdb.org |
| 70 | +https://crossdb.org |
0 commit comments