From f3c3a817fa897a0e743a9652a47a909d4b4b54b5 Mon Sep 17 00:00:00 2001 From: JC Wang Date: Mon, 19 Aug 2024 23:36:54 +0800 Subject: [PATCH] Deployed c12eebe with MkDocs version: 1.6.0 --- 404.html | 2 +- CHANGELOG/index.html | 2 +- about/buy/index.html | 2 +- about/privacy/index.html | 2 +- about/refund/index.html | 2 +- about/terms/index.html | 2 +- admin/data-backup/index.html | 2 +- admin/data-restore/index.html | 2 +- admin/shell/index.html | 8 +- client/api-c/index.html | 12 +- client/api-python/index.html | 2 +- community/index.html | 2 +- develop/connect/index.html | 7 +- develop/ddl/index.html | 6 +- develop/dml/index.html | 23 +++- develop/multi-stmts/index.html | 19 ++- develop/prep-stmts/index.html | 36 +++++- develop/query/index.html | 45 ++++--- develop/transaction/index.html | 22 +++- faq/index.html | 2 +- get-started/bench/index.html | 145 ++++++++--------------- get-started/install/index.html | 10 +- get-started/tutorial/index.html | 103 ++++++++-------- glossary/index.html | 2 +- index.html | 2 +- intro/index.html | 2 +- replication/logic-replication/index.html | 51 -------- replication/pubsub/index.html | 56 --------- replication/replication/index.html | 66 ----------- search/search_index.json | 2 +- server/server/index.html | 50 -------- server/status/index.html | 33 ------ sitemap.xml | 103 ++++++---------- sitemap.xml.gz | Bin 531 -> 493 bytes sql/backup/index.html | 2 +- sql/data-types/index.html | 2 +- sql/database/index.html | 2 +- sql/dml/index.html | 2 +- sql/functions/index.html | 2 +- sql/indexes/index.html | 4 +- sql/misc/index.html | 2 +- sql/name-limit/index.html | 2 +- sql/operators/index.html | 2 +- sql/statements/index.html | 2 +- sql/table/index.html | 2 +- sql/transaction/index.html | 4 +- sysdb/information-schema/index.html | 2 +- sysdb/system/index.html | 2 +- 48 files changed, 322 insertions(+), 535 deletions(-) delete mode 100755 replication/logic-replication/index.html delete mode 100755 replication/pubsub/index.html delete mode 100755 replication/replication/index.html delete mode 100755 server/server/index.html delete mode 100755 server/status/index.html diff --git a/404.html b/404.html index 19b8350..cbcd359 100755 --- a/404.html +++ b/404.html @@ -1 +1 @@ - CrossDB
\ No newline at end of file + CrossDB
\ No newline at end of file diff --git a/CHANGELOG/index.html b/CHANGELOG/index.html index ca83ed3..19528e4 100755 --- a/CHANGELOG/index.html +++ b/CHANGELOG/index.html @@ -1 +1 @@ - Change Log - CrossDB
Skip to content

Change Log

0.6.0 (2024-08-18)

  • Initial refactor release

  • This project was redesigned and rewritten from scratch for over one year

  • Standard RDBMS model
  • New SQL APIs which can support more language
  • MySQL style SQL and shell, which will be easy to study.

0.5.0 (2023-06-26)

Features

  • CrossDB command line tool crossdb-cli is released
  • Optimize insert/update/query/delete performance
  • Add new API cross_matchCreate and cross_matchFree
  • DML APIs supports cross_fields_h and cross_match_h

Bug Fixes

0.4.0 (2023-06-20)

Features

  • Support FreeBSD(X64)
  • Optimize insert/update/query/delete performance
  • Add new API cross_fieldsCreate and cross_fieldsFree

Bug Fixes

0.3.0 (2023-06-13)

Features

  • Support MacOS (X64 and ARM64)
  • Change CROSS_DB_XXX to CROSS_XXX

Bug Fixes

  • cross_dbTblCreate flags CROSS_DB_RBTREE doesn't create Primary Key Index type correctly

0.2.0 (2023-06-07)

Features

  • Support Windows
  • Support Linux ARM64

Bug Fixes

0.1.0 (2023-06-03)

  • Initial release

Features

Bug Fixes

\ No newline at end of file + Change Log - CrossDB
Skip to content

Change Log

0.6.0 (2024-08-18)

  • Initial refactor release

  • This project was redesigned and rewritten from scratch for over one year

  • Standard RDBMS model
  • New SQL APIs which can support more language
  • MySQL style SQL and shell, which will be easy to study.

0.5.0 (2023-06-26)

Features

  • CrossDB command line tool crossdb-cli is released
  • Optimize insert/update/query/delete performance
  • Add new API cross_matchCreate and cross_matchFree
  • DML APIs supports cross_fields_h and cross_match_h

Bug Fixes

0.4.0 (2023-06-20)

Features

  • Support FreeBSD(X64)
  • Optimize insert/update/query/delete performance
  • Add new API cross_fieldsCreate and cross_fieldsFree

Bug Fixes

0.3.0 (2023-06-13)

Features

  • Support MacOS (X64 and ARM64)
  • Change CROSS_DB_XXX to CROSS_XXX

Bug Fixes

  • cross_dbTblCreate flags CROSS_DB_RBTREE doesn't create Primary Key Index type correctly

0.2.0 (2023-06-07)

Features

  • Support Windows
  • Support Linux ARM64

Bug Fixes

0.1.0 (2023-06-03)

  • Initial release

Features

Bug Fixes

\ No newline at end of file diff --git a/about/buy/index.html b/about/buy/index.html index 45b2eb0..3c949b0 100755 --- a/about/buy/index.html +++ b/about/buy/index.html @@ -1,4 +1,4 @@ - How to Buy - CrossDB
Skip to content

Privacy Notice

Introduction

CrossDB Software has designed its website so that, in general, you can browse the CrossDB website without being asked for any personal information. Exceptions to this are when you specifically ask for information, request an evaluation copy of our software or download CrossDB trial software.

This policy covers how CrossDB Software treats personal information that CrossDB may collect and receive via the CrossDB website. Your use of the CrossDB website constitutes acceptance of and agreement with the CrossDB Software Privacy Policy. CrossDB reserves the right to change the CrossDB Software Privacy Policy at any time without notice.

Information collection and use

CrossDB collects personal information when you request for information, request an evaluation of our software or when you download trial software. This information includes information about you such as name, business name and address, telephone and fax numbers, email address, operating system, and hardware environment. Providing information is voluntary. You may provide this information by filling out an on-line form, by email or other communication to CrossDB. However, you may not receive the product information, software evaluation or downloads if you choose not to provide the requested information.

CrossDB Software's use of the information you provided will be to send you the information that you requested. CrossDB Software may also use the information to provide you with additional information about our products and services or market research. The information may be used to follow up with you regarding information supplied, software you downloaded or evaluated.

CrossDB does not sell information collected from users of CrossDB website to other organizations. CrossDB may share the information collected with its subsidiaries and its affiliates such as partners and distributors.

General Information

CrossDB web servers record standard information about CrossDB Web accesses such as IP addresses, your server name, browser type, etc. when you visit our website. CrossDB uses this for information about usage at CrossDB Software's website. The information submitted to CrossDB Software via the Web may be processed, stored and used outside the country where it was submitted.

Links to third party websites are provided for your convenience. By using these links, you will no longer be on the CrossDB Software website and the CrossDB Software Privacy Policy will no longer apply.

Contact us

If you have any question about the information you provided to us or about the CrossDB Software Privacy Policy, please contact us at support@crossdb.org

\ No newline at end of file + Privacy Notice - CrossDB

Privacy Notice

Introduction

CrossDB Software has designed its website so that, in general, you can browse the CrossDB website without being asked for any personal information. Exceptions to this are when you specifically ask for information, request an evaluation copy of our software or download CrossDB trial software.

This policy covers how CrossDB Software treats personal information that CrossDB may collect and receive via the CrossDB website. Your use of the CrossDB website constitutes acceptance of and agreement with the CrossDB Software Privacy Policy. CrossDB reserves the right to change the CrossDB Software Privacy Policy at any time without notice.

Information collection and use

CrossDB collects personal information when you request for information, request an evaluation of our software or when you download trial software. This information includes information about you such as name, business name and address, telephone and fax numbers, email address, operating system, and hardware environment. Providing information is voluntary. You may provide this information by filling out an on-line form, by email or other communication to CrossDB. However, you may not receive the product information, software evaluation or downloads if you choose not to provide the requested information.

CrossDB Software's use of the information you provided will be to send you the information that you requested. CrossDB Software may also use the information to provide you with additional information about our products and services or market research. The information may be used to follow up with you regarding information supplied, software you downloaded or evaluated.

CrossDB does not sell information collected from users of CrossDB website to other organizations. CrossDB may share the information collected with its subsidiaries and its affiliates such as partners and distributors.

General Information

CrossDB web servers record standard information about CrossDB Web accesses such as IP addresses, your server name, browser type, etc. when you visit our website. CrossDB uses this for information about usage at CrossDB Software's website. The information submitted to CrossDB Software via the Web may be processed, stored and used outside the country where it was submitted.

Links to third party websites are provided for your convenience. By using these links, you will no longer be on the CrossDB Software website and the CrossDB Software Privacy Policy will no longer apply.

Contact us

If you have any question about the information you provided to us or about the CrossDB Software Privacy Policy, please contact us at support@crossdb.org

\ No newline at end of file diff --git a/about/refund/index.html b/about/refund/index.html index d5147a6..006c4e3 100755 --- a/about/refund/index.html +++ b/about/refund/index.html @@ -1 +1 @@ - Refund Policy - CrossDB

Refund Policy

Thank you for using CrossDB Database! We don't offer refund, please try it first then subscribe the product by month or year. You can cancel the subscription anytime as you want.

\ No newline at end of file + Refund Policy - CrossDB

Refund Policy

Thank you for using CrossDB Database! We don't offer refund, please try it first then subscribe the product by month or year. You can cancel the subscription anytime as you want.

\ No newline at end of file diff --git a/about/terms/index.html b/about/terms/index.html index a7d5252..ac781bb 100755 --- a/about/terms/index.html +++ b/about/terms/index.html @@ -1 +1 @@ - Terms of Service - CrossDB

Terms of Service

CrossDB provides this Website for your information and use, subject to the terms set forth below. By accessing this Website, you agree to accept the following terms.

General terms

In no event will CrossDB be liable for any damages including, without limitation, indirect, incidental, consequential, special or exemplary damages, that arise out of or relate to the use of or inability to use the CrossDB Website, even if CrossDB has been advised of the possibility of such damages.

Any and all information provided on CrossDB’s Website is provided “as is,” with no warranty as to accuracy or content.

CrossDB does not adopt or endorse the views of any third party Websites linked to or from the CrossDB Website.

CrossDB reserves the right to change, modify, add or remove any of these terms at any time.

\ No newline at end of file + Terms of Service - CrossDB

Terms of Service

CrossDB provides this Website for your information and use, subject to the terms set forth below. By accessing this Website, you agree to accept the following terms.

General terms

In no event will CrossDB be liable for any damages including, without limitation, indirect, incidental, consequential, special or exemplary damages, that arise out of or relate to the use of or inability to use the CrossDB Website, even if CrossDB has been advised of the possibility of such damages.

Any and all information provided on CrossDB’s Website is provided “as is,” with no warranty as to accuracy or content.

CrossDB does not adopt or endorse the views of any third party Websites linked to or from the CrossDB Website.

CrossDB reserves the right to change, modify, add or remove any of these terms at any time.

\ No newline at end of file diff --git a/admin/data-backup/index.html b/admin/data-backup/index.html index 75491e2..cd0a47f 100755 --- a/admin/data-backup/index.html +++ b/admin/data-backup/index.html @@ -1,4 +1,4 @@ - Data Backup - CrossDB

Data Backup

Dump with DUMP statement

  • Dump everything
DUMP DATABASE school INTO 'school.sql';
+ Data Backup - CrossDB      

Data Backup

Dump with DUMP statement

  • Dump everything
DUMP DATABASE school INTO 'school.sql';
 
xdb_exec (pConn, "DUMP DATABASE school INTO 'school.sql'");
 
  • Dump schema only
DUMP DATABASE school NODATA INTO 'school.sql';
 
xdb_exec (pConn, "DUMP DATABASE school NODATA INTO 'school.sql'");
diff --git a/admin/data-restore/index.html b/admin/data-restore/index.html
index 8411c9d..33af2d4 100755
--- a/admin/data-restore/index.html
+++ b/admin/data-restore/index.html
@@ -1,4 +1,4 @@
- Data Restore - CrossDB      

Data Restore

Load with SOURCE statement

SOURCE 'school.sql'
+ Data Restore - CrossDB      

Data Restore

Load with SOURCE statement

SOURCE 'school.sql'
 
xdb_exec (pConn, "SOURCE 'school.sql'");
 

Load with CrossDB tool

crossdb school < school.sql
 
cat school.sql | crossdb school
diff --git a/admin/shell/index.html b/admin/shell/index.html
index be47688..1b01bf0 100755
--- a/admin/shell/index.html
+++ b/admin/shell/index.html
@@ -1,4 +1,4 @@
- CrossDB Shell - CrossDB      

CrossDB Shell

CrossDB tool

This tool can

  • Open and operate local database
  • Connect and operate remote database
  • Work as standalone database server
$ crossdb -h
+ CrossDB Shell - CrossDB      

CrossDB Shell

CrossDB tool

This tool can

  • Open and operate local database
  • Connect and operate remote database
  • Work as standalone database server
$ crossdb -h
 crossdb: option requires an argument -- 'h'
 Usage: xdb-cli [OPTIONS] [[path/]db_name]
   -h                        Show this help
@@ -10,10 +10,10 @@
   -p                        Client password
   -e <sql>                  Execute SQL statements and quite
 

Open DB

crossdb school
-

Open DB and execute command

crossdb -e 'SELECT * FROM student WHERE id=1; SELECT * FROM student WHERE age=10' school
-

Embedded shell

You program can enter interactive shell use the SHELL statement.

SHELL
+

Open DB and Execute Command

crossdb -e 'SELECT * FROM student WHERE id=1; SELECT * FROM student WHERE age=10' school
+

Embedded Shell

You program can enter interactive shell use the SHELL statement.

SHELL
 
xdb_exec (pConn, "SHELL");
-

Auto completion

Use TAB to do auto completion for SQL statements, keywords, db name, table name, field name, etc.

XDB> <TAB>
+

Auto Completion

Use TAB to do auto completion for SQL statements, keywords, db name, table name, field name, etc.

XDB> <TAB>
 CREATE      Create database, table, index, etc
 DROP        Drop database, table, index, etc
 ALTER       Alter database, table, index, etc
diff --git a/client/api-c/index.html b/client/api-c/index.html
index 638378b..270b504 100755
--- a/client/api-c/index.html
+++ b/client/api-c/index.html
@@ -1,4 +1,4 @@
- C APIs - CrossDB      

C APIs

APIs List

API Descritpion
xdb_conn_t* xdb_open (const char *path) Open a connection
void xdb_close (xdb_conn_t *pConn) Close a connection
xdb_res_t* xdb_exec (xdb_conn_t* pConn, const char *sql) Execute SQL statement
xdb_res_t* xdb_pexec (xdb_conn_t* pConn, const char *sql, ...) Execute formatted SQL statement
xdb_res_t* xdb_next_result (xdb_conn_t *pConn) Get next SQL statement result
bool xdb_more_result (xdb_conn_t* pRes) Check is there more result
void xdb_free_result (xdb_res_t* pRes) Free result set
xdb_col_t* xdb_column_meta (uint64_t meta, uint16_t iCol) Fetch one row
xdb_row_t* xdb_fetch_row (xdb_res_t* pRes) Fetch one row
int xdb_column_int (uint64_t meta, void *pRow, uint16_t iCol) Get int column from row
float xdb_column_float (uint64_t meta, void *pRow, uint16_t iCol) Get float/double column from row
const char * xdb_column_str (uint64_t meta, void *pRow, uint16_t iCol) Get string column from row
xdb_stmt_t* xdb_stmt_prepare (xdb_conn_t* pConn, const char *sql) Prepare statement
xdb_ret xdb_bind_int (xdb_stmt_t *pStmt, uint16_t para_id, int val) Bind int value
xdb_ret xdb_bind_float (xdb_stmt_t *pStmt, uint16_t para_id, float val) Bind float value
xdb_ret xdb_bind_str (xdb_stmt_t *pStmt, uint16_t para_id, const char *str) Bind string value
xdb_res_t* xdb_stmt_exec (xdb_stmt_t *pStmt) Execute prepared SQL statement
void xdb_stmt_close (xdb_stmt_t *pStmt) Free prepared SQL statement
xdb_ret xdb_begin (xdb_conn_t* pConn) Begin transaction
xdb_ret xdb_commit (xdb_conn_t* pConn) Commit transaction
xdb_ret xdb_rollback (xdb_conn_t* pConn) Rollback transaction
int xdb_print_row (uint64_t meta, void *pRow, int format) Print row to console
const char * xdb_errmsg (xdb_res_t *pRes) Get error/information message
const char * xdb_version () Get CrossDB version string

xdb_open

Open a connection and create/open a Database.

xdb_conn_t*
+ C APIs - CrossDB      

C APIs

APIs List

API Descritpion
xdb_conn_t* xdb_open (const char *path) Open a connection
void xdb_close (xdb_conn_t *pConn) Close a connection
xdb_res_t* xdb_exec (xdb_conn_t* pConn, const char *sql) Execute SQL statement
xdb_res_t* xdb_next_result (xdb_conn_t *pConn) Get next SQL statement result
bool xdb_more_result (xdb_conn_t* pRes) Check is there more result
void xdb_free_result (xdb_res_t* pRes) Free result set
xdb_col_t* xdb_column_meta (uint64_t meta, uint16_t iCol) Fetch one row
xdb_row_t* xdb_fetch_row (xdb_res_t* pRes) Fetch one row
int xdb_column_int (uint64_t meta, void *pRow, uint16_t iCol) Get int column from row
float xdb_column_float (uint64_t meta, void *pRow, uint16_t iCol) Get float/double column from row
const char * xdb_column_str (uint64_t meta, void *pRow, uint16_t iCol) Get string column from row
xdb_stmt_t* xdb_stmt_prepare (xdb_conn_t* pConn, const char *sql) Prepare statement
xdb_ret xdb_bind_int (xdb_stmt_t *pStmt, uint16_t para_id, int val) Bind int value
xdb_ret xdb_bind_float (xdb_stmt_t *pStmt, uint16_t para_id, float val) Bind float value
xdb_ret xdb_bind_str (xdb_stmt_t *pStmt, uint16_t para_id, const char *str) Bind string value
xdb_res_t* xdb_stmt_exec (xdb_stmt_t *pStmt) Execute prepared SQL statement
void xdb_stmt_close (xdb_stmt_t *pStmt) Free prepared SQL statement
xdb_ret xdb_begin (xdb_conn_t* pConn) Begin transaction
xdb_ret xdb_commit (xdb_conn_t* pConn) Commit transaction
xdb_ret xdb_rollback (xdb_conn_t* pConn) Rollback transaction
int xdb_print_row (uint64_t meta, void *pRow, int format) Print row to console
const char * xdb_errmsg (xdb_res_t *pRes) Get error/information message
const char * xdb_version () Get CrossDB version string

xdb_open

Open a connection and create/open a Database.

xdb_conn_t*
 xdb_open (const char *path);
 
 // TBD
@@ -11,15 +11,15 @@
 
 xdb_res_t*
 xdb_exec2 (xdb_conn_t *pConn, const char *sql, int len);
-
  • A valid xdb_res_t pointer is returned always.
  • row count: pRes->row_count
  • column count: pRes->col_count
  • column meta: pRes->row_meta, use xdb_col_t* xdb_column_meta (uint64_t meta, uint16_t iCol) to get column meta.

xdb_pexec

Execute formatted SQL statement and return result set.

xdb_res_t*
+
  • A valid xdb_res_t pointer is returned always.
  • errcode: if != 0, then can use xdb_errmsg(pRes) to get the error message.
  • row count: pRes->row_count for query statement
  • affected rows: pRes->affected_rows for INSERT UPDATE DELETE rows
  • column count: pRes->col_count for query statement
  • column meta: pRes->row_meta, use xdb_column_meta to get column meta.

xdb_pexec

Execute formatted SQL statement and return result set.

xdb_res_t*
 xdb_pexec (xdb_conn_t *pConn, const char *sql, ...);
-
  • A valid xdb_res_t pointer is returned always.

Note

If sql contains %, should use escape \%.

xdb_next_result

Get next SQL statement result

xdb_res_t*
+
  • A valid xdb_res_t pointer is returned always.

Note

If sql contains %, should use escape \%.

xdb_next_result

Get next SQL statement result

Return NULL if no more result

xdb_res_t*
 xdb_next_result (xdb_conn_t *pConn);
-

xdb_more_result

Check is there more result

bool
+

xdb_more_result

Check is there more result

bool
 xdb_more_result (xdb_conn_t *pConn);
-

xdb_free_result

Free result set

void
+

xdb_free_result

Free result set

void
 xdb_free_result (xdb_res_t *pRes);
-

Note

You only need to call xdb_free_result for statements more than 0 rows.

xdb_column_meta

Get column meta.

const xdb_col_t* 
+

Note

You only need to call xdb_free_result for query statements with errcode=0.

xdb_column_meta

Get column meta.

const xdb_col_t* 
 xdb_column_meta (uint64_t meta, uint16_t iCol)
 

Note

This is an inline function.

xdb_fetch_row

Fetch one row and return row list array.

xdb_row_t*
 xdb_fetch_row (xdb_res_t *pRes);
diff --git a/client/api-python/index.html b/client/api-python/index.html
index 801892e..33b252a 100755
--- a/client/api-python/index.html
+++ b/client/api-python/index.html
@@ -1,4 +1,4 @@
- Python - CrossDB      

Python

TBD

Comments

Python

TBD

Comments

Community

Report Bugs

Github Issues

Require Fetures

Github Fetures

Discussion

Github Discussion

Contribution

In order to keep CrossDB quality and high-performance, this project does not accept patches. If you would like to suggest a change and you include a patch as a proof-of-concept, that would be great. However, please do not be offended if we rewrite your patch from scratch.

Following contributions are welcome:

  • Language bindings: Python, Java, Go, CSharp, Javascript, PHP, etc
  • Test and report bugs

Comments

Community

Report Bugs

Github Issues

Require Fetures

Github Fetures

Discussion

Github Discussion

Contribution

In order to keep CrossDB quality and high-performance, this project does not accept patches. If you would like to suggest a change and you include a patch as a proof-of-concept, that would be great. However, please do not be offended if we rewrite your patch from scratch.

Following contributions are welcome:

  • Language bindings: Python, Java, Go, CSharp, Javascript, PHP, etc
  • Test and report bugs

Comments

Connect to CrossDB

  • One thread can use only one connection. One connection can only be used by one thread.
  • All opened databases are shared with all opened connections, and they can USE DATABASE db_name to switch connection's default DB.

C APIs

  • Open a connection
xdb_conn_t *pConn = xdb_open (NULL);
+ Connect - CrossDB      

Connect to CrossDB

You need a connection instance to connect to CrossDB and all operations will use this connection handle.

  • One thread can use only one connection. One connection can only be used by one thread.
  • All opened databases are shared with all opened connections, and they can USE DATABASE db_name to switch connection's default DB.

C APIs

  • Open a connection
xdb_conn_t *pConn = xdb_open (NULL);
 

Note

User has to use OPEN DATABASE '[path/]db_name' or CREATE DATABASE '[path/]db_name' or USE DATABASE db_name.

  • Open a connection and create a default memory database if not exist
xdb_conn_t *pConn = xdb_open (":memory:");
-
  • Open a connection and create a on-disk database school if not exist in current folder as the default database
xdb_conn_t *pConn = xdb_open ("school");
+
  • Open a connection and create a on-disk database school if not exist as the default database
//  In current folder
+xdb_conn_t *pConn = xdb_open ("school");
+
// In specified folder
+xdb_conn_t *pConn = xdb_open ("/var/crossdb/school");
 
CrossDB

Data Model

Create and Use a Database

-- Create database in current folder
+ Data Model - CrossDB      

Data Model

Create and Use a Database

-- Create database in current folder
 CREATE DATABASE school;
 -- Create database in specified folder (must exist)
-CREATE DATABASE '/var/dbpath/school';
+CREATE DATABASE '/var/crossdb/school';
 -- Create in-memory database 
 CREATE DATABASE test ENGINE=memory;
 
// Create database in current folder
 xdb_res_t *pRes = xdb_exec (pConn, "CREATE DATABASE school");
 // Create database in specified folder (must exist)
-xdb_res_t *pRes = xdb_exec (pConn, "CREATE DATABASE '/var/dbpath/school'");
+xdb_res_t *pRes = xdb_exec (pConn, "CREATE DATABASE '/var/crossdb/school'");
 // Create in-memory database 
 xdb_res_t *pRes = xdb_exec (pConn, "CREATE DATABASE test ENGINE=memory");
 

Create a Table

CREATE TABLE IF NOT EXISTS student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(256), INDEX (name));
diff --git a/develop/dml/index.html b/develop/dml/index.html
index 260dde9..055a79b 100755
--- a/develop/dml/index.html
+++ b/develop/dml/index.html
@@ -1,8 +1,23 @@
- Data Manipulation - CrossDB      

Data Manipulation

Insert Rows

INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95);
-INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')", 'He is a boy.\nHe likes playing football.\nWe all like him!');
+ Data Manipulation - CrossDB      

Data Manipulation

Insert Rows

INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95);
+
+INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')", 'He is a boy.\nHe likes playing football.\nWe all like him!');
 
pRes = xdb_exec (pConn, "INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)");
-pRes = xdb_pexec (pConn, "INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')", "He is a boy.\nHe likes playing football.\nWe all like him!");
-

Update Rows

TBD

Delete Rows

TBD

Comments

Multi-Statements

TBD

Comments

Multi-Statements

Multi-Statements feature can improve performance a lot especailly for client-server mode. As you can run a batch of statements in one query, then get result one by one in parallel. For database doesn't support Multi-Statements, you have to send one statement, wait result, then send next one which will be low performance especailly when network lattency is big.

SELECT COUNT(*) FROM student; SELECT id,name FROM student WHERE id=2;
+
pRes = xdb_exec (pConn, "SELECT COUNT(*) FROM student; SELECT id,name FROM student WHERE id=2");
+printf ("-- 1st result: ");
+if (NULL != (pRow = xdb_fetch_row (pRes))) {
+    xdb_print_row (pRes->col_meta, pRow, 0);
+    printf ("\n");
+}
+xdb_free_result (pRes);
+printf ("-- 2nd result: ");
+pRes = xdb_next_result (pConn);
+if (NULL != pRes) {
+    if (NULL != (pRow = xdb_fetch_row (pRes))) {
+        xdb_print_row (pRes->col_meta, pRow, 0);
+        printf ("\n");
+    }
+    xdb_free_result (pRes);
+}
+

Comments

Prepared Statements

TBD

Comments

Prepared Statements

Prepared Statements can save the SQL parsing time and improve performance.

Note

Now only support SELECT UPDATE DELETE statements.

Steps

  • Create Prepared Statments
xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, "xxx WHERE id=?");
+
  • Bind paramters
xdb_bind_int (pStmt, 1, id);
+

Note

Bind parameter id starts from 1. Now only support WHERE clause.

  • Execute prepared statements
xdb_res_t *pRes = xdb_stmt_exec (pStmt);
+
  • Close statements
xdb_stmt_close (pStmt);
+

Select

xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, "SELECT * FROM student WHERE id=?");
+if (NULL != pStmt) {
+    xdb_bind_int (pStmt, 1, id);
+    pRes = xdb_stmt_exec (pStmt);
+    pRow = xdb_fetch_row (pRes);
+    // handle pRow
+    xdb_free_result (pRes);
+
+    // close when finish using
+    xdb_stmt_close (pStmt);
+    }
+}
+

Update

xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, "UPDATE student SET age=15 WHERE id=?");
+if (NULL != pStmt) {
+    xdb_bind_int (pStmt, 1, id);
+    pRes = xdb_stmt_exec (pStmt);
+
+    // close when finish using
+    xdb_stmt_close (pStmt);
+    }
+}
+

Delete

xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, "DELETE FROM student WHERE id=?");
+if (NULL != pStmt) {
+    xdb_bind_int (pStmt, 1, id[i]);
+    pRes = xdb_stmt_exec (pStmt);
+
+    // close when finish using
+    xdb_stmt_close (pStmt);
+    }
+}
+

Comments

Query Rows

TBD

Comments

Query Rows

Select Rows

SELECT id,name,age,class,score from student WHERE id = 2;
+
xdb_res_t *pRes = xdb_exec (pConn, "SELECT id,name,age,class,score from student WHERE id = 2");
+
+xdb_res_t *pRes = xdb_pexec (pConn, "SELECT id,name,age,class,score from student WHERE id = %d", id);
+
+// check pRes->errcode = 0
+

Get Row Count

pRes->row_count;
+

Get Column information

for (int i = 0; i < pRes->col_count; ++i) {
+    xdb_col_t *pCol = xdb_column_meta (pRes, i);
+    printf ("type %d name %s\n", pCol->type, pCol->name);
+}
+

Fetch One Row

xdb_row_t *pRow = xdb_fetch_row (pRes);
+

Get Column Values

  • Access by column data type
printf ("char value %d\n",      *(char*)pRow[0]);
+printf ("short value %d\n",     *(short*)pRow[1]);
+printf ("int value %d\n",       *(int*)pRow[2]);
+printf ("bigint value %"PRIi64"\n", *(int64_t*)pRow[3]);
+printf ("float value %f\n",     *(float*)pRow[4]);
+printf ("double value %d\n",    *(double*)pRow[5]);
+printf ("string value %s\n",    *(char*)pRow[6]);
+printf ("string len   %d\n",    *(uint16_t*)(pRow[6]-2));
+
  • Access by API
printf ("char value %d\n",      xdb_column_int(pRes->col_meta, pRow, 0));
+printf ("short value %d\n",     xdb_column_int(pRes->col_meta, pRow, 1));
+printf ("int value %d\n",       xdb_column_int(pRes->col_meta, pRow, 2));
+printf ("bigint value %"PRIi64"\n", xdb_column_int64(pRes->col_meta, pRow, 3));
+printf ("float value %f\n",     xdb_column_float(pRes->col_meta, pRow, 4));
+printf ("double value %d\n",    xdb_column_double(pRes->col_meta, pRow, 5));
+printf ("string value %s\n",    xdb_column_str(pRes->col_meta, pRow, 6));
+int len;
+printf ("string value %s, len %d\n", xdb_column_str2(pRes->col_meta, pRow, 6, &len), len);
+

Comments

Transaction

Reader-Writeer MVCC

Current CrossDB uses table-level readwrite lock, only one writer connection thread can modify the table, other writer connection threads will be blocked. However the reader connection threads won't be blocked and they'll see the old values. When the writer connection change is committed, the new value is visible by these reader connections (read committed).
In short writer before commit will not block readers to read old values

Auto-commit

TBD

Begin

TBD

Commit

TBD

Rollback

TBD

Comments

Transaction

CrossDB transaction supports ACID. Default isolation level is READ COMMITTED

Reader-Writeer MVCC

Current CrossDB uses table-level readwrite lock, only one writer connection thread can modify the table, other writer connection threads will be blocked. However the reader connection threads won't be blocked and they'll see the old values. When the writer connection change is committed, the new value is visible by these reader connections (read committed).
In short writer before commit will not block readers to read old values

Auto-commit

Enabled by default.

-- Disable auto-commit
+SET AUTOCOMMIT = 0;
+-- Enable auto-commit
+SET AUTOCOMMIT = 1;
+
// Disable auto-commit
+xdb_exec (pConn, "SET AUTOCOMMIT = 0");
+// Enable auto-commit
+xdb_exec (pConn, "SET AUTOCOMMIT = 1");
+

Begin Transaction

BEGIN;
+
xdb_begin (pConn); // fast
+// or
+xdb_exec (pConn, "BEGIN");
+

Note

This operation is optional and transaction will begin automatically when changing table.

Commit Transaction

COMMIT;
+
xdb_commit (pConn); // fast
+// or
+xdb_exec (pConn, "COMMIT");
+

Rollback Transaction

ROLLBACK;
+
xdb_rollback (pConn); // fast
+// or
+xdb_exec (pConn, "ROLLBACK");
+

Note

Even there's errors during statements execution, transaction won't be rollbacked automatically, and user have to issue rollback expilicitly.

Comments

FAQ

Why is CrossDB so fast?

  • Use memory map to access DB data directly (so your DB must less than the main memory to get highest speed).
  • Use high-performance hash as the main index, and use the super fast wyhash as the hash function.
  • Hand-written SQL parser which is more than 10X faster than Flex/Bison parser tools.
  • High-performance read-write lock and multi-core optimization.
  • Execute multiple SQL statements in one API, which will imporve client-server DB performance dramatically.
  • High-efficient client-server protocols.
  • Avoid memory allocation/free as much as possible.
  • High-performance implementation code

Comments

FAQ

Why is CrossDB so fast?

  • Use memory map to access DB data directly (so your DB must less than the main memory to get highest speed).
  • Use high-performance hash as the main index, and use the super fast wyhash as the hash function.
  • Hand-written SQL parser which is more than 10X faster than Flex/Bison parser tools.
  • High-performance read-write lock and multi-core optimization.
  • Execute multiple SQL statements in one API, which will imporve client-server DB performance dramatically.
  • High-efficient client-server protocols.
  • Avoid memory allocation/free as much as possible.
  • High-performance implementation code

Comments

Example and Bench

Example

crossdb$ make example
-=== Select all 7 rows
-id=1 name='jack' age=10 class='3-1' score=90.000000 info=''
-id=2 name='tom' age=11 class='2-5' score=91.000000 info=''
-id=3 name='jack' age=11 class='1-6' score=92.000000 info=''
-id=4 name='rose' age=10 class='4-2' score=90.000000 info=''
-id=5 name='tim' age=10 class='3-1' score=95.000000 info=''
-id=6 name='Tony' age=10 class='3-1' score=95.000000 info='He is a boy.
-He likes playing football.
-We all like him!'
-id=7 name='Wendy' age=10 class='3-1' score=95.000000 info='She is a girl.
-She likes cooking.
-We all love her!'
-
-=== Update age = 9 for id = 2
-select 1 rows
-id=2 name='tom' age=9 class='2-5' score=91.000000
-id=2 name='tom' age=9 class='2-5' score=91.000000
-id=2 name='tom' age=9 class='2-5' score=91.000000
-
-=== Delete id = 3
-select 0 rows
-=== select 1 rows
-COUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667
-COUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667
-COUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667
-
-=== Muti-Statements
-COUNT(*)=6
-id=2 name='tom'
-   _____                   _____  ____      _
-  / ____|                 |  __ \|  _ \   _| |_
- | |     _ __ ___  ___ ___| |  | | |_) | |_   _|
- | |    | '__/ _ \/ __/ __| |  | |  _ <    |_|
- | |____| | | (_) \__ \__ \ |__| | |_) |  0.6.0
-  \_____|_|  \___/|___/___/_____/|____/ crossdb.org
-
-============ Welcome to CrossDB Shell ============
-<help>: Help Info       <F1>: Shortcuts
-<exit>: Exit shell      <TAB>: Auto completion
-
-XDB> exit
-

Bench Test

Test with 1000 rows

crossdb/bench/c$ ./a.out 1000
-********************** INSERT 1000 with SQL **********************
-Use time 763ns, QPS 1310615
-********************** Random LKUP 5000000 with SQL **********************
-Use time 951987ns, QPS 5252172
-Use time 921033ns, QPS 5428687
-Use time 915605ns, QPS 5460870
-Use time 926288ns, QPS 5397889
-********************** UPDATE 1000 with SQL **********************
-Use time 760ns, QPS 1315789
-********************** DELETE 1000 with SQL **********************
-Use time 438ns, QPS 2283105
-
-********************** INSERT 1000 with SQL **********************
-Use time 687ns, QPS 1455604
-********************** Random LKUP 10000000 with Prepared STMT **********************
-Use time 294717ns, QPS 33930855
-Use time 297268ns, QPS 33639678
-Use time 298728ns, QPS 33475268
-Use time 295278ns, QPS 33866390
-********************** UPDATE 1000 with Prepared SMTT **********************
-Use time 576ns, QPS 1736111
-********************** DELETE 1000 with Prepared SQL **********************
-Use time 252ns, QPS 3968253
-

Test with 1000,1000 rows

crossdb$ make bench
-or
-crossdb/bench/c$ ./a.out
-
-********************** INSERT 1000000 with SQL **********************
-Use time 539342ns, QPS 1854111
-********************** Random LKUP 1000000 with SQL **********************
-Use time 336044ns, QPS 2975800
-Use time 333927ns, QPS 2994666
-Use time 329699ns, QPS 3033069
-Use time 331632ns, QPS 3015390
-********************** UPDATE 1000000 with SQL **********************
-Use time 579945ns, QPS 1724301
-********************** DELETE 1000000 with SQL **********************
-Use time 405004ns, QPS 2469111
-
-********************** INSERT 1000000 with SQL **********************
-Use time 527486ns, QPS 1895784
-********************** Random LKUP 10000000 with Prepared STMT **********************
-Use time 1678936ns, QPS 5956153
-Use time 1668971ns, QPS 5991715
-Use time 1670993ns, QPS 5984465
-Use time 1652815ns, QPS 6050283
-********************** UPDATE 1000000 with Prepared SMTT **********************
-Use time 381320ns, QPS 2622469
-********************** DELETE 1000000 with Prepared SQL **********************
-Use time 232181ns, QPS 4306984
+ Bench Test - CrossDB      

Bench Test

Test with 1000 rows

crossdb/bench/c$ ./a.out 1000
+********************** INSERT 1000 with SQL **********************
+Use time 763ns, QPS 1310615
+********************** Random LKUP 5000000 with SQL **********************
+Use time 951987ns, QPS 5252172
+Use time 921033ns, QPS 5428687
+Use time 915605ns, QPS 5460870
+Use time 926288ns, QPS 5397889
+********************** UPDATE 1000 with SQL **********************
+Use time 760ns, QPS 1315789
+********************** DELETE 1000 with SQL **********************
+Use time 438ns, QPS 2283105
+
+********************** INSERT 1000 with SQL **********************
+Use time 687ns, QPS 1455604
+********************** Random LKUP 10000000 with Prepared STMT **********************
+Use time 294717ns, QPS 33930855
+Use time 297268ns, QPS 33639678
+Use time 298728ns, QPS 33475268
+Use time 295278ns, QPS 33866390
+********************** UPDATE 1000 with Prepared SMTT **********************
+Use time 576ns, QPS 1736111
+********************** DELETE 1000 with Prepared SQL **********************
+Use time 252ns, QPS 3968253
+

Test with 1000,1000 rows

crossdb$ make bench
+or
+crossdb/bench/c$ ./a.out
+
+********************** INSERT 1000000 with SQL **********************
+Use time 539342ns, QPS 1854111
+********************** Random LKUP 1000000 with SQL **********************
+Use time 336044ns, QPS 2975800
+Use time 333927ns, QPS 2994666
+Use time 329699ns, QPS 3033069
+Use time 331632ns, QPS 3015390
+********************** UPDATE 1000000 with SQL **********************
+Use time 579945ns, QPS 1724301
+********************** DELETE 1000000 with SQL **********************
+Use time 405004ns, QPS 2469111
+
+********************** INSERT 1000000 with SQL **********************
+Use time 527486ns, QPS 1895784
+********************** Random LKUP 10000000 with Prepared STMT **********************
+Use time 1678936ns, QPS 5956153
+Use time 1668971ns, QPS 5991715
+Use time 1670993ns, QPS 5984465
+Use time 1652815ns, QPS 6050283
+********************** UPDATE 1000000 with Prepared SMTT **********************
+Use time 381320ns, QPS 2622469
+********************** DELETE 1000000 with Prepared SQL **********************
+Use time 232181ns, QPS 4306984
+

Maximum performance

This will build with -O3 and -march=native flags

crossdb/bench/c$ make fast
 

Comments

CrossDB

Build and Install

Build

crossdb$ make
+ Build and Install - CrossDB      

Build and Install

Build

crossdb$ make
 make build                Build crossdb library and tool
 make debug                Build crossdb library and tool with debug
 make run                  Run crossdb tool
 make clean                Clean build result
-make install              Install crossdb(lib&tool&header) to Linux & FreeBSD
-make uninstall            Uninstall crossdb from Linux & FreeBSD
+make install              Install crossdb(lib&tool&header) to Linux/FreeBSD
+make uninstall            Uninstall crossdb from Linux/FreeBSD
 make installmacos         Install crossdb(lib&tool&header) to MacOS
 make uninstallmacos       Uninstall crossdb from MacOS
 make example              Build and run example (need to install crossdb first)
@@ -13,7 +13,7 @@
 sudo make install
 

MacOS

make build
 sudo make installmacos
-

Windows

You need to install MINGW64 to build. Then set gcc path to system environment variables Path and make sure gcc can run.

build
+

Windows

You need to install MINGW64 to build. Then set gcc path to system environment variables Path and make sure gcc can run.

build.bat
 

Comments

\ No newline at end of file +
\ No newline at end of file diff --git a/get-started/tutorial/index.html b/get-started/tutorial/index.html index 768617f..fde1827 100755 --- a/get-started/tutorial/index.html +++ b/get-started/tutorial/index.html @@ -1,24 +1,14 @@ - Turorial - CrossDB

Turorial

  • Open conection and create default memory database
xdb_res_t   *pRes;
+ Turorial - CrossDB      

Turorial

Open conection and create default memory database

xdb_res_t   *pRes;
 xdb_row_t   *pRow;
 
 xdb_conn_t  *pConn = xdb_open (":memory:");
-
  • Create Table
pRes = xdb_exec (pConn, "CREATE TABLE student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(255))");
+

Create Table

pRes = xdb_exec (pConn, "CREATE TABLE student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(255))");
 XDB_CHECK(pRes, printf ("Can't create table student\n"); goto error;);
 pRes = xdb_exec (pConn, "CREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(255), INDEX (name))");
 XDB_CHECK(pRes, printf ("Can't create table teacher\n"); goto error;);
 pRes = xdb_exec (pConn, "CREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name))");
 XDB_CHECK(pRes, printf ("Can't create table book\n"); goto error;);
-
  • Insert Rows
pRes = xdb_exec (pConn, "INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)");
+

Insert Rows

pRes = xdb_exec (pConn, "INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)");
 XDB_CHECK(pRes, printf ("Can't insert table student\n"); goto error;);
 pRes = xdb_pexec (pConn, "INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')", "He is a boy.\nHe likes playing football.\nWe all like him!");
 XDB_CHECK(pRes, printf ("Can't insert table student\n"); goto error;);
@@ -28,26 +18,14 @@
 XDB_CHECK(pRes, printf ("Can't insert table teacher\n"); goto error;);
 pRes = xdb_exec (pConn, "INSERT INTO book (id,name,author,count) VALUES (1,'Romeo and Juliet','Shakespeare',10),(2,'Pride and Prejudice','Austen',5),(3,'Great Expectations','Dickens',8),(4,'Sorrows of Young Werther','Von Goethe',4)");
 XDB_CHECK(pRes, printf ("Can't insert table book\n"); goto error;);
-
  • Select Rows
pRes = xdb_exec (pConn, "SELECT * from student");
+

Select Rows

pRes = xdb_exec (pConn, "SELECT * from student");
 printf ("=== Select all %d rows\n", (int)pRes->row_count);
 while (NULL != (pRow = xdb_fetch_row (pRes))) {
     xdb_print_row (pRes->col_meta, pRow, 0);
     printf ("\n");
-    printf ("id=%d name='%s' age=%d class='%s' score=%f\n", 
-        xdb_column_int (pRes->col_meta, pRow, 0), 
-        xdb_column_str (pRes->col_meta, pRow, 1), 
-        xdb_column_int (pRes->col_meta, pRow, 2), 
-        xdb_column_str (pRes->col_meta, pRow, 3), 
-        xdb_column_float(pRes->col_meta, pRow, 4));
-    printf ("id=%d name='%s' age=%d class='%s' score=%f\n", 
-        *(int*)pRow[0], 
-        (char*)pRow[1], 
-        *(int*)pRow[2], 
-        (char*)pRow[3], 
-        *(float*)pRow[4]);
-}
-xdb_free_result (pRes);
-
  • Update Rows
printf ("\n=== Update age = 9 for id = 2\n");
+}
+xdb_free_result (pRes);
+

Update Rows

printf ("\n=== Update age = 9 for id = 2\n");
 pRes = xdb_exec (pConn, "UPDATE student set age=9 WHERE id = 2");
 XDB_CHECK(pRes, printf ("Can't update id=%d\n",2); goto error;);
 
@@ -58,7 +36,7 @@
     printf ("\n");
 }
 xdb_free_result (pRes);
-
  • Delete Rows
printf ("\n=== Delete id = 3\n");
+

Delete Rows

printf ("\n=== Delete id = 3\n");
 pRes = xdb_exec (pConn, "DELETE FROM student WHERE id = 3");
 XDB_CHECK(pRes, printf ("Can't delete id=%d\n",3); goto error;);
 
@@ -69,27 +47,15 @@
     printf ("\n");
 }
 xdb_free_result (pRes);
-
  • Aggregation function
printf ("\n=== AGG COUNT,MIN,MAX,SUM,AVG\n");
+

Aggregation function

printf ("\n=== AGG COUNT,MIN,MAX,SUM,AVG\n");
 pRes = xdb_exec (pConn, "SELECT COUNT(*),MIN(score),MAX(score),SUM(score),AVG(score) FROM student");
 printf ("=== select %d rows\n", (int)pRes->row_count);
 if (NULL != (pRow = xdb_fetch_row (pRes))) {
     xdb_print_row (pRes->col_meta, pRow, 0);
     printf ("\n");
-    printf ("COUNT(*)=%d MIN(score)=%f MAX(score)=%f SUM(score)=%f AVG(score)=%f\n", 
-        xdb_column_int (pRes->col_meta, pRow, 0), 
-        xdb_column_double(pRes->col_meta, pRow, 1), 
-        xdb_column_double(pRes->col_meta, pRow, 2), 
-        xdb_column_double(pRes->col_meta, pRow, 3), 
-        xdb_column_double(pRes->col_meta, pRow, 4));
-    printf ("COUNT(*)=%d MIN(score)=%f MAX(score)=%f SUM(score)=%f AVG(score)=%f\n", 
-        (int)*(int64_t*)pRow[0], 
-        *(float*)pRow[1], 
-        *(float*)pRow[2], 
-        *(double*)pRow[3], 
-        *(double*)pRow[4]);
-}
-xdb_free_result (pRes);
-
  • Transaction Rollback
printf ("\n=== Rollback\n");
+}
+xdb_free_result (pRes);
+

Transaction Rollback

printf ("\n=== Rollback\n");
 xdb_begin (pConn);
 pRes = xdb_exec (pConn, "UPDATE student set age=15 WHERE id = 2");
 pRes = xdb_exec (pConn, "SELECT id,name,age from student WHERE id = 2");
@@ -108,7 +74,7 @@
     printf ("\n");
 }
 xdb_free_result (pRes);
-
  • Transaction Commit
printf ("\n=== Commit\n");
+

Transaction Commit

printf ("\n=== Commit\n");
 xdb_begin (pConn);
 pRes = xdb_exec (pConn, "UPDATE student set age=15 WHERE id = 2");
 pRes = xdb_exec (pConn, "SELECT * from student WHERE id = 2");
@@ -127,7 +93,7 @@
     printf ("\n");
 }
 xdb_free_result (pRes);
-
  • Multi-Statements
printf ("\n=== Muti-Statements\n");
+

Multi-Statements

printf ("\n=== Muti-Statements\n");
 pRes = xdb_exec (pConn, "SELECT COUNT(*) FROM student; SELECT id,name FROM student WHERE id=2");
 // count(*) 
 if (NULL != (pRow = xdb_fetch_row (pRes))) {
@@ -146,6 +112,45 @@
 }
 
 xdb_exec (pConn, "SHELL");
+

Enter Embedded Shell

xdb_exec (pConn, "SHELL");
+

Example Output

crossdb$ make example
+=== Select all 7 rows
+id=1 name='jack' age=10 class='3-1' score=90.000000 info=''
+id=2 name='tom' age=11 class='2-5' score=91.000000 info=''
+id=3 name='jack' age=11 class='1-6' score=92.000000 info=''
+id=4 name='rose' age=10 class='4-2' score=90.000000 info=''
+id=5 name='tim' age=10 class='3-1' score=95.000000 info=''
+id=6 name='Tony' age=10 class='3-1' score=95.000000 info='He is a boy.
+He likes playing football.
+We all like him!'
+id=7 name='Wendy' age=10 class='3-1' score=95.000000 info='She is a girl.
+She likes cooking.
+We all love her!'
+
+=== Update age = 9 for id = 2
+select 1 rows
+id=2 name='tom' age=9 class='2-5' score=91.000000
+
+=== Delete id = 3
+select 0 rows
+=== select 1 rows
+COUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667
+
+=== Muti-Statements
+COUNT(*)=6
+id=2 name='tom'
+   _____                   _____  ____      _
+  / ____|                 |  __ \|  _ \   _| |_
+ | |     _ __ ___  ___ ___| |  | | |_) | |_   _|
+ | |    | '__/ _ \/ __/ __| |  | |  _ <    |_|
+ | |____| | | (_) \__ \__ \ |__| | |_) |  0.6.0
+  \_____|_|  \___/|___/___/_____/|____/ crossdb.org
+
+============ Welcome to CrossDB Shell ============
+<help>: Help Info       <F1>: Shortcuts
+<exit>: Exit shell      <TAB>: Auto completion
+
+XDB> exit
 

Comments

\ No newline at end of file +
\ No newline at end of file diff --git a/glossary/index.html b/glossary/index.html index 1729ea1..da9482c 100755 --- a/glossary/index.html +++ b/glossary/index.html @@ -1,4 +1,4 @@ - Glossary - CrossDB

Glossary

ACID

ACID refers to the four key properties of a transaction: atomicity, consistency, isolation, and durability. Each of these properties is described below.

Atomicity means that either all the changes of an operation are performed, or none of them are.

Consistency means that transactions always bring the database from one consistent state to another.

Isolation means that a transaction in process is invisible to other transactions until it completes. This allows concurrent transactions to read and write data without sacrificing consistency.

Durability means that once a transaction is committed, it remains committed even in the event of a system failure.

CRUD

Acronym for “create, read, update, delete”, a common sequence of operations in database applications. Often denotes a class of applications with relatively simple database usage (basic DDL, DML and query statements in SQL) that can be implemented quickly in any language.

DDL

Data definition language, a set of SQL statements for manipulating the database itself rather than individual table rows. Includes all forms of the CREATE, ALTER, and DROP statements. DDL statements automatically commit the current transaction; they cannot be rolled back.

DML

Data manipulation language, a set of SQL statements for performing SELECT, INSERT, UPDATE, and DELETE operations.

Hash Index

A type of index intended for queries that use equality operators, rather than range operators such as greater-than or BETWEEN.

IMDB

IMDB(In-Memory database) is a type of database system that maintains data in memory, to avoid overhead due to disk I/O and translation between disk blocks and memory areas.

Index

A data structure that provides a fast lookup capability for rows of a table, typically by forming a tree structure (B-tree) representing all the values of a particular column or set of columns.

INFORMATION_SCHEMA

The name of the database that provides a query interface to the CrpssDB data dictionary. (This name is defined by the ANSI SQL standard.) To examine information (metadata) about the database, you can query tables such as INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.COLUMNS, rather than using SHOW commands that produce unstructured output.

MVCC

MVCC(Multi-Version Concurrency Control) is a concurrency control mechanism in many databases. It processes the memory read by transactions to achieve concurrent access to DB, thereby avoiding blocking caused by conflicts between concurrent reads and writes.

OLTP

Acronym for “Online Transaction Processing”. A database system, or a database application, that runs a workload with many transactions, with frequent writes as well as reads, typically affecting small amounts of data at a time.

SQL

The Structured Query Language that is standard for performing database operations. Often divided into the categories DDL, DML, and queries.

Comments

Glossary

ACID

ACID refers to the four key properties of a transaction: atomicity, consistency, isolation, and durability. Each of these properties is described below.

Atomicity means that either all the changes of an operation are performed, or none of them are.

Consistency means that transactions always bring the database from one consistent state to another.

Isolation means that a transaction in process is invisible to other transactions until it completes. This allows concurrent transactions to read and write data without sacrificing consistency.

Durability means that once a transaction is committed, it remains committed even in the event of a system failure.

CRUD

Acronym for “create, read, update, delete”, a common sequence of operations in database applications. Often denotes a class of applications with relatively simple database usage (basic DDL, DML and query statements in SQL) that can be implemented quickly in any language.

DDL

Data definition language, a set of SQL statements for manipulating the database itself rather than individual table rows. Includes all forms of the CREATE, ALTER, and DROP statements. DDL statements automatically commit the current transaction; they cannot be rolled back.

DML

Data manipulation language, a set of SQL statements for performing SELECT, INSERT, UPDATE, and DELETE operations.

Hash Index

A type of index intended for queries that use equality operators, rather than range operators such as greater-than or BETWEEN.

IMDB

IMDB(In-Memory database) is a type of database system that maintains data in memory, to avoid overhead due to disk I/O and translation between disk blocks and memory areas.

Index

A data structure that provides a fast lookup capability for rows of a table, typically by forming a tree structure (B-tree) representing all the values of a particular column or set of columns.

INFORMATION_SCHEMA

The name of the database that provides a query interface to the CrpssDB data dictionary. (This name is defined by the ANSI SQL standard.) To examine information (metadata) about the database, you can query tables such as INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.COLUMNS, rather than using SHOW commands that produce unstructured output.

MVCC

MVCC(Multi-Version Concurrency Control) is a concurrency control mechanism in many databases. It processes the memory read by transactions to achieve concurrent access to DB, thereby avoiding blocking caused by conflicts between concurrent reads and writes.

OLTP

Acronym for “Online Transaction Processing”. A database system, or a database application, that runs a workload with many transactions, with frequent writes as well as reads, typically affecting small amounts of data at a time.

SQL

The Structured Query Language that is standard for performing database operations. Often divided into the categories DDL, DML, and queries.

Comments

CrossDB
Super High-performance Embedded and Server RDBMS✨

Quick Learn🧭 Benchmark 📜

CrossDB

CrossDB
Super High-performance Embedded and Server RDBMS✨

Quick Learn🧭 Benchmark 📜

  • 🌌 Simple


    CrossDB is easy to install and deploy. It has zero external dependencies and runs in-process in its host application or as a single binary with tiny footprint.

CrossDB

Introduction

CrossDB is a super high-performance embedded and server RDBMS. It's developed for high performance scenarios with main memory can hold whole DB.

Features

  • Support Multiple OS Platforms: Linux/Windows/MacOS/FreeBSD etc
  • Support Multiple CPU ARCH: X86/ARM/PPC/MIPS etc
  • Support OnDisk/In-memory/RamDisk/Hybrid Storage
  • Support Standard RDBMS model
  • Support MySQL like SQL
  • Support Multiple databases
  • Support Primary Key and multiple Secondary Indexes
  • Support HASH and RBTREE(TBD) Index
  • Support Multi-columns Index
  • Support Exact Match, Leftmost Match(TBD), Range Match(TBD)
  • Support Standard ACID Transaction (begin/commit/rollback)
  • Support WAL for OnDisk storage(TBD)
  • Support Multiple Threads and Multiple Processes Access
  • Support Table level read-write lock
  • Support Reader-Writer MVCC
  • Support Embedded CrossDB Shell
  • Support Multi-Statments APIs
  • Support Prepared Statments APIs
  • Super High Performance
  • Very Simple: Simple header and library file
  • Zero Config: no complex config, real out-of-the-box

Use Cases

  • You can use CrossDB In-Memory DB to manage Process Runtime Data to replace STL or hand-wrting data structures.
  • You can use CrossDB RamDisk DB to support Process Restartability, In-Service Software Upgrade(ISSU) easily.
  • You can use CrossDB OnDisk DB to store data on Disk/Flash/SDD.
  • You can use CrossDB to work as a super fast cache DB.
CrossDB

Introduction

CrossDB is a super high-performance embedded and server RDBMS. It's developed for high performance scenarios with main memory can hold whole DB.

Features

  • Support Multiple OS Platforms: Linux/Windows/MacOS/FreeBSD etc
  • Support Multiple CPU ARCH: X86/ARM/PPC/MIPS etc
  • Support OnDisk/In-memory/RamDisk/Hybrid Storage
  • Support Standard RDBMS model
  • Support MySQL like SQL
  • Support Multiple databases
  • Support Primary Key and multiple Secondary Indexes
  • Support HASH and RBTREE(TBD) Index
  • Support Multi-columns Index
  • Support Exact Match, Leftmost Match(TBD), Range Match(TBD)
  • Support Standard ACID Transaction (begin/commit/rollback)
  • Support WAL for OnDisk storage(TBD)
  • Support Multiple Threads and Multiple Processes Access
  • Support Table level read-write lock
  • Support Reader-Writer MVCC
  • Support Embedded CrossDB Shell
  • Support Multi-Statments APIs
  • Support Prepared Statments APIs
  • Super High Performance
  • Very Simple: Simple header and library file
  • Zero Config: no complex config, real out-of-the-box

Use Cases

  • You can use CrossDB In-Memory DB to manage Process Runtime Data to replace STL or hand-wrting data structures.
  • You can use CrossDB RamDisk DB to support Process Restartability, In-Service Software Upgrade(ISSU) easily.
  • You can use CrossDB OnDisk DB to store data on Disk/Flash/SDD.
  • You can use CrossDB to work as a super fast cache DB.
CrossDB

Logical Replication

Create Replication

CREATE REPLICATION rep_name [replication_option] ...
-
-replication_option:
-    HOST = xx 
-  | PORT = xx 
-  | USER = xx 
-  | PASSWORD = xx 
-  | DB = (dbname,...)
-  | INITSYNC = {true | false}
-  | AUDIT = {true | false}
-  | SCHEMA = {true | false}
-  | ENABLE = {true | false}
-

Change Replication

ALTER REPLICATION rep_name [replication_option] ...
-
-replication_option:
-    ENABLE = {true | false}
-  | USER = xx 
-  | PASSWORD = xx 
-

Drop Replication

DROP REPLICATION [IF EXISTS] rep_name
-

Show Replication

SHOW REPLICATION
-

Comments

\ No newline at end of file diff --git a/replication/pubsub/index.html b/replication/pubsub/index.html deleted file mode 100755 index 5906bdf..0000000 --- a/replication/pubsub/index.html +++ /dev/null @@ -1,56 +0,0 @@ - PUBSUB - CrossDB

PUBSUB

Create Subscription

CREATE SUBSCRIPTION sub_name [subscripton_option] ...
-
-subscripton_option:
-    HOST = xx 
-  | PORT = xx 
-  | USER = xx 
-  | PASSWORD = xx 
-  | SRCDB = db_name
-  | DB = db_name
-  | INITSYNC = {FULL | SCHEMA | DATA | NONE}
-  | OFFSET = 0, -1
-  | AUDIT = {true | false}
-  | ENABLE = {true | false}
-
-    FILTERS (select * from xxx where xx into mytable)
-
-  | TABLES = (tbl_name,...)
-

Change Replication

ALTER REPLICATION rep_name [replication_option] ...
-
-replication_option:
-    ENABLE = {true | false}
-  | USER = xx 
-  | PASSWORD = xx 
-

Drop Replication

DROP REPLICATION [IF EXISTS] rep_name
-

Show Replication

SHOW REPLICATION
-

Comments

\ No newline at end of file diff --git a/replication/replication/index.html b/replication/replication/index.html deleted file mode 100755 index 43e0068..0000000 --- a/replication/replication/index.html +++ /dev/null @@ -1,66 +0,0 @@ - Replication - CrossDB

Replication

Create Replication

CREATE REPLICATION rep_name [replication_option] ...
-
-replication_option:
-    HOST = xx 
-  | PORT = xx 
-  | USER = xx 
-  | PASSWORD = xx 
-  | DB = db_name
-  | TABLES = (tbl_name,...)
-  | TODB = db_name
-  | INITSYNC = {FULL | SCHEMA | DATA | NONE}
-  | AUDIT = {true | false}
-  | ENABLE = {true | false}
-
-    FILTERS (select * from xxx where xx into mytable)
-

Change Replication

ALTER REPLICATION rep_name [replication_option] ...
-
-replication_option:
-    ENABLE = {true | false}
-  | OFFSET = 0, -1
-  | USER = xx 
-  | PASSWORD = xx 
-

Drop Replication

DROP REPLICATION [IF EXISTS] rep_name
-

Show Replication

SHOW REPLICSTATUS
-    show secondary status
-
-SHOW REPLICATION
-    show my replica status
-
-role: master/slave
-
-SHOW MASTER STATUS
-
-SHOW REPLICA STATUS [FOR CHANNEL channel]
-SHOW SLAVE STATUS [FOR CHANNEL channel]
-

Comments

\ No newline at end of file diff --git a/search/search_index.json b/search/search_index.json index cd5cbb8..7d1f138 100755 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":"

CrossDBSuper High-performance Embedded and Server RDBMS\u2728

Quick Learn\ud83e\udded Benchmark \ud83d\udcdc

  • \ud83c\udf0c Simple

    CrossDB is easy to install and deploy. It has zero external dependencies and runs in-process in its host application or as a single binary with tiny footprint.

  • \u267b\ufe0f Portable

    CrossDB runs on Linux, macOS, Windows, BSD and all popular hardware architectures. It has idiomatic client APIs for major programming languages.

    Read more

  • \ud83d\ude80 Super Fast

    The hand-writing SQL parser and memory-oriented design architecture make the database run SQL at blazing speed.

  • \u26fd Hybrid Storage Mode

    CrossDB supports On-Disk database and In-Memory database(IMDB). It can also support Hybrid mode with some tables On-Disk and some In-Memory.

  • \ud83d\udd31 MySQL-like SQL

    Most SQL commands are similar with MySQL.

    Read more

  • \ud83d\udcae Server Mode

    Besides the Embedded RDBMS mode, CrossDB can also run in Embedded Server mode or run CrossDB as Standalone RDBMS server.

CSQL
xdb_res_t   *pRes;\nxdb_row_t   *pRow;\nxdb_conn_t  *pConn = xdb_open (\":memory:\");\npRes = xdb_exec (pConn, \"CREATE TABLE student (id INT, name CHAR(16), age INT, class CHAR(16), score INT)\");\npRes = xdb_exec (pConn, \"INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)\");\npRes = xdb_exec (pConn, \"SELECT * from student\");\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->row_meta, pRow);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\npRes = xdb_exec (pConn, \"UPDATE student set age=9 WHERE id = 2\");\npRes = xdb_exec (pConn, \"DELETE FROM student WHERE id = 3\");\nxdb_close (pConn);\n
CREATE TABLE student (id INT, name CHAR(16), age INT, class CHAR(16), score INT);\nINSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95);\nSELECT * FROM student;\nSELECT * FROM student WHERE id = 1;\nUPDATE student set age=9 WHERE id = 2;\nDELETE FROM student WHERE id = 3;\n

Note

This project was redesigned and rewritten from scratch. It's still in early development stage, so please DO NOT use in your project now.

"},{"location":"CHANGELOG/","title":"Change Log","text":""},{"location":"CHANGELOG/#060-2024-08-18","title":"0.6.0 (2024-08-18)","text":"
  • Initial refactor release

  • This project was redesigned and rewritten from scratch for over one year

  • Standard RDBMS model
  • New SQL APIs which can support more language
  • MySQL style SQL and shell, which will be easy to study.
"},{"location":"CHANGELOG/#050-2023-06-26","title":"0.5.0 (2023-06-26)","text":"

Features

  • CrossDB command line tool crossdb-cli is released
  • Optimize insert/update/query/delete performance
  • Add new API cross_matchCreate and cross_matchFree
  • DML APIs supports cross_fields_h and cross_match_h

Bug Fixes

"},{"location":"CHANGELOG/#040-2023-06-20","title":"0.4.0 (2023-06-20)","text":"

Features

  • Support FreeBSD(X64)
  • Optimize insert/update/query/delete performance
  • Add new API cross_fieldsCreate and cross_fieldsFree

Bug Fixes

"},{"location":"CHANGELOG/#030-2023-06-13","title":"0.3.0 (2023-06-13)","text":"

Features

  • Support MacOS (X64 and ARM64)
  • Change CROSS_DB_XXX to CROSS_XXX

Bug Fixes

  • cross_dbTblCreate flags CROSS_DB_RBTREE doesn't create Primary Key Index type correctly
"},{"location":"CHANGELOG/#020-2023-06-07","title":"0.2.0 (2023-06-07)","text":"

Features

  • Support Windows
  • Support Linux ARM64

Bug Fixes

"},{"location":"CHANGELOG/#010-2023-06-03","title":"0.1.0 (2023-06-03)","text":"
  • Initial release

Features

Bug Fixes

"},{"location":"community/","title":"Community","text":""},{"location":"community/#report-bugs","title":"Report Bugs","text":"

Github Issues

"},{"location":"community/#require-fetures","title":"Require Fetures","text":"

Github Fetures

"},{"location":"community/#discussion","title":"Discussion","text":"

Github Discussion

"},{"location":"community/#contribution","title":"Contribution","text":"

In order to keep CrossDB quality and high-performance, this project does not accept patches. If you would like to suggest a change and you include a patch as a proof-of-concept, that would be great. However, please do not be offended if we rewrite your patch from scratch.

Following contributions are welcome:

  • Language bindings: Python, Java, Go, CSharp, Javascript, PHP, etc
  • Test and report bugs
"},{"location":"faq/","title":"FAQ","text":""},{"location":"faq/#why-is-crossdb-so-fast","title":"Why is CrossDB so fast?","text":"
  • Use memory map to access DB data directly (so your DB must less than the main memory to get highest speed).
  • Use high-performance hash as the main index, and use the super fast wyhash as the hash function.
  • Hand-written SQL parser which is more than 10X faster than Flex/Bison parser tools.
  • High-performance read-write lock and multi-core optimization.
  • Execute multiple SQL statements in one API, which will imporve client-server DB performance dramatically.
  • High-efficient client-server protocols.
  • Avoid memory allocation/free as much as possible.
  • High-performance implementation code
"},{"location":"glossary/","title":"Glossary","text":""},{"location":"glossary/#acid","title":"ACID","text":"

ACID refers to the four key properties of a transaction: atomicity, consistency, isolation, and durability. Each of these properties is described below.

Atomicity means that either all the changes of an operation are performed, or none of them are.

Consistency means that transactions always bring the database from one consistent state to another.

Isolation means that a transaction in process is invisible to other transactions until it completes. This allows concurrent transactions to read and write data without sacrificing consistency.

Durability means that once a transaction is committed, it remains committed even in the event of a system failure.

"},{"location":"glossary/#crud","title":"CRUD","text":"

Acronym for \u201ccreate, read, update, delete\u201d, a common sequence of operations in database applications. Often denotes a class of applications with relatively simple database usage (basic DDL, DML and query statements in SQL) that can be implemented quickly in any language.

"},{"location":"glossary/#ddl","title":"DDL","text":"

Data definition language, a set of SQL statements for manipulating the database itself rather than individual table rows. Includes all forms of the CREATE, ALTER, and DROP statements. DDL statements automatically commit the current transaction; they cannot be rolled back.

"},{"location":"glossary/#dml","title":"DML","text":"

Data manipulation language, a set of SQL statements for performing SELECT, INSERT, UPDATE, and DELETE operations.

"},{"location":"glossary/#hash-index","title":"Hash Index","text":"

A type of index intended for queries that use equality operators, rather than range operators such as greater-than or BETWEEN.

"},{"location":"glossary/#imdb","title":"IMDB","text":"

IMDB(In-Memory database) is a type of database system that maintains data in memory, to avoid overhead due to disk I/O and translation between disk blocks and memory areas.

"},{"location":"glossary/#index","title":"Index","text":"

A data structure that provides a fast lookup capability for rows of a table, typically by forming a tree structure (B-tree) representing all the values of a particular column or set of columns.

"},{"location":"glossary/#information_schema","title":"INFORMATION_SCHEMA","text":"

The name of the database that provides a query interface to the CrpssDB data dictionary. (This name is defined by the ANSI SQL standard.) To examine information (metadata) about the database, you can query tables such as INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.COLUMNS, rather than using SHOW commands that produce unstructured output.

"},{"location":"glossary/#mvcc","title":"MVCC","text":"

MVCC(Multi-Version Concurrency Control) is a concurrency control mechanism in many databases. It processes the memory read by transactions to achieve concurrent access to DB, thereby avoiding blocking caused by conflicts between concurrent reads and writes.

"},{"location":"glossary/#oltp","title":"OLTP","text":"

Acronym for \u201cOnline Transaction Processing\u201d. A database system, or a database application, that runs a workload with many transactions, with frequent writes as well as reads, typically affecting small amounts of data at a time.

"},{"location":"glossary/#sql","title":"SQL","text":"

The Structured Query Language that is standard for performing database operations. Often divided into the categories DDL, DML, and queries.

"},{"location":"intro/","title":"Introduction","text":"

CrossDB is a super high-performance embedded and server RDBMS. It's developed for high performance scenarios with main memory can hold whole DB.

"},{"location":"intro/#features","title":"Features","text":"
  • Support Multiple OS Platforms: Linux/Windows/MacOS/FreeBSD etc
  • Support Multiple CPU ARCH: X86/ARM/PPC/MIPS etc
  • Support OnDisk/In-memory/RamDisk/Hybrid Storage
  • Support Standard RDBMS model
  • Support MySQL like SQL
  • Support Multiple databases
  • Support Primary Key and multiple Secondary Indexes
  • Support HASH and RBTREE(TBD) Index
  • Support Multi-columns Index
  • Support Exact Match, Leftmost Match(TBD), Range Match(TBD)
  • Support Standard ACID Transaction (begin/commit/rollback)
  • Support WAL for OnDisk storage(TBD)
  • Support Multiple Threads and Multiple Processes Access
  • Support Table level read-write lock
  • Support Reader-Writer MVCC
  • Support Embedded CrossDB Shell
  • Support Multi-Statments APIs
  • Support Prepared Statments APIs
  • Super High Performance
  • Very Simple: Simple header and library file
  • Zero Config: no complex config, real out-of-the-box
"},{"location":"intro/#use-cases","title":"Use Cases","text":"
  • You can use CrossDB In-Memory DB to manage Process Runtime Data to replace STL or hand-wrting data structures.
  • You can use CrossDB RamDisk DB to support Process Restartability, In-Service Software Upgrade(ISSU) easily.
  • You can use CrossDB OnDisk DB to store data on Disk/Flash/SDD.
  • You can use CrossDB to work as a super fast cache DB.
"},{"location":"about/buy/","title":"How to Buy","text":""},{"location":"about/privacy/","title":"Privacy Notice","text":""},{"location":"about/privacy/#introduction","title":"Introduction","text":"

CrossDB Software has designed its website so that, in general, you can browse the CrossDB website without being asked for any personal information. Exceptions to this are when you specifically ask for information, request an evaluation copy of our software or download CrossDB trial software.

This policy covers how CrossDB Software treats personal information that CrossDB may collect and receive via the CrossDB website. Your use of the CrossDB website constitutes acceptance of and agreement with the CrossDB Software Privacy Policy. CrossDB reserves the right to change the CrossDB Software Privacy Policy at any time without notice.

"},{"location":"about/privacy/#information-collection-and-use","title":"Information collection and use","text":"

CrossDB collects personal information when you request for information, request an evaluation of our software or when you download trial software. This information includes information about you such as name, business name and address, telephone and fax numbers, email address, operating system, and hardware environment. Providing information is voluntary. You may provide this information by filling out an on-line form, by email or other communication to CrossDB. However, you may not receive the product information, software evaluation or downloads if you choose not to provide the requested information.

CrossDB Software's use of the information you provided will be to send you the information that you requested. CrossDB Software may also use the information to provide you with additional information about our products and services or market research. The information may be used to follow up with you regarding information supplied, software you downloaded or evaluated.

CrossDB does not sell information collected from users of CrossDB website to other organizations. CrossDB may share the information collected with its subsidiaries and its affiliates such as partners and distributors.

"},{"location":"about/privacy/#general-information","title":"General Information","text":"

CrossDB web servers record standard information about CrossDB Web accesses such as IP addresses, your server name, browser type, etc. when you visit our website. CrossDB uses this for information about usage at CrossDB Software's website. The information submitted to CrossDB Software via the Web may be processed, stored and used outside the country where it was submitted.

Links to third party websites are provided for your convenience. By using these links, you will no longer be on the CrossDB Software website and the CrossDB Software Privacy Policy will no longer apply.

"},{"location":"about/privacy/#contact-us","title":"Contact us","text":"

If you have any question about the information you provided to us or about the CrossDB Software Privacy Policy, please contact us at support@crossdb.org

"},{"location":"about/refund/","title":"Refund Policy","text":"

Thank you for using CrossDB Database! We don't offer refund, please try it first then subscribe the product by month or year. You can cancel the subscription anytime as you want.

"},{"location":"about/terms/","title":"Terms of Service","text":"

CrossDB provides this Website for your information and use, subject to the terms set forth below. By accessing this Website, you agree to accept the following terms.

"},{"location":"about/terms/#general-terms","title":"General terms","text":"

In no event will CrossDB be liable for any damages including, without limitation, indirect, incidental, consequential, special or exemplary damages, that arise out of or relate to the use of or inability to use the CrossDB Website, even if CrossDB has been advised of the possibility of such damages.

Any and all information provided on CrossDB\u2019s Website is provided \u201cas is,\u201d with no warranty as to accuracy or content.

CrossDB does not adopt or endorse the views of any third party Websites linked to or from the CrossDB Website.

CrossDB reserves the right to change, modify, add or remove any of these terms at any time.

"},{"location":"admin/data-backup/","title":"Data Backup","text":""},{"location":"admin/data-backup/#dump-with-dump-statement","title":"Dump with DUMP statement","text":"
  • Dump everything
SQLC
DUMP DATABASE school INTO 'school.sql';\n
xdb_exec (pConn, \"DUMP DATABASE school INTO 'school.sql'\");\n
  • Dump schema only
SQLC
DUMP DATABASE school NODATA INTO 'school.sql';\n
xdb_exec (pConn, \"DUMP DATABASE school NODATA INTO 'school.sql'\");\n
  • Dump data only
SQLC
DUMP DATABASE school NODROP NOCREATE INTO 'school.sql';\n
xdb_exec (pConn, \"DUMP DATABASE school NODROP NOCREATE INTO 'school.sql'\");\n
"},{"location":"admin/data-backup/#dump-with-crossdb-tool","title":"Dump with crossdb tool","text":"
  • Dump everything
crossdb -e \"DUMP DATABASE\" school > school.sql\n
crossdb -e \"DUMP DATABASE school INTO 'school.sql'\" school\n
  • Dump schema only
crossdb -e \"DUMP DATABASE school NODATA INTO 'school.sql'\" school\n
  • Dump data only
crossdb -e \"DUMP DATABASE school NODROP NOCREATE INTO 'school.sql'\" school\n
"},{"location":"admin/data-restore/","title":"Data Restore","text":""},{"location":"admin/data-restore/#load-with-source-statement","title":"Load with SOURCE statement","text":"SQLC
SOURCE 'school.sql'\n
xdb_exec (pConn, \"SOURCE 'school.sql'\");\n
"},{"location":"admin/data-restore/#load-with-crossdb-tool","title":"Load with CrossDB tool","text":"
crossdb school < school.sql\n
cat school.sql | crossdb school\n
crossdb -e \"SOURCE 'school.sql'\" school\n
"},{"location":"admin/shell/","title":"CrossDB Shell","text":""},{"location":"admin/shell/#crossdb-tool","title":"CrossDB tool","text":"

This tool can

  • Open and operate local database
  • Connect and operate remote database
  • Work as standalone database server
$ crossdb -h\ncrossdb: option requires an argument -- 'h'\nUsage: xdb-cli [OPTIONS] [[path/]db_name]\n  -h                        Show this help\n  -S                        Server: Start in server mode\n  -h <ip>                   IP address to bind to or connect to\n  -P <port>                 Port to listen or connect\n  -D <datadir>              Server: Data directory to store databases\n  -u <user>                 Client user\n  -p                        Client password\n  -e <sql>                  Execute SQL statements and quite\n
"},{"location":"admin/shell/#open-db","title":"Open DB","text":"
crossdb school\n
"},{"location":"admin/shell/#open-db-and-execute-command","title":"Open DB and execute command","text":"
crossdb -e 'SELECT * FROM student WHERE id=1; SELECT * FROM student WHERE age=10' school\n
"},{"location":"admin/shell/#embedded-shell","title":"Embedded shell","text":"

You program can enter interactive shell use the SHELL statement.

SQLC
SHELL\n
xdb_exec (pConn, \"SHELL\");\n
"},{"location":"admin/shell/#auto-completion","title":"Auto completion","text":"

Use TAB to do auto completion for SQL statements, keywords, db name, table name, field name, etc.

XDB> <TAB>\nCREATE      Create database, table, index, etc\nDROP        Drop database, table, index, etc\nALTER       Alter database, table, index, etc\nSELECT      Select rows from table\nINSERT      Insert rows into table\nUPDATE      Update rows in table\nDELETE      Delete rows from table\nBEGIN       Begin transaction\nCOMMIT      Commit transaction\nROLLBACK    Rollback transaction\nUSE         Switch Databae\nSHOW        Show database, table, index, etc\nDESCRIBE    Show Table Schema\nEXPLAIN     Show SELECT statement index selection\nSET         Config parameters\nOPEN        Open database\nCLOSE       Close database\nDUMP        Dump database\nSOURCE      Load SQL file\nSHELL       Enter interactive shell\nHELP        Help\n
XDB> S <TAB>\nSELECT    Select rows from table\nSHOW      Show database, table, index, etc\nSET       Config parameters\nSOURCE    Load SQL file\nSHELL     Enter interactive shell\nXDB> SE <TAB>\nSELECT    Select rows from table\nSET       Config parameters\nXDB> SEL <TAB>\nXDB> SELECT\n
XDB> SELECT <TAB>\nXDB> SELECT * <TAB>\nXDB> SELECT * FROM <TAB>\nstudent    teacher    book\nXDB> SELECT * FROM s<TAB>\nXDB> SELECT * FROM student\n
XDB> SELECT * FROM student <TAB>\nWHERE       ORDER BY    LIMIT       OFFSET      AND         id          name        age         class       score\ninfo\nXDB> SELECT * FROM student WHERE i <TAB>\nid      info\n
XDB> SHOW  <TAB>\nDATABASES    TABLES       INDEXES      COLUMNS      CREATE\n
"},{"location":"client/api-c/","title":"C APIs","text":""},{"location":"client/api-c/#apis-list","title":"APIs List","text":"API Descritpion xdb_conn_t* xdb_open (const char *path) Open a connection void xdb_close (xdb_conn_t *pConn) Close a connection xdb_res_t* xdb_exec (xdb_conn_t* pConn, const char *sql) Execute SQL statement xdb_res_t* xdb_pexec (xdb_conn_t* pConn, const char *sql, ...) Execute formatted SQL statement xdb_res_t* xdb_next_result (xdb_conn_t *pConn) Get next SQL statement result bool xdb_more_result (xdb_conn_t* pRes) Check is there more result void xdb_free_result (xdb_res_t* pRes) Free result set xdb_col_t* xdb_column_meta (uint64_t meta, uint16_t iCol) Fetch one row xdb_row_t* xdb_fetch_row (xdb_res_t* pRes) Fetch one row int xdb_column_int (uint64_t meta, void *pRow, uint16_t iCol) Get int column from row float xdb_column_float (uint64_t meta, void *pRow, uint16_t iCol) Get float/double column from row const char * xdb_column_str (uint64_t meta, void *pRow, uint16_t iCol) Get string column from row xdb_stmt_t* xdb_stmt_prepare (xdb_conn_t* pConn, const char *sql) Prepare statement xdb_ret xdb_bind_int (xdb_stmt_t *pStmt, uint16_t para_id, int val) Bind int value xdb_ret xdb_bind_float (xdb_stmt_t *pStmt, uint16_t para_id, float val) Bind float value xdb_ret xdb_bind_str (xdb_stmt_t *pStmt, uint16_t para_id, const char *str) Bind string value xdb_res_t* xdb_stmt_exec (xdb_stmt_t *pStmt) Execute prepared SQL statement void xdb_stmt_close (xdb_stmt_t *pStmt) Free prepared SQL statement xdb_ret xdb_begin (xdb_conn_t* pConn) Begin transaction xdb_ret xdb_commit (xdb_conn_t* pConn) Commit transaction xdb_ret xdb_rollback (xdb_conn_t* pConn) Rollback transaction int xdb_print_row (uint64_t meta, void *pRow, int format) Print row to console const char * xdb_errmsg (xdb_res_t *pRes) Get error/information message const char * xdb_version () Get CrossDB version string"},{"location":"client/api-c/#xdb_open","title":"xdb_open","text":"

Open a connection and create/open a Database.

xdb_conn_t*\nxdb_open (const char *path);\n\n// TBD\nxdb_conn_t*\nxdb_open2 (const char *path, uint32_t flags);\n
  • If path is :memory: will create or open a memory database, else create or open a on-disk database. This database will be the default DB of this connection.
  • If path is NULL: Only open a connection. User has to use OPEN DATABASE '[path/]db_name' or CREATE DATABASE '[path/]db_name' or USE DATABASE db_name.
  • One thread can use only one connection. One connection can only be used by one thread
  • All opened databases are shared with all opened connections, and they can USE DATABASE db_name to switch connection default DB.
"},{"location":"client/api-c/#xdb_close","title":"xdb_close","text":"

Create a connection.

void\nxdb_close (xdb_conn_t *pConn);\n
"},{"location":"client/api-c/#xdb_exec","title":"xdb_exec","text":"

Execute SQL statement and return result set.

xdb_res_t*\nxdb_exec (xdb_conn_t* pConn, const char *sql);\n\nxdb_res_t*\nxdb_exec2 (xdb_conn_t *pConn, const char *sql, int len);\n
  • A valid xdb_res_t pointer is returned always.
  • row count: pRes->row_count
  • column count: pRes->col_count
  • column meta: pRes->row_meta, use xdb_col_t* xdb_column_meta (uint64_t meta, uint16_t iCol) to get column meta.
"},{"location":"client/api-c/#xdb_pexec","title":"xdb_pexec","text":"

Execute formatted SQL statement and return result set.

xdb_res_t*\nxdb_pexec (xdb_conn_t *pConn, const char *sql, ...);\n
  • A valid xdb_res_t pointer is returned always.

Note

If sql contains %, should use escape \\%.

"},{"location":"client/api-c/#xdb_next_result","title":"xdb_next_result","text":"

Get next SQL statement result

xdb_res_t*\nxdb_next_result (xdb_conn_t *pConn);\n

"},{"location":"client/api-c/#xdb_more_result","title":"xdb_more_result","text":"

Check is there more result

bool\nxdb_more_result (xdb_conn_t *pConn);\n

"},{"location":"client/api-c/#xdb_free_result","title":"xdb_free_result","text":"

Free result set

void\nxdb_free_result (xdb_res_t *pRes);\n

Note

You only need to call xdb_free_result for statements more than 0 rows.

"},{"location":"client/api-c/#xdb_column_meta","title":"xdb_column_meta","text":"

Get column meta.

const xdb_col_t* \nxdb_column_meta (uint64_t meta, uint16_t iCol)\n

Note

This is an inline function.

"},{"location":"client/api-c/#xdb_fetch_row","title":"xdb_fetch_row","text":"

Fetch one row and return row list array.

xdb_row_t*\nxdb_fetch_row (xdb_res_t *pRes);\n
"},{"location":"client/api-c/#xdb_column_int","title":"xdb_column_int","text":"

Get int column from row.

int \nxdb_column_int (uint64_t meta, void *pRow, uint16_t iCol);\n\nint64_t \nxdb_column_int64 (uint64_t meta, void *pRow, uint16_t iCol);\n

Note

If you know the detailed format, you can access the pointer directly. *(int8_t*)pVal[iCol], *(int16_t*)pVal[iCol], *(int32_t*)pVal[iCol], *(int64_t*)pVal[iCol]

"},{"location":"client/api-c/#xdb_column_float","title":"xdb_column_float","text":"

Get float column from row.

float\nxdb_column_float (uint64_t meta, xdb_row_t *pRow, uint16_t iCol);\n\ndouble \nxdb_column_double (uint64_t meta, void *pRow, uint16_t iCol);\n

Note

If you know the detailed format, you can access the pointer directly. *(float*)pVal[iCol], *(double*)pVal[iCol]

"},{"location":"client/api-c/#xdb_column_str","title":"xdb_column_str","text":"

Get string column from row.

const char*\nxdb_column_str (uint64_t meta, xdb_row_t *pRow, uint16_t iCol);\n\nconst char*\nxdb_column_str2 (uint64_t meta, xdb_row_t *pRow, uint16_t iCol, int *pLen);\n

Note

You can access the pointer directly: *(const char*)pVal[iCol], get the length *(uint16_t*)(pVal[iCol]-2)

"},{"location":"client/api-c/#xdb_stmt_prepare","title":"xdb_stmt_prepare","text":"
xdb_stmt_t* \nxdb_stmt_prepare (xdb_conn_t* pConn, const char *sql);\n
"},{"location":"client/api-c/#xdb_bind_int","title":"xdb_bind_int","text":"

Binds an int value to the prepared statement at the specified parameter index.

xdb_ret\nxdb_bind_int (xdb_stmt_t *pStmt, uint16_t para_id, int val);\n\nxdb_ret\nxdb_bind_int64 (xdb_stmt_t *pStmt, uint16_t para_id, int64_t val);\n
"},{"location":"client/api-c/#xdb_bind_float","title":"xdb_bind_float","text":"

Binds a double value to the prepared statement at the specified parameter index.

xdb_ret\nxdb_bind_float (xdb_stmt_t *pStmt, uint16_t para_id, float val);\n\nxdb_ret\nxdb_bind_double (xdb_stmt_t *pStmt, uint16_t para_id, double val)\n
"},{"location":"client/api-c/#xdb_bind_str","title":"xdb_bind_str","text":"

Binds a string value to the prepared statement at the specified parameter index.

xdb_ret\nxdb_bind_str (xdb_stmt_t *pStmt, uint16_t id, const char *str, int len);\n\nxdb_ret\nxdb_bind_str2 (xdb_stmt_t *pStmt, uint16_t para_id, const char *str, int len)\n
"},{"location":"client/api-c/#xdb_stmt_exec","title":"xdb_stmt_exec","text":"

Execute a prepared statement.

xdb_res_t*\nxdb_stmt_exec (xdb_stmt_t *pStmt);\n
"},{"location":"client/api-c/#xdb_stmt_close","title":"xdb_stmt_close","text":"

Close a prepared statement.

void\nxdb_stmt_close (xdb_stmt_t *pStmt);\n
"},{"location":"client/api-c/#xdb_begin","title":"xdb_begin","text":"

Begin a transaction.

xdb_ret\nxdb_begin (xdb_conn_t* pConn);\n
  • For embedded local connection, always return XDB_OK.
"},{"location":"client/api-c/#xdb_commit","title":"xdb_commit","text":"

Commit a transaction.

xdb_ret\nxdb_commit (xdb_conn_t* pConn);\n
  • For embedded local connection, always return XDB_OK.
"},{"location":"client/api-c/#xdb_rollback","title":"xdb_rollback","text":"

Rollback a transaction.

xdb_ret\nxdb_rollback (xdb_conn_t* pConn);\n
  • For embedded local connection, always return XDB_OK.
"},{"location":"client/api-c/#xdb_print_row","title":"xdb_print_row","text":"

Print row to console.

int \nxdb_print_row (uint64_t meta, xdb_row_t *pRow, int format);\n
"},{"location":"client/api-c/#xdb_errmsg","title":"xdb_errmsg","text":"

Get error/information message in result.

const char *\nxdb_errmsg (xdb_res_t *pRes);\n
"},{"location":"client/api-c/#xdb_version","title":"xdb_version","text":"

Get CrossDB version string.

const char*\nxdb_version();\n
"},{"location":"client/api-c/#types","title":"Types","text":""},{"location":"client/api-c/#xdb_errno_e","title":"xdb_errno_e","text":"

Error Code

typedef enum {\n    XDB_OK,\n    XDB_ERROR,\n    XDB_E_PARAM,\n    XDB_E_STMT,\n    XDB_E_NODB,\n    XDB_E_NOTFOUND,\n    XDB_E_EXISTS,\n    XDB_E_FULL,\n    XDB_E_CONSTRAINT,\n    XDB_E_AUTH,\n    XDB_E_MEMORY,\n    XDB_E_FILE,\n    XDB_E_SOCK,\n} xdb_errno_e;\n

"},{"location":"client/api-c/#xdb_type_t","title":"xdb_type_t","text":"

Data Types

typedef enum {\n    XDB_TYPE_NULL       = 0,  // 1 bit\n    XDB_TYPE_TINYINT    = 1,  // 1 byte\n    XDB_TYPE_SMALLINT   = 2,  // 2 bytes\n    XDB_TYPE_INT        = 3,  // 4 bytes\n    XDB_TYPE_BIGINT     = 4,  // 8 bytes\n    XDB_TYPE_UTINYINT   = 5,  // 1 byte\n    XDB_TYPE_USMALLINT  = 6,  // 2 bytes\n    XDB_TYPE_UINT       = 7,  // 4 bytes\n    XDB_TYPE_UBIGINT    = 8,  // 8 bytes\n    XDB_TYPE_FLOAT      = 9,  // 4 bytes\n    XDB_TYPE_DOUBLE     = 10, // 8 bytes\n    XDB_TYPE_TIMESTAMP  = 11, // 8 bytes\n    XDB_TYPE_CHAR       = 12, // fixed-length string(at most 65535 byte)\n    XDB_TYPE_BINARY     = 13, // fixed-length binary(at most 65535 byte)\n    XDB_TYPE_VCHAR      = 14, // varied-length string(at most 65535 byte)\n    XDB_TYPE_VBINARY    = 15, // varied-length binary(at most 65535 byte)\n    XDB_TYPE_MAX        = 21\n} xdb_type_t;\n

"},{"location":"client/api-c/#structures","title":"Structures","text":""},{"location":"client/api-c/#xdb_res_t","title":"xdb_res_t","text":"

Result Set

typedef struct xdb_res_t {\n    uint32_t    len_type;       // MSB 4bit are type xdb_restype_t\n    uint16_t    errcode;        // 4\n    uint16_t    status;         // 6 xdb_status_t\n\n    uint32_t    meta_len;       // 8\n    uint16_t    col_count;      // 12\n    uint8_t     stmt_type;      // 14 SQL type(create/delete/drop/show/select/delete/update...)\n    uint8_t     rsvd;\n\n    uint64_t    row_count;      // 2*8 SELECT/SHOW\n    uint64_t    affected_rows;  // 3*8 INSERT/UPDATE/DELETE\n    uint64_t    insert_id;      // 4*8 INSERT\n    uint64_t    col_meta;       // 5*8 xdb_meta_t, <ptr:ptr off: 0 following is meta>\n    uint64_t    row_data;       // 6*8 xdb_rowlist_t, ptr: base ptr or error str or infomation xdb_msg_t\n    uint64_t    data_len;       // 7*8\n} xdb_res_t;\n

"},{"location":"client/api-c/#xdb_msg_t","title":"xdb_msg_t","text":"

Return Message

typedef struct {\n    uint32_t    len_type;       // LSB 4bit are type\n    uint16_t    len;\n    char        msg[];\n} xdb_msg_t;\n

"},{"location":"client/api-c/#xdb_meta_t","title":"xdb_meta_t","text":"

Query Meta information

typedef struct {\n    uint32_t    len_type;       // LSB 4bit are type\n    uint16_t    col_count;      // 3*4\n    uint16_t    null_off;       // 3*4+2\n    uint16_t    row_size;\n    uint16_t    rsvd;\n    uint64_t    col_list;       // xdb_col_t list\n    xdb_col_t   cols[];\n} xdb_meta_t;\n

"},{"location":"client/api-c/#xdb_col_t","title":"xdb_col_t","text":"

Query Column information

typedef struct {\n    uint16_t    col_len;    // colum total len\n    uint8_t     col_type;   // xdb_type_t\n    uint8_t     col_rsvd;\n    uint32_t    col_off;\n    uint16_t    col_rsvd2;\n    uint8_t     col_nmlen;\n    char        col_name[];\n} xdb_col_t;\n

"},{"location":"client/api-c/#xdb_rowdat_t","title":"xdb_rowdat_t","text":"

Query row data information

typedef struct {\n    uint32_t    len_type;       // LSB 4bit are type\n    uint8_t     rowdat[];\n} xdb_rowdat_t;\n

"},{"location":"client/api-c/#xdb_rowlist_t","title":"xdb_rowlist_t","text":"
typedef uint64_t xdb_row_t; // xdb_rowdat_t\n\ntypedef struct {\n    uint32_t    rl_count;\n    uint32_t    rl_curid;\n    xdb_row_t   rl_pRows[];\n} xdb_rowlist_t;\n
"},{"location":"client/api-python/","title":"Python","text":"

TBD

"},{"location":"develop/connect/","title":"Connect to CrossDB","text":"
  • One thread can use only one connection. One connection can only be used by one thread.
  • All opened databases are shared with all opened connections, and they can USE DATABASE db_name to switch connection's default DB.
"},{"location":"develop/connect/#c-apis","title":"C APIs","text":"
  • Open a connection
xdb_conn_t *pConn = xdb_open (NULL);\n

Note

User has to use OPEN DATABASE '[path/]db_name' or CREATE DATABASE '[path/]db_name' or USE DATABASE db_name.

  • Open a connection and create a default memory database if not exist
xdb_conn_t *pConn = xdb_open (\":memory:\");\n
  • Open a connection and create a on-disk database school if not exist in current folder as the default database
xdb_conn_t *pConn = xdb_open (\"school\");\n
"},{"location":"develop/ddl/","title":"Data Model","text":""},{"location":"develop/ddl/#create-and-use-a-database","title":"Create and Use a Database","text":"SQLC
-- Create database in current folder\nCREATE DATABASE school;\n-- Create database in specified folder (must exist)\nCREATE DATABASE '/var/dbpath/school';\n-- Create in-memory database \nCREATE DATABASE test ENGINE=memory;\n
// Create database in current folder\nxdb_res_t *pRes = xdb_exec (pConn, \"CREATE DATABASE school\");\n// Create database in specified folder (must exist)\nxdb_res_t *pRes = xdb_exec (pConn, \"CREATE DATABASE '/var/dbpath/school'\");\n// Create in-memory database \nxdb_res_t *pRes = xdb_exec (pConn, \"CREATE DATABASE test ENGINE=memory\");\n
"},{"location":"develop/ddl/#create-a-table","title":"Create a Table","text":"SQLC
CREATE TABLE IF NOT EXISTS student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(256), INDEX (name));\nCREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(256), INDEX (name));\nCREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name));\n
xdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(256), INDEX (name))\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(256), INDEX (name))\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name))\");\n
"},{"location":"develop/ddl/#create-index","title":"Create Index","text":"SQLC
CREATE INDEX idx_name ON student (age);\nCREATE INDEX idx_name ON teacher (age);\nCREATE INDEX idx_name ON student (author);\n
xdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE INDEX idx_name ON student (age)\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE INDEX idx_name ON teacher (age)\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE INDEX idx_name ON student (author)\");\n
"},{"location":"develop/dml/","title":"Data Manipulation","text":""},{"location":"develop/dml/#insert-rows","title":"Insert Rows","text":"SQLC
INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95);\nINSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')\", 'He is a boy.\\nHe likes playing football.\\nWe all like him!');\n
pRes = xdb_exec (pConn, \"INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)\");\npRes = xdb_pexec (pConn, \"INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')\", \"He is a boy.\\nHe likes playing football.\\nWe all like him!\");\n
"},{"location":"develop/dml/#update-rows","title":"Update Rows","text":"

TBD

"},{"location":"develop/dml/#delete-rows","title":"Delete Rows","text":"

TBD

"},{"location":"develop/multi-stmts/","title":"Multi-Statements","text":"

TBD

"},{"location":"develop/prep-stmts/","title":"Prepared Statements","text":"

TBD

"},{"location":"develop/query/","title":"Query Rows","text":"

TBD

"},{"location":"develop/transaction/","title":"Transaction","text":""},{"location":"develop/transaction/#reader-writeer-mvcc","title":"Reader-Writeer MVCC","text":"

Current CrossDB uses table-level readwrite lock, only one writer connection thread can modify the table, other writer connection threads will be blocked. However the reader connection threads won't be blocked and they'll see the old values. When the writer connection change is committed, the new value is visible by these reader connections (read committed). In short writer before commit will not block readers to read old values

"},{"location":"develop/transaction/#auto-commit","title":"Auto-commit","text":"

TBD

"},{"location":"develop/transaction/#begin","title":"Begin","text":"

TBD

"},{"location":"develop/transaction/#commit","title":"Commit","text":"

TBD

"},{"location":"develop/transaction/#rollback","title":"Rollback","text":"

TBD

"},{"location":"get-started/bench/","title":"Example and Bench","text":""},{"location":"get-started/bench/#example","title":"Example","text":"
crossdb$ make example\n=== Select all 7 rows\nid=1 name='jack' age=10 class='3-1' score=90.000000 info=''\nid=2 name='tom' age=11 class='2-5' score=91.000000 info=''\nid=3 name='jack' age=11 class='1-6' score=92.000000 info=''\nid=4 name='rose' age=10 class='4-2' score=90.000000 info=''\nid=5 name='tim' age=10 class='3-1' score=95.000000 info=''\nid=6 name='Tony' age=10 class='3-1' score=95.000000 info='He is a boy.\nHe likes playing football.\nWe all like him!'\nid=7 name='Wendy' age=10 class='3-1' score=95.000000 info='She is a girl.\nShe likes cooking.\nWe all love her!'\n\n=== Update age = 9 for id = 2\nselect 1 rows\nid=2 name='tom' age=9 class='2-5' score=91.000000\nid=2 name='tom' age=9 class='2-5' score=91.000000\nid=2 name='tom' age=9 class='2-5' score=91.000000\n\n=== Delete id = 3\nselect 0 rows\n=== select 1 rows\nCOUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667\nCOUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667\nCOUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667\n\n=== Muti-Statements\nCOUNT(*)=6\nid=2 name='tom'\n   _____                   _____  ____      _\n  / ____|                 |  __ \\|  _ \\   _| |_\n | |     _ __ ___  ___ ___| |  | | |_) | |_   _|\n | |    | '__/ _ \\/ __/ __| |  | |  _ <    |_|\n | |____| | | (_) \\__ \\__ \\ |__| | |_) |  0.6.0\n  \\_____|_|  \\___/|___/___/_____/|____/ crossdb.org\n\n============ Welcome to CrossDB Shell ============\n<help>: Help Info       <F1>: Shortcuts\n<exit>: Exit shell      <TAB>: Auto completion\n\nXDB> exit\n
"},{"location":"get-started/bench/#bench-test","title":"Bench Test","text":"

Test with 1000 rows

crossdb/bench/c$ ./a.out 1000\n********************** INSERT 1000 with SQL **********************\nUse time 763ns, QPS 1310615\n********************** Random LKUP 5000000 with SQL **********************\nUse time 951987ns, QPS 5252172\nUse time 921033ns, QPS 5428687\nUse time 915605ns, QPS 5460870\nUse time 926288ns, QPS 5397889\n********************** UPDATE 1000 with SQL **********************\nUse time 760ns, QPS 1315789\n********************** DELETE 1000 with SQL **********************\nUse time 438ns, QPS 2283105\n\n********************** INSERT 1000 with SQL **********************\nUse time 687ns, QPS 1455604\n********************** Random LKUP 10000000 with Prepared STMT **********************\nUse time 294717ns, QPS 33930855\nUse time 297268ns, QPS 33639678\nUse time 298728ns, QPS 33475268\nUse time 295278ns, QPS 33866390\n********************** UPDATE 1000 with Prepared SMTT **********************\nUse time 576ns, QPS 1736111\n********************** DELETE 1000 with Prepared SQL **********************\nUse time 252ns, QPS 3968253\n

Test with 1000,1000 rows

crossdb$ make bench\nor\ncrossdb/bench/c$ ./a.out\n\n********************** INSERT 1000000 with SQL **********************\nUse time 539342ns, QPS 1854111\n********************** Random LKUP 1000000 with SQL **********************\nUse time 336044ns, QPS 2975800\nUse time 333927ns, QPS 2994666\nUse time 329699ns, QPS 3033069\nUse time 331632ns, QPS 3015390\n********************** UPDATE 1000000 with SQL **********************\nUse time 579945ns, QPS 1724301\n********************** DELETE 1000000 with SQL **********************\nUse time 405004ns, QPS 2469111\n\n********************** INSERT 1000000 with SQL **********************\nUse time 527486ns, QPS 1895784\n********************** Random LKUP 10000000 with Prepared STMT **********************\nUse time 1678936ns, QPS 5956153\nUse time 1668971ns, QPS 5991715\nUse time 1670993ns, QPS 5984465\nUse time 1652815ns, QPS 6050283\n********************** UPDATE 1000000 with Prepared SMTT **********************\nUse time 381320ns, QPS 2622469\n********************** DELETE 1000000 with Prepared SQL **********************\nUse time 232181ns, QPS 4306984\n
"},{"location":"get-started/install/","title":"Build and Install","text":""},{"location":"get-started/install/#build","title":"Build","text":"
crossdb$ make\nmake build                Build crossdb library and tool\nmake debug                Build crossdb library and tool with debug\nmake run                  Run crossdb tool\nmake clean                Clean build result\nmake install              Install crossdb(lib&tool&header) to Linux & FreeBSD\nmake uninstall            Uninstall crossdb from Linux & FreeBSD\nmake installmacos         Install crossdb(lib&tool&header) to MacOS\nmake uninstallmacos       Uninstall crossdb from MacOS\nmake example              Build and run example (need to install crossdb first)\nmake bench                Build and run bench test (need to install crossdb first)\n
"},{"location":"get-started/install/#linuxfreebsd","title":"Linux/FreeBSD","text":"
make build\nsudo make install\n
"},{"location":"get-started/install/#macos","title":"MacOS","text":"
make build\nsudo make installmacos\n
"},{"location":"get-started/install/#windows","title":"Windows","text":"

You need to install MINGW64 to build. Then set gcc path to system environment variables Path and make sure gcc can run.

build\n
"},{"location":"get-started/tutorial/","title":"Turorial","text":"
  • Open conection and create default memory database
xdb_res_t   *pRes;\nxdb_row_t   *pRow;\n\nxdb_conn_t  *pConn = xdb_open (\":memory:\");\n
  • Create Table
pRes = xdb_exec (pConn, \"CREATE TABLE student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(255))\");\nXDB_CHECK(pRes, printf (\"Can't create table student\\n\"); goto error;);\npRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(255), INDEX (name))\");\nXDB_CHECK(pRes, printf (\"Can't create table teacher\\n\"); goto error;);\npRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name))\");\nXDB_CHECK(pRes, printf (\"Can't create table book\\n\"); goto error;);\n
  • Insert Rows
pRes = xdb_exec (pConn, \"INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)\");\nXDB_CHECK(pRes, printf (\"Can't insert table student\\n\"); goto error;);\npRes = xdb_pexec (pConn, \"INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')\", \"He is a boy.\\nHe likes playing football.\\nWe all like him!\");\nXDB_CHECK(pRes, printf (\"Can't insert table student\\n\"); goto error;);\npRes = xdb_pexec (pConn, \"INSERT INTO student (id,name,age,class,score,info) VALUES (7,'Wendy',10,'3-1',95,'%s')\", \"She is a girl.\\nShe likes cooking.\\nWe all love her!\");\nXDB_CHECK(pRes, printf (\"Can't insert table student\\n\"); goto error;);\npRes = xdb_exec (pConn, \"INSERT INTO teacher (id,name,age) VALUES (1,'Tomas',40),(2,'Steven',50),(3,'Bill',31),(4,'Lucy',29)\");\nXDB_CHECK(pRes, printf (\"Can't insert table teacher\\n\"); goto error;);\npRes = xdb_exec (pConn, \"INSERT INTO book (id,name,author,count) VALUES (1,'Romeo and Juliet','Shakespeare',10),(2,'Pride and Prejudice','Austen',5),(3,'Great Expectations','Dickens',8),(4,'Sorrows of Young Werther','Von Goethe',4)\");\nXDB_CHECK(pRes, printf (\"Can't insert table book\\n\"); goto error;);\n
  • Select Rows
pRes = xdb_exec (pConn, \"SELECT * from student\");\nprintf (\"=== Select all %d rows\\n\", (int)pRes->row_count);\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n    printf (\"id=%d name='%s' age=%d class='%s' score=%f\\n\", \n        xdb_column_int (pRes->col_meta, pRow, 0), \n        xdb_column_str (pRes->col_meta, pRow, 1), \n        xdb_column_int (pRes->col_meta, pRow, 2), \n        xdb_column_str (pRes->col_meta, pRow, 3), \n        xdb_column_float(pRes->col_meta, pRow, 4));\n    printf (\"id=%d name='%s' age=%d class='%s' score=%f\\n\", \n        *(int*)pRow[0], \n        (char*)pRow[1], \n        *(int*)pRow[2], \n        (char*)pRow[3], \n        *(float*)pRow[4]);\n}\nxdb_free_result (pRes);\n
  • Update Rows
printf (\"\\n=== Update age = 9 for id = 2\\n\");\npRes = xdb_exec (pConn, \"UPDATE student set age=9 WHERE id = 2\");\nXDB_CHECK(pRes, printf (\"Can't update id=%d\\n\",2); goto error;);\n\npRes = xdb_exec (pConn, \"SELECT id,name,age,class,score from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
  • Delete Rows
printf (\"\\n=== Delete id = 3\\n\");\npRes = xdb_exec (pConn, \"DELETE FROM student WHERE id = 3\");\nXDB_CHECK(pRes, printf (\"Can't delete id=%d\\n\",3); goto error;);\n\npRes = xdb_exec (pConn, \"SELECT * from student WHERE id = 3\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
  • Aggregation function
printf (\"\\n=== AGG COUNT,MIN,MAX,SUM,AVG\\n\");\npRes = xdb_exec (pConn, \"SELECT COUNT(*),MIN(score),MAX(score),SUM(score),AVG(score) FROM student\");\nprintf (\"=== select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n    printf (\"COUNT(*)=%d MIN(score)=%f MAX(score)=%f SUM(score)=%f AVG(score)=%f\\n\", \n        xdb_column_int (pRes->col_meta, pRow, 0), \n        xdb_column_double(pRes->col_meta, pRow, 1), \n        xdb_column_double(pRes->col_meta, pRow, 2), \n        xdb_column_double(pRes->col_meta, pRow, 3), \n        xdb_column_double(pRes->col_meta, pRow, 4));\n    printf (\"COUNT(*)=%d MIN(score)=%f MAX(score)=%f SUM(score)=%f AVG(score)=%f\\n\", \n        (int)*(int64_t*)pRow[0], \n        *(float*)pRow[1], \n        *(float*)pRow[2], \n        *(double*)pRow[3], \n        *(double*)pRow[4]);\n}\nxdb_free_result (pRes);\n
  • Transaction Rollback
printf (\"\\n=== Rollback\\n\");\nxdb_begin (pConn);\npRes = xdb_exec (pConn, \"UPDATE student set age=15 WHERE id = 2\");\npRes = xdb_exec (pConn, \"SELECT id,name,age from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\nprintf (\"-- rollback\\n\");\nxdb_rollback (pConn);\npRes = xdb_exec (pConn, \"SELECT id,name,age from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
  • Transaction Commit
printf (\"\\n=== Commit\\n\");\nxdb_begin (pConn);\npRes = xdb_exec (pConn, \"UPDATE student set age=15 WHERE id = 2\");\npRes = xdb_exec (pConn, \"SELECT * from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\nprintf (\"-- commit\\n\");\nxdb_commit (pConn);\npRes = xdb_exec (pConn, \"SELECT * from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
  • Multi-Statements
printf (\"\\n=== Muti-Statements\\n\");\npRes = xdb_exec (pConn, \"SELECT COUNT(*) FROM student; SELECT id,name FROM student WHERE id=2\");\n// count(*) \nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n// select\npRes = xdb_next_result (pConn);\nif (NULL != pRes) {\n    if (NULL != (pRow = xdb_fetch_row (pRes))) {\n        xdb_print_row (pRes->col_meta, pRow, 0);\n        printf (\"\\n\");\n    }\n    xdb_free_result (pRes);\n}\n\nxdb_exec (pConn, \"SHELL\");\n
"},{"location":"replication/logic-replication/","title":"Logical Replication","text":""},{"location":"replication/logic-replication/#create-replication","title":"Create Replication","text":"
CREATE REPLICATION rep_name [replication_option] ...\n\nreplication_option:\n    HOST = xx \n  | PORT = xx \n  | USER = xx \n  | PASSWORD = xx \n  | DB = (dbname,...)\n  | INITSYNC = {true | false}\n  | AUDIT = {true | false}\n  | SCHEMA = {true | false}\n  | ENABLE = {true | false}\n
"},{"location":"replication/logic-replication/#change-replication","title":"Change Replication","text":"
ALTER REPLICATION rep_name [replication_option] ...\n\nreplication_option:\n    ENABLE = {true | false}\n  | USER = xx \n  | PASSWORD = xx \n
"},{"location":"replication/logic-replication/#drop-replication","title":"Drop Replication","text":"
DROP REPLICATION [IF EXISTS] rep_name\n
"},{"location":"replication/logic-replication/#show-replication","title":"Show Replication","text":"
SHOW REPLICATION\n
"},{"location":"replication/pubsub/","title":"PUBSUB","text":""},{"location":"replication/pubsub/#create-subscription","title":"Create Subscription","text":"
CREATE SUBSCRIPTION sub_name [subscripton_option] ...\n\nsubscripton_option:\n    HOST = xx \n  | PORT = xx \n  | USER = xx \n  | PASSWORD = xx \n  | SRCDB = db_name\n  | DB = db_name\n  | INITSYNC = {FULL | SCHEMA | DATA | NONE}\n  | OFFSET = 0, -1\n  | AUDIT = {true | false}\n  | ENABLE = {true | false}\n\n    FILTERS (select * from xxx where xx into mytable)\n\n  | TABLES = (tbl_name,...)\n
"},{"location":"replication/pubsub/#change-replication","title":"Change Replication","text":"
ALTER REPLICATION rep_name [replication_option] ...\n\nreplication_option:\n    ENABLE = {true | false}\n  | USER = xx \n  | PASSWORD = xx \n
"},{"location":"replication/pubsub/#drop-replication","title":"Drop Replication","text":"
DROP REPLICATION [IF EXISTS] rep_name\n
"},{"location":"replication/pubsub/#show-replication","title":"Show Replication","text":"
SHOW REPLICATION\n
"},{"location":"replication/replication/","title":"Replication","text":""},{"location":"replication/replication/#create-replication","title":"Create Replication","text":"
CREATE REPLICATION rep_name [replication_option] ...\n\nreplication_option:\n    HOST = xx \n  | PORT = xx \n  | USER = xx \n  | PASSWORD = xx \n  | DB = db_name\n  | TABLES = (tbl_name,...)\n  | TODB = db_name\n  | INITSYNC = {FULL | SCHEMA | DATA | NONE}\n  | AUDIT = {true | false}\n  | ENABLE = {true | false}\n\n    FILTERS (select * from xxx where xx into mytable)\n
"},{"location":"replication/replication/#change-replication","title":"Change Replication","text":"
ALTER REPLICATION rep_name [replication_option] ...\n\nreplication_option:\n    ENABLE = {true | false}\n  | OFFSET = 0, -1\n  | USER = xx \n  | PASSWORD = xx \n
"},{"location":"replication/replication/#drop-replication","title":"Drop Replication","text":"
DROP REPLICATION [IF EXISTS] rep_name\n
"},{"location":"replication/replication/#show-replication","title":"Show Replication","text":"
SHOW REPLICSTATUS\n    show secondary status\n\nSHOW REPLICATION\n    show my replica status\n\nrole: master/slave\n\nSHOW MASTER STATUS\n\nSHOW REPLICA STATUS [FOR CHANNEL channel]\nSHOW SLAVE STATUS [FOR CHANNEL channel]\n
"},{"location":"server/server/","title":"Server","text":""},{"location":"server/server/#create-server","title":"Create Server","text":"
CREATE SERVER [IF NOT EXISTS] server_name [server_option ...]\n\nserver_option:\n    IP = ipaddr\n  | PORT = xxx \n  | TYPE = {SERVER | WEBUI | MYSQL}\n  | AUTH = {NO | PASSWORD | ACL}\n  | ENABLE = {true | false}\n  | PASSWORD = 'string'\n  | DB = (db_name,...)\n
"},{"location":"server/server/#modify-server","title":"Modify Server","text":"
ALTER SERVER server_name [server_option ...]\n\nserver_option:\n  | AUTH = {NO | PASSWORD | ACL}\n  | ENABLE = {true | false}\n  | PASSWORD = xxxx\n  | DB = (db_name,...)\n
"},{"location":"server/server/#drop-server","title":"Drop Server","text":"
DROP SERVER [IF EXISTS] server_name\n
"},{"location":"server/server/#show-server","title":"Show Server","text":"
SHOW SERVERS\n
"},{"location":"server/status/","title":"Status","text":""},{"location":"server/status/#show-status","title":"Show Status","text":"

SHOW [SESSION | GLOBAL] STATUS\n
global status, uptime, dbs, tables, sql stats

"},{"location":"server/status/#show-sessions","title":"Show Sessions","text":"

SHOW SESSIONS\n
pid, connect time, (telnet|client), ip, port, user, sql stats

"},{"location":"sql/backup/","title":"Backup and Restore","text":""},{"location":"sql/backup/#source","title":"Source","text":"

Load and execute SQL file into current database

SOURCE '[path/]sqlfile'\n
"},{"location":"sql/backup/#dump-database","title":"Dump Database","text":"

Dump current database to console

DUMP DATABASE\n

Dump specified database with options

DUMP DATABASE db_name [dump_option] ...\n\ndump_option:\n    NODROP      : Don't add DROP statement\n  | NOCREATE    : Don't add CREATE statement\n  | NODATA      : Don't dump ROW data\n  | INTO '[path/]outfile' : Dump into file instead of console\n
"},{"location":"sql/data-types/","title":"Data Types","text":"Type Bytes Description Note BOOL 1 Bool, the value range is {true, false}. TBD TINYINT 1 Single-byte integer, the value range is [-128, 127]. SMALLINT 2 Short integer, the value range is [-32768, 32767]. INT 4 Integer, the value range is [-2^31, 2^31-1]. BIGINT 8 Long integer, the value range is [-2^63, 2^63-1]. TINYINT UNSIGNED 1 unsigned single-byte integer, the value range is [0, 255]. TBD SMALLINT UNSIGNED 2 unsigned integer, the value range is [0, 65535]. TBD INT UNSIGNED 4 Unsigned integer, the value range is [0, 2^32-1]. TBD BIGINT UNSIGNED 8 unsigned long integer, the value range is [0, 2^64-1]. TBD TIMESTAMP 8 Default precision is microsecond. TBD FLOAT 4 Floating point number. DOUBLE 8 Double precision floating point number. CHAR [COLLATE collation_name] User-defined, max 65535 Fixed-length UTF-8 string. VARCHAR [COLLATE collation_name] User-defined, max 65535 Variable-Length UTF-8 string. TBD BINARY User-defined, max 65535 Fixed-length binary data. TBD VARBINARY User-defined, max 65535 Variable-Length binary data. TBD"},{"location":"sql/data-types/#collation","title":"Collation","text":"Type Description NOCASE Case insensitive [Default]. BINARY Case sensitive."},{"location":"sql/data-types/#escape-characters","title":"Escape Characters","text":"Escape Character Actual Meaning \\n Line Break \\r Carriage Return \\t tab \\' Single quote ' \\\" Double quote \" ` backtick ` \\ Back Slash \\ \\% % see below for details _ _ see below for details"},{"location":"sql/database/","title":"Database","text":""},{"location":"sql/database/#create-database","title":"Create Database","text":"
CREATE DATABASE [IF NOT EXISTS] {db_name | '[path/]db_name'} [db_option] ...\n\ndb_option:\n    ENGINE = {MMAP | MEMORY}\n  | LOCKMODE = {THREAD | PROCESS | NOLOCK}\n
LOCKMODE Lock used Description THREAD [default] high-performance thread read-write lock For single process multiple threads access. PROCESS file read-write lock For multiple processes multiple threads access. NOLOCK no lock For test/diag purpose only.

Note

'[path]/db_name' is only valid for embedded database. db_options are default values for new created tables and you can use table_options to overwrite these default values.

"},{"location":"sql/database/#open-database","title":"Open Database","text":"
OPEN DATABASE {db_name | '[path/]db_name'} [dbg_option] ...\n\ndbg_option:\n    FLUSHMODE = {ASYNC | SYNC | NOSYNC}\n  | LOCKMODE = {THREAD | PROCESS | NOLOCK}\n

Note

This command can only be used for embedded database. dbg_option is only valid for current session and only for debug purpose.

"},{"location":"sql/database/#close-database","title":"Close Database","text":"
CLOSE DATABASE [IF EXISTS] db_name\n

Note

This command can only be used for embedded database.

"},{"location":"sql/database/#drop-database","title":"Drop Database","text":"
DROP DATABASE [IF EXISTS] db_name\n
"},{"location":"sql/database/#use-database","title":"Use Database","text":"
USE db_name\n
"},{"location":"sql/database/#show-databases","title":"Show Databases","text":"
SHOW DATABASES [WHERE expr]\n
XDB> show DATABASES ;\n+----------+--------+-----------+\n| database | engine | data_path |\n+----------+--------+-----------+\n| system   |        |           |\n| memory   |        |           |\n+----------+--------+-----------+\n2 rows in set (0.012 ms)\n
"},{"location":"sql/dml/","title":"Data manipulation","text":""},{"location":"sql/dml/#insert","title":"Insert","text":"
INSERT INTO tbl_name \n    [(col_name,...)] \n    VALUES (val,...), ...\n\nINSERT INTO tbl_name SET col_name = value, [col_name = value], ...\n
"},{"location":"sql/dml/#replace","title":"Replace","text":"
REPLACE INTO tbl_name \n    [(col_name,...)] \n    VALUES (val,...), ...\n
"},{"location":"sql/dml/#select","title":"Select","text":"
SELECT col_name,... FROM tbl_name\n    [WHERE expr]\n    [ORDER BY col_name [ASC | DESC], ...]\n    [LIMIT {[offset,] row_count | row_count OFFSET offset}]\n
"},{"location":"sql/dml/#update","title":"Update","text":"
UPDATE tbl_name\n    SET col_name=val, ... \n    [WHERE expr]\n    [ORDER BY col_name [ASC | DESC], ...]\n    [LIMIT {[offset,] row_count | row_count OFFSET offset}]\n
"},{"location":"sql/dml/#delete","title":"Delete","text":"
DELETE FROM tbl_name\n    [WHERE expr]\n    [ORDER BY col_name [ASC | DESC], ...]\n    [LIMIT {[offset,] row_count | row_count OFFSET offset}]\n
"},{"location":"sql/dml/#explain","title":"Explain","text":"
EXPLAIN SELECT statement\n
"},{"location":"sql/functions/","title":"Functions","text":""},{"location":"sql/functions/#aggregate-functions","title":"Aggregate Functions","text":"Function Return Type Description COUNT(*) BIGINT The number of rows. COUNT(col_name) BIGINT The number of rows in the specified column. MIN(col_name) Same with column The minimum value of a specific column MAX(col_name) Same with column The maximum value of a specific column. SUM(col_name) DOUBLE or BIGINT The sum of a specific column in a table AVG(col_name) DOUBLE The average value of the specified column."},{"location":"sql/indexes/","title":"Index","text":""},{"location":"sql/indexes/#create-index","title":"Create Index","text":"
CREATE [UNIQUE] INDEX idx_name \n    [USING {HASH | BTREE}] \n    ON tbl_name (col_name,...)\n
"},{"location":"sql/indexes/#drop-index","title":"Drop Index","text":"
DROP INDEX idx_name ON tbl_name\n
"},{"location":"sql/indexes/#show-index","title":"Show Index","text":"
SHOW {INDEX | INDEXES | KEYS} [FROM tbl_name] [WHERE expr]\n
XDB> show INDEXES ;\n+---------+---------+------+----------+\n| table   | idx_key | type | col_list |\n+---------+---------+------+----------+\n| student | PRIMARY | HASH | id       |\n| student | name_2  | HASH | name     |\n| teacher | PRIMARY | HASH | id       |\n| teacher | name_2  | HASH | name     |\n| book    | PRIMARY | HASH | id       |\n| book    | name_2  | HASH | name     |\n+---------+---------+------+----------+\n6 rows in set (0.016 ms)\n
"},{"location":"sql/misc/","title":"Misc","text":""},{"location":"sql/misc/#shell","title":"Shell","text":"

Enter interactive shell

SHELL\n
"},{"location":"sql/misc/#help","title":"Help","text":"
HELP [topic] [subtopic]\n
"},{"location":"sql/name-limit/","title":"Name and Limit","text":""},{"location":"sql/name-limit/#case-sensitive","title":"Case Sensitive","text":"Type Case-sensitive Keyword False Function False DB Name False Table Name False Column Name False Index Name False"},{"location":"sql/name-limit/#limit","title":"Limit","text":"Type Limit DB Name 64 Table Name 64 Column Name 64 Index Name 64 Single SQL statement 1048576 (1M) DB per process 1024 Table per DB 4095 Rows per Table 2,000,000,000 (2B) Row size 524288 (512K) Index per Table 16 Filter Fields 64"},{"location":"sql/operators/","title":"Operators","text":""},{"location":"sql/operators/#comparison-operators","title":"Comparison Operators","text":"Operator Description Note = Equal to <>, != Not equal to TBD > Greater than TBD < Less than TBD >= Greater than or equal to TBD <= Less than or equal to TBD IS NULL NULL value test TBD IS NOT NULL NOT NULL value test TBD BETWEEN ... AND ... Whether a value is within a range of values TBD NOT BETWEEN ... AND ... Whether a value is not within a range of values TBD IN Whether a value is not within a set of values TBD NOT IN Negation of simple pattern matching TBD LIKE Wildcard match TBD

LIKE is used together with wildcards to match strings. Its usage is described as follows:

  • '%' matches 0 or any number of characters, '_' matches any single ASCII character.
  • \\_ is used to match the _ in the string.
"},{"location":"sql/operators/#logical-operators","title":"Logical Operators","text":"Operator Description Note AND Logical AND OR Logical OR TBD"},{"location":"sql/statements/","title":"SQL Statements","text":"Statement Descritpion Note BEGIN Start a new transaction. COMMIT Commits the open transaction if exists. CLOSE DATABASE Close an opened database. Embedded Mode only CREATE DATABASE Create a database. CREATE INDEX Create an index on the specified table. CREATE TABLE Create a new table. DELETE Delete rows in a table. DESCRIBE Describe the specified table. DROP DATABASE Drop a database. DROP INDEX Drop the specified index on the specified table. DROP TABLE Drop the specified table. DUMP DATABASE Dump database into file. EXPLAIN Returns detailed information on how the query is executed. HELP SQL statements help. INSERT Insert data into a table. OPEN DATABASE Open a database on disk. Embedded Mode only ROLLBACK Roll back the open transaction if exists. SELECT Retrieves data from a table. SET AUTOCOMMIT Set session transaction auto-commit. SHELL Enter interactive shell. SHOW COLUMNS Show the list of columns within a given table. SHOW CREATE TABLE Show the CREATE TABLE statement. SHOW DATABASE Show the list of databases. SHOW INDEXES Show the list of indexes associated with a given table. SHOW TABLES Show the list of tables in database. SOURCE Load and execute SQL file. UPDATE Modifies rows in a table. USE Use the database as the current default database."},{"location":"sql/table/","title":"Table","text":""},{"location":"sql/table/#create-table","title":"Create Table","text":"
CREATE TABLE [IF NOT EXISTS] tbl_name (create_definition, ...) [table_option] ...\n\nCREATE OR REPLACE TABLE tbl_name (create_definition, ...)  [table_option] ...\n\ncreate_definition:\n    col_name data_type [column_option] ...\n  | PRIMARY KEY index_definition\n  | UNIQUE [KEY | INDEX] [idx_name] index_definition\n  | {KEY | INDEX} [idx_name] index_definition\n\ndata_type:\n    BOOL\n  | TINYINT [UNSIGNED]\n  | SMALLINT [UNSIGNED]\n  | {INT | INTEGER} [UNSIGNED]\n  | BIGINT [UNSIGNED]\n  | TIMESTAMP\n  | CHAR[(n)] [COLLATE <collation_name>]\n  | VARCHAR[(n)] [COLLATE <collation_name>]\n  | BINARY[(n)]\n  | VBINARY[(n)]\n\ncollation_name:\n    BINARY\n  | NOCASE\n\ncolumn_option:\n    {NOT NULL | NULL} \n  | DEFAULT value\n  | AUTO_INCREMENT \n  | [PRIMARY] KEY\n  | UNIQUE [KEY]\n\nindex_definition: [USING {HASH | BTREE}] (col_name, ...)\n\ntable_option:\n    ENGINE = MEMORY\n  | MAX_ROWS = value\n  | MIN_ROWS = value\n  | LOCKMODE = {THREAD | PROCESS | NOLOCK}\n  | ROWLOCK = {0 | 1}\n  | MVCC = {0 | 1}\n
"},{"location":"sql/table/#drop-table","title":"Drop Table","text":"
DROP TABLE [IF EXISTS] tbl_name\n
"},{"location":"sql/table/#show-tables","title":"Show Tables","text":""},{"location":"sql/table/#show-all-tables","title":"Show All Tables","text":"
SHOW TABLES [LIKE pattern] [WHERE expr]\n
XDB> show TABLES ;\n+---------+--------+-------------+-----------+\n| table   | engine | primary_key | data_path |\n+---------+--------+-------------+-----------+\n| student |        |             |           |\n| teacher |        |             |           |\n| book    |        |             |           |\n+---------+--------+-------------+-----------+\n3 rows in set (0.022 ms)\n
"},{"location":"sql/table/#show-create-table","title":"Show Create Table","text":"
SHOW CREATE TABLE tbl_name\n
XDB> show CREATE TABLE student ;\n+-------------------------------+\n| schema                        |\n+-------------------------------+\n| CREATE TABLE student (        |\n|   id               INT,       |\n|   name             CHAR(16),  |\n|   age              INT,       |\n|   class            CHAR(16),  |\n|   score            FLOAT,     |\n|   info             CHAR(256), |\n|   PRIMARY KEY (id),           |\n|   KEY         name_2 (name)   |\n| );                            |\n+-------------------------------+\n1 row in set (0.026 ms)\n
"},{"location":"sql/table/#show-table-columns","title":"Show Table Columns","text":"
{DESC | DESCRIBE} tbl_name\n\nSHOW COLUMNS [FROM tbl_name] [WHERE expr]\n
XDB> DESCRIBE student ;\n+--------+-------+-----+\n| column | type  | len |\n+--------+-------+-----+\n| id     | INT   | 4   |\n| name   | CHAR  | 16  |\n| age    | INT   | 4   |\n| class  | CHAR  | 16  |\n| score  | FLOAT | 4   |\n| info   | CHAR  | 256 |\n+--------+-------+-----+\n6 rows in set (0.023 ms)\n
"},{"location":"sql/transaction/","title":"Transaction and Lock","text":""},{"location":"sql/transaction/#begin-transaction","title":"Begin Transaction","text":"
BEGIN\n\nSTART TRANSACTION [READ WRITE | READ ONLY]\n

Note

Will commit any existing open transaction

"},{"location":"sql/transaction/#commit-transaction","title":"Commit Transaction","text":"
COMMIT\n
"},{"location":"sql/transaction/#rollback-transaction","title":"Rollback Transaction","text":"
ROLLBACK\n
"},{"location":"sql/transaction/#lock-tables","title":"Lock Tables","text":"
-- TBD\nLOCK {TABLE | TABLES} tbl_name { READ | WRITE } [, tbl_name { READ | WRITE }] ...\n

Note

This command must be executed after BEGIN transaction for performance or prevent other sessions to , and locks will be released after commit transaction.

"},{"location":"sql/transaction/#set-isolation-level","title":"Set Isolation Level","text":"
-- TBD\nSET TRANSACTION ISOLATION LEVEL { READ COMMITTED | REPEATABLE READ | READ UNCOMMITTED | SERIALIZABLE }\n

Note

TBD, default is READ COMMITTED.

"},{"location":"sql/transaction/#set-auto-commit","title":"Set Auto Commit","text":"
SET AUTOCOMMIT = {0 | 1}\n

Note

Default AUTOCOMMIT = 1.

"},{"location":"sysdb/information-schema/","title":"INFORMATION_SCHEMA","text":"

TBD

"},{"location":"sysdb/system/","title":"system","text":""},{"location":"sysdb/system/#databases","title":"Databases","text":"
XDB> SELECT * FROM system.databases;\n+----------+--------+-----------+\n| database | engine | data_path |\n+----------+--------+-----------+\n| system   |        |           |\n| memory   |        |           |\n+----------+--------+-----------+\n2 rows in set (0.010 ms)\n
"},{"location":"sysdb/system/#tables","title":"Tables","text":"
XDB> SELECT * FROM system.tables where database='memory';\n+----------+---------+--------+-----------+-------------------------------+\n| database | table   | engine | data_path | schema                        |\n+----------+---------+--------+-----------+-------------------------------+\n| memory   | student |        |           | CREATE TABLE student (        |\n|          |         |        |           |   id               INT,       |\n|          |         |        |           |   name             CHAR(16),  |\n|          |         |        |           |   age              INT,       |\n|          |         |        |           |   class            CHAR(16),  |\n|          |         |        |           |   score            FLOAT,     |\n|          |         |        |           |   info             CHAR(256), |\n|          |         |        |           |   PRIMARY KEY (id),           |\n|          |         |        |           |   KEY         name_2 (name)   |\n|          |         |        |           | );                            |\n| memory   | teacher |        |           | CREATE TABLE teacher (        |\n|          |         |        |           |   id               INT,       |\n|          |         |        |           |   name             CHAR(16),  |\n|          |         |        |           |   age              INT,       |\n|          |         |        |           |   info             CHAR(256), |\n|          |         |        |           |   PRIMARY KEY (id),           |\n|          |         |        |           |   KEY         name_2 (name)   |\n|          |         |        |           | );                            |\n| memory   | book    |        |           | CREATE TABLE book (           |\n|          |         |        |           |   id               INT,       |\n|          |         |        |           |   name             CHAR(64),  |\n|          |         |        |           |   author           CHAR(32),  |\n|          |         |        |           |   count            INT,       |\n|          |         |        |           |   PRIMARY KEY (id),           |\n|          |         |        |           |   KEY         name_2 (name)   |\n|          |         |        |           | );                            |\n+----------+---------+--------+-----------+-------------------------------+\n3 rows in set (0.020 ms)\n
"},{"location":"sysdb/system/#columns","title":"Columns","text":"
XDB> SELECT * FROM system.columns where database='memory';\n+----------+---------+--------+-------+-----+\n| database | table   | column | type  | len |\n+----------+---------+--------+-------+-----+\n| memory   | student | id     | INT   | 4   |\n| memory   | student | name   | CHAR  | 16  |\n| memory   | student | age    | INT   | 4   |\n| memory   | student | class  | CHAR  | 16  |\n| memory   | student | score  | FLOAT | 4   |\n| memory   | student | info   | CHAR  | 256 |\n| memory   | teacher | id     | INT   | 4   |\n| memory   | teacher | name   | CHAR  | 16  |\n| memory   | teacher | age    | INT   | 4   |\n| memory   | teacher | info   | CHAR  | 256 |\n| memory   | book    | id     | INT   | 4   |\n| memory   | book    | name   | CHAR  | 64  |\n| memory   | book    | author | CHAR  | 32  |\n| memory   | book    | count  | INT   | 4   |\n+----------+---------+--------+-------+-----+\n14 rows in set (0.017 ms)\n
"},{"location":"sysdb/system/#indexes","title":"Indexes","text":"
XDB> SELECT * FROM system.indexes where database='memory';\n+----------+---------+---------+------+----------+\n| database | table   | idx_key | type | col_list |\n+----------+---------+---------+------+----------+\n| memory   | student | PRIMARY | HASH | id       |\n| memory   | student | name_2  | HASH | name     |\n| memory   | teacher | PRIMARY | HASH | id       |\n| memory   | teacher | name_2  | HASH | name     |\n| memory   | book    | PRIMARY | HASH | id       |\n| memory   | book    | name_2  | HASH | name     |\n+----------+---------+---------+------+----------+\n6 rows in set (0.016 ms)\n
"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":"

CrossDBSuper High-performance Embedded and Server RDBMS\u2728

Quick Learn\ud83e\udded Benchmark \ud83d\udcdc

  • \ud83c\udf0c Simple

    CrossDB is easy to install and deploy. It has zero external dependencies and runs in-process in its host application or as a single binary with tiny footprint.

  • \u267b\ufe0f Portable

    CrossDB runs on Linux, macOS, Windows, BSD and all popular hardware architectures. It has idiomatic client APIs for major programming languages.

    Read more

  • \ud83d\ude80 Super Fast

    The hand-writing SQL parser and memory-oriented design architecture make the database run SQL at blazing speed.

  • \u26fd Hybrid Storage Mode

    CrossDB supports On-Disk database and In-Memory database(IMDB). It can also support Hybrid mode with some tables On-Disk and some In-Memory.

  • \ud83d\udd31 MySQL-like SQL

    Most SQL commands are similar with MySQL.

    Read more

  • \ud83d\udcae Server Mode

    Besides the Embedded RDBMS mode, CrossDB can also run in Embedded Server mode or run CrossDB as Standalone RDBMS server.

CSQL
xdb_res_t   *pRes;\nxdb_row_t   *pRow;\nxdb_conn_t  *pConn = xdb_open (\":memory:\");\npRes = xdb_exec (pConn, \"CREATE TABLE student (id INT, name CHAR(16), age INT, class CHAR(16), score INT)\");\npRes = xdb_exec (pConn, \"INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)\");\npRes = xdb_exec (pConn, \"SELECT * from student\");\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->row_meta, pRow);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\npRes = xdb_exec (pConn, \"UPDATE student set age=9 WHERE id = 2\");\npRes = xdb_exec (pConn, \"DELETE FROM student WHERE id = 3\");\nxdb_close (pConn);\n
CREATE TABLE student (id INT, name CHAR(16), age INT, class CHAR(16), score INT);\nINSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95);\nSELECT * FROM student;\nSELECT * FROM student WHERE id = 1;\nUPDATE student set age=9 WHERE id = 2;\nDELETE FROM student WHERE id = 3;\n

Note

This project was redesigned and rewritten from scratch. It's still in early development stage, so please DO NOT use in your project now.

"},{"location":"CHANGELOG/","title":"Change Log","text":""},{"location":"CHANGELOG/#060-2024-08-18","title":"0.6.0 (2024-08-18)","text":"
  • Initial refactor release

  • This project was redesigned and rewritten from scratch for over one year

  • Standard RDBMS model
  • New SQL APIs which can support more language
  • MySQL style SQL and shell, which will be easy to study.
"},{"location":"CHANGELOG/#050-2023-06-26","title":"0.5.0 (2023-06-26)","text":"

Features

  • CrossDB command line tool crossdb-cli is released
  • Optimize insert/update/query/delete performance
  • Add new API cross_matchCreate and cross_matchFree
  • DML APIs supports cross_fields_h and cross_match_h

Bug Fixes

"},{"location":"CHANGELOG/#040-2023-06-20","title":"0.4.0 (2023-06-20)","text":"

Features

  • Support FreeBSD(X64)
  • Optimize insert/update/query/delete performance
  • Add new API cross_fieldsCreate and cross_fieldsFree

Bug Fixes

"},{"location":"CHANGELOG/#030-2023-06-13","title":"0.3.0 (2023-06-13)","text":"

Features

  • Support MacOS (X64 and ARM64)
  • Change CROSS_DB_XXX to CROSS_XXX

Bug Fixes

  • cross_dbTblCreate flags CROSS_DB_RBTREE doesn't create Primary Key Index type correctly
"},{"location":"CHANGELOG/#020-2023-06-07","title":"0.2.0 (2023-06-07)","text":"

Features

  • Support Windows
  • Support Linux ARM64

Bug Fixes

"},{"location":"CHANGELOG/#010-2023-06-03","title":"0.1.0 (2023-06-03)","text":"
  • Initial release

Features

Bug Fixes

"},{"location":"community/","title":"Community","text":""},{"location":"community/#report-bugs","title":"Report Bugs","text":"

Github Issues

"},{"location":"community/#require-fetures","title":"Require Fetures","text":"

Github Fetures

"},{"location":"community/#discussion","title":"Discussion","text":"

Github Discussion

"},{"location":"community/#contribution","title":"Contribution","text":"

In order to keep CrossDB quality and high-performance, this project does not accept patches. If you would like to suggest a change and you include a patch as a proof-of-concept, that would be great. However, please do not be offended if we rewrite your patch from scratch.

Following contributions are welcome:

  • Language bindings: Python, Java, Go, CSharp, Javascript, PHP, etc
  • Test and report bugs
"},{"location":"faq/","title":"FAQ","text":""},{"location":"faq/#why-is-crossdb-so-fast","title":"Why is CrossDB so fast?","text":"
  • Use memory map to access DB data directly (so your DB must less than the main memory to get highest speed).
  • Use high-performance hash as the main index, and use the super fast wyhash as the hash function.
  • Hand-written SQL parser which is more than 10X faster than Flex/Bison parser tools.
  • High-performance read-write lock and multi-core optimization.
  • Execute multiple SQL statements in one API, which will imporve client-server DB performance dramatically.
  • High-efficient client-server protocols.
  • Avoid memory allocation/free as much as possible.
  • High-performance implementation code
"},{"location":"glossary/","title":"Glossary","text":""},{"location":"glossary/#acid","title":"ACID","text":"

ACID refers to the four key properties of a transaction: atomicity, consistency, isolation, and durability. Each of these properties is described below.

Atomicity means that either all the changes of an operation are performed, or none of them are.

Consistency means that transactions always bring the database from one consistent state to another.

Isolation means that a transaction in process is invisible to other transactions until it completes. This allows concurrent transactions to read and write data without sacrificing consistency.

Durability means that once a transaction is committed, it remains committed even in the event of a system failure.

"},{"location":"glossary/#crud","title":"CRUD","text":"

Acronym for \u201ccreate, read, update, delete\u201d, a common sequence of operations in database applications. Often denotes a class of applications with relatively simple database usage (basic DDL, DML and query statements in SQL) that can be implemented quickly in any language.

"},{"location":"glossary/#ddl","title":"DDL","text":"

Data definition language, a set of SQL statements for manipulating the database itself rather than individual table rows. Includes all forms of the CREATE, ALTER, and DROP statements. DDL statements automatically commit the current transaction; they cannot be rolled back.

"},{"location":"glossary/#dml","title":"DML","text":"

Data manipulation language, a set of SQL statements for performing SELECT, INSERT, UPDATE, and DELETE operations.

"},{"location":"glossary/#hash-index","title":"Hash Index","text":"

A type of index intended for queries that use equality operators, rather than range operators such as greater-than or BETWEEN.

"},{"location":"glossary/#imdb","title":"IMDB","text":"

IMDB(In-Memory database) is a type of database system that maintains data in memory, to avoid overhead due to disk I/O and translation between disk blocks and memory areas.

"},{"location":"glossary/#index","title":"Index","text":"

A data structure that provides a fast lookup capability for rows of a table, typically by forming a tree structure (B-tree) representing all the values of a particular column or set of columns.

"},{"location":"glossary/#information_schema","title":"INFORMATION_SCHEMA","text":"

The name of the database that provides a query interface to the CrpssDB data dictionary. (This name is defined by the ANSI SQL standard.) To examine information (metadata) about the database, you can query tables such as INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.COLUMNS, rather than using SHOW commands that produce unstructured output.

"},{"location":"glossary/#mvcc","title":"MVCC","text":"

MVCC(Multi-Version Concurrency Control) is a concurrency control mechanism in many databases. It processes the memory read by transactions to achieve concurrent access to DB, thereby avoiding blocking caused by conflicts between concurrent reads and writes.

"},{"location":"glossary/#oltp","title":"OLTP","text":"

Acronym for \u201cOnline Transaction Processing\u201d. A database system, or a database application, that runs a workload with many transactions, with frequent writes as well as reads, typically affecting small amounts of data at a time.

"},{"location":"glossary/#sql","title":"SQL","text":"

The Structured Query Language that is standard for performing database operations. Often divided into the categories DDL, DML, and queries.

"},{"location":"intro/","title":"Introduction","text":"

CrossDB is a super high-performance embedded and server RDBMS. It's developed for high performance scenarios with main memory can hold whole DB.

"},{"location":"intro/#features","title":"Features","text":"
  • Support Multiple OS Platforms: Linux/Windows/MacOS/FreeBSD etc
  • Support Multiple CPU ARCH: X86/ARM/PPC/MIPS etc
  • Support OnDisk/In-memory/RamDisk/Hybrid Storage
  • Support Standard RDBMS model
  • Support MySQL like SQL
  • Support Multiple databases
  • Support Primary Key and multiple Secondary Indexes
  • Support HASH and RBTREE(TBD) Index
  • Support Multi-columns Index
  • Support Exact Match, Leftmost Match(TBD), Range Match(TBD)
  • Support Standard ACID Transaction (begin/commit/rollback)
  • Support WAL for OnDisk storage(TBD)
  • Support Multiple Threads and Multiple Processes Access
  • Support Table level read-write lock
  • Support Reader-Writer MVCC
  • Support Embedded CrossDB Shell
  • Support Multi-Statments APIs
  • Support Prepared Statments APIs
  • Super High Performance
  • Very Simple: Simple header and library file
  • Zero Config: no complex config, real out-of-the-box
"},{"location":"intro/#use-cases","title":"Use Cases","text":"
  • You can use CrossDB In-Memory DB to manage Process Runtime Data to replace STL or hand-wrting data structures.
  • You can use CrossDB RamDisk DB to support Process Restartability, In-Service Software Upgrade(ISSU) easily.
  • You can use CrossDB OnDisk DB to store data on Disk/Flash/SDD.
  • You can use CrossDB to work as a super fast cache DB.
"},{"location":"about/buy/","title":"How to Buy","text":""},{"location":"about/privacy/","title":"Privacy Notice","text":""},{"location":"about/privacy/#introduction","title":"Introduction","text":"

CrossDB Software has designed its website so that, in general, you can browse the CrossDB website without being asked for any personal information. Exceptions to this are when you specifically ask for information, request an evaluation copy of our software or download CrossDB trial software.

This policy covers how CrossDB Software treats personal information that CrossDB may collect and receive via the CrossDB website. Your use of the CrossDB website constitutes acceptance of and agreement with the CrossDB Software Privacy Policy. CrossDB reserves the right to change the CrossDB Software Privacy Policy at any time without notice.

"},{"location":"about/privacy/#information-collection-and-use","title":"Information collection and use","text":"

CrossDB collects personal information when you request for information, request an evaluation of our software or when you download trial software. This information includes information about you such as name, business name and address, telephone and fax numbers, email address, operating system, and hardware environment. Providing information is voluntary. You may provide this information by filling out an on-line form, by email or other communication to CrossDB. However, you may not receive the product information, software evaluation or downloads if you choose not to provide the requested information.

CrossDB Software's use of the information you provided will be to send you the information that you requested. CrossDB Software may also use the information to provide you with additional information about our products and services or market research. The information may be used to follow up with you regarding information supplied, software you downloaded or evaluated.

CrossDB does not sell information collected from users of CrossDB website to other organizations. CrossDB may share the information collected with its subsidiaries and its affiliates such as partners and distributors.

"},{"location":"about/privacy/#general-information","title":"General Information","text":"

CrossDB web servers record standard information about CrossDB Web accesses such as IP addresses, your server name, browser type, etc. when you visit our website. CrossDB uses this for information about usage at CrossDB Software's website. The information submitted to CrossDB Software via the Web may be processed, stored and used outside the country where it was submitted.

Links to third party websites are provided for your convenience. By using these links, you will no longer be on the CrossDB Software website and the CrossDB Software Privacy Policy will no longer apply.

"},{"location":"about/privacy/#contact-us","title":"Contact us","text":"

If you have any question about the information you provided to us or about the CrossDB Software Privacy Policy, please contact us at support@crossdb.org

"},{"location":"about/refund/","title":"Refund Policy","text":"

Thank you for using CrossDB Database! We don't offer refund, please try it first then subscribe the product by month or year. You can cancel the subscription anytime as you want.

"},{"location":"about/terms/","title":"Terms of Service","text":"

CrossDB provides this Website for your information and use, subject to the terms set forth below. By accessing this Website, you agree to accept the following terms.

"},{"location":"about/terms/#general-terms","title":"General terms","text":"

In no event will CrossDB be liable for any damages including, without limitation, indirect, incidental, consequential, special or exemplary damages, that arise out of or relate to the use of or inability to use the CrossDB Website, even if CrossDB has been advised of the possibility of such damages.

Any and all information provided on CrossDB\u2019s Website is provided \u201cas is,\u201d with no warranty as to accuracy or content.

CrossDB does not adopt or endorse the views of any third party Websites linked to or from the CrossDB Website.

CrossDB reserves the right to change, modify, add or remove any of these terms at any time.

"},{"location":"admin/data-backup/","title":"Data Backup","text":""},{"location":"admin/data-backup/#dump-with-dump-statement","title":"Dump with DUMP statement","text":"
  • Dump everything
SQLC
DUMP DATABASE school INTO 'school.sql';\n
xdb_exec (pConn, \"DUMP DATABASE school INTO 'school.sql'\");\n
  • Dump schema only
SQLC
DUMP DATABASE school NODATA INTO 'school.sql';\n
xdb_exec (pConn, \"DUMP DATABASE school NODATA INTO 'school.sql'\");\n
  • Dump data only
SQLC
DUMP DATABASE school NODROP NOCREATE INTO 'school.sql';\n
xdb_exec (pConn, \"DUMP DATABASE school NODROP NOCREATE INTO 'school.sql'\");\n
"},{"location":"admin/data-backup/#dump-with-crossdb-tool","title":"Dump with crossdb tool","text":"
  • Dump everything
crossdb -e \"DUMP DATABASE\" school > school.sql\n
crossdb -e \"DUMP DATABASE school INTO 'school.sql'\" school\n
  • Dump schema only
crossdb -e \"DUMP DATABASE school NODATA INTO 'school.sql'\" school\n
  • Dump data only
crossdb -e \"DUMP DATABASE school NODROP NOCREATE INTO 'school.sql'\" school\n
"},{"location":"admin/data-restore/","title":"Data Restore","text":""},{"location":"admin/data-restore/#load-with-source-statement","title":"Load with SOURCE statement","text":"SQLC
SOURCE 'school.sql'\n
xdb_exec (pConn, \"SOURCE 'school.sql'\");\n
"},{"location":"admin/data-restore/#load-with-crossdb-tool","title":"Load with CrossDB tool","text":"
crossdb school < school.sql\n
cat school.sql | crossdb school\n
crossdb -e \"SOURCE 'school.sql'\" school\n
"},{"location":"admin/shell/","title":"CrossDB Shell","text":""},{"location":"admin/shell/#crossdb-tool","title":"CrossDB tool","text":"

This tool can

  • Open and operate local database
  • Connect and operate remote database
  • Work as standalone database server
$ crossdb -h\ncrossdb: option requires an argument -- 'h'\nUsage: xdb-cli [OPTIONS] [[path/]db_name]\n  -h                        Show this help\n  -S                        Server: Start in server mode\n  -h <ip>                   IP address to bind to or connect to\n  -P <port>                 Port to listen or connect\n  -D <datadir>              Server: Data directory to store databases\n  -u <user>                 Client user\n  -p                        Client password\n  -e <sql>                  Execute SQL statements and quite\n
"},{"location":"admin/shell/#open-db","title":"Open DB","text":"
crossdb school\n
"},{"location":"admin/shell/#open-db-and-execute-command","title":"Open DB and Execute Command","text":"
crossdb -e 'SELECT * FROM student WHERE id=1; SELECT * FROM student WHERE age=10' school\n
"},{"location":"admin/shell/#embedded-shell","title":"Embedded Shell","text":"

You program can enter interactive shell use the SHELL statement.

SQLC
SHELL\n
xdb_exec (pConn, \"SHELL\");\n
"},{"location":"admin/shell/#auto-completion","title":"Auto Completion","text":"

Use TAB to do auto completion for SQL statements, keywords, db name, table name, field name, etc.

XDB> <TAB>\nCREATE      Create database, table, index, etc\nDROP        Drop database, table, index, etc\nALTER       Alter database, table, index, etc\nSELECT      Select rows from table\nINSERT      Insert rows into table\nUPDATE      Update rows in table\nDELETE      Delete rows from table\nBEGIN       Begin transaction\nCOMMIT      Commit transaction\nROLLBACK    Rollback transaction\nUSE         Switch Databae\nSHOW        Show database, table, index, etc\nDESCRIBE    Show Table Schema\nEXPLAIN     Show SELECT statement index selection\nSET         Config parameters\nOPEN        Open database\nCLOSE       Close database\nDUMP        Dump database\nSOURCE      Load SQL file\nSHELL       Enter interactive shell\nHELP        Help\n
XDB> S <TAB>\nSELECT    Select rows from table\nSHOW      Show database, table, index, etc\nSET       Config parameters\nSOURCE    Load SQL file\nSHELL     Enter interactive shell\nXDB> SE <TAB>\nSELECT    Select rows from table\nSET       Config parameters\nXDB> SEL <TAB>\nXDB> SELECT\n
XDB> SELECT <TAB>\nXDB> SELECT * <TAB>\nXDB> SELECT * FROM <TAB>\nstudent    teacher    book\nXDB> SELECT * FROM s<TAB>\nXDB> SELECT * FROM student\n
XDB> SELECT * FROM student <TAB>\nWHERE       ORDER BY    LIMIT       OFFSET      AND         id          name        age         class       score\ninfo\nXDB> SELECT * FROM student WHERE i <TAB>\nid      info\n
XDB> SHOW  <TAB>\nDATABASES    TABLES       INDEXES      COLUMNS      CREATE\n
"},{"location":"client/api-c/","title":"C APIs","text":""},{"location":"client/api-c/#apis-list","title":"APIs List","text":"API Descritpion xdb_conn_t* xdb_open (const char *path) Open a connection void xdb_close (xdb_conn_t *pConn) Close a connection xdb_res_t* xdb_exec (xdb_conn_t* pConn, const char *sql) Execute SQL statement xdb_res_t* xdb_next_result (xdb_conn_t *pConn) Get next SQL statement result bool xdb_more_result (xdb_conn_t* pRes) Check is there more result void xdb_free_result (xdb_res_t* pRes) Free result set xdb_col_t* xdb_column_meta (uint64_t meta, uint16_t iCol) Fetch one row xdb_row_t* xdb_fetch_row (xdb_res_t* pRes) Fetch one row int xdb_column_int (uint64_t meta, void *pRow, uint16_t iCol) Get int column from row float xdb_column_float (uint64_t meta, void *pRow, uint16_t iCol) Get float/double column from row const char * xdb_column_str (uint64_t meta, void *pRow, uint16_t iCol) Get string column from row xdb_stmt_t* xdb_stmt_prepare (xdb_conn_t* pConn, const char *sql) Prepare statement xdb_ret xdb_bind_int (xdb_stmt_t *pStmt, uint16_t para_id, int val) Bind int value xdb_ret xdb_bind_float (xdb_stmt_t *pStmt, uint16_t para_id, float val) Bind float value xdb_ret xdb_bind_str (xdb_stmt_t *pStmt, uint16_t para_id, const char *str) Bind string value xdb_res_t* xdb_stmt_exec (xdb_stmt_t *pStmt) Execute prepared SQL statement void xdb_stmt_close (xdb_stmt_t *pStmt) Free prepared SQL statement xdb_ret xdb_begin (xdb_conn_t* pConn) Begin transaction xdb_ret xdb_commit (xdb_conn_t* pConn) Commit transaction xdb_ret xdb_rollback (xdb_conn_t* pConn) Rollback transaction int xdb_print_row (uint64_t meta, void *pRow, int format) Print row to console const char * xdb_errmsg (xdb_res_t *pRes) Get error/information message const char * xdb_version () Get CrossDB version string"},{"location":"client/api-c/#xdb_open","title":"xdb_open","text":"

Open a connection and create/open a Database.

xdb_conn_t*\nxdb_open (const char *path);\n\n// TBD\nxdb_conn_t*\nxdb_open2 (const char *path, uint32_t flags);\n
  • If path is :memory: will create or open a memory database, else create or open a on-disk database. This database will be the default DB of this connection.
  • If path is NULL: Only open a connection. User has to use OPEN DATABASE '[path/]db_name' or CREATE DATABASE '[path/]db_name' or USE DATABASE db_name.
  • One thread can use only one connection. One connection can only be used by one thread
  • All opened databases are shared with all opened connections, and they can USE DATABASE db_name to switch connection default DB.
"},{"location":"client/api-c/#xdb_close","title":"xdb_close","text":"

Create a connection.

void\nxdb_close (xdb_conn_t *pConn);\n
"},{"location":"client/api-c/#xdb_exec","title":"xdb_exec","text":"

Execute SQL statement and return result set.

xdb_res_t*\nxdb_exec (xdb_conn_t* pConn, const char *sql);\n\nxdb_res_t*\nxdb_exec2 (xdb_conn_t *pConn, const char *sql, int len);\n
  • A valid xdb_res_t pointer is returned always.
  • errcode: if != 0, then can use xdb_errmsg(pRes) to get the error message.
  • row count: pRes->row_count for query statement
  • affected rows: pRes->affected_rows for INSERT UPDATE DELETE rows
  • column count: pRes->col_count for query statement
  • column meta: pRes->row_meta, use xdb_column_meta to get column meta.
"},{"location":"client/api-c/#xdb_pexec","title":"xdb_pexec","text":"

Execute formatted SQL statement and return result set.

xdb_res_t*\nxdb_pexec (xdb_conn_t *pConn, const char *sql, ...);\n
  • A valid xdb_res_t pointer is returned always.

Note

If sql contains %, should use escape \\%.

"},{"location":"client/api-c/#xdb_next_result","title":"xdb_next_result","text":"

Get next SQL statement result

Return NULL if no more result

xdb_res_t*\nxdb_next_result (xdb_conn_t *pConn);\n
"},{"location":"client/api-c/#xdb_more_result","title":"xdb_more_result","text":"

Check is there more result

bool\nxdb_more_result (xdb_conn_t *pConn);\n
"},{"location":"client/api-c/#xdb_free_result","title":"xdb_free_result","text":"

Free result set

void\nxdb_free_result (xdb_res_t *pRes);\n

Note

You only need to call xdb_free_result for query statements with errcode=0.

"},{"location":"client/api-c/#xdb_column_meta","title":"xdb_column_meta","text":"

Get column meta.

const xdb_col_t* \nxdb_column_meta (uint64_t meta, uint16_t iCol)\n

Note

This is an inline function.

"},{"location":"client/api-c/#xdb_fetch_row","title":"xdb_fetch_row","text":"

Fetch one row and return row list array.

xdb_row_t*\nxdb_fetch_row (xdb_res_t *pRes);\n
"},{"location":"client/api-c/#xdb_column_int","title":"xdb_column_int","text":"

Get int column from row.

int \nxdb_column_int (uint64_t meta, void *pRow, uint16_t iCol);\n\nint64_t \nxdb_column_int64 (uint64_t meta, void *pRow, uint16_t iCol);\n

Note

If you know the detailed format, you can access the pointer directly. *(int8_t*)pVal[iCol], *(int16_t*)pVal[iCol], *(int32_t*)pVal[iCol], *(int64_t*)pVal[iCol]

"},{"location":"client/api-c/#xdb_column_float","title":"xdb_column_float","text":"

Get float column from row.

float\nxdb_column_float (uint64_t meta, xdb_row_t *pRow, uint16_t iCol);\n\ndouble \nxdb_column_double (uint64_t meta, void *pRow, uint16_t iCol);\n

Note

If you know the detailed format, you can access the pointer directly. *(float*)pVal[iCol], *(double*)pVal[iCol]

"},{"location":"client/api-c/#xdb_column_str","title":"xdb_column_str","text":"

Get string column from row.

const char*\nxdb_column_str (uint64_t meta, xdb_row_t *pRow, uint16_t iCol);\n\nconst char*\nxdb_column_str2 (uint64_t meta, xdb_row_t *pRow, uint16_t iCol, int *pLen);\n

Note

You can access the pointer directly: *(const char*)pVal[iCol], get the length *(uint16_t*)(pVal[iCol]-2)

"},{"location":"client/api-c/#xdb_stmt_prepare","title":"xdb_stmt_prepare","text":"
xdb_stmt_t* \nxdb_stmt_prepare (xdb_conn_t* pConn, const char *sql);\n
"},{"location":"client/api-c/#xdb_bind_int","title":"xdb_bind_int","text":"

Binds an int value to the prepared statement at the specified parameter index.

xdb_ret\nxdb_bind_int (xdb_stmt_t *pStmt, uint16_t para_id, int val);\n\nxdb_ret\nxdb_bind_int64 (xdb_stmt_t *pStmt, uint16_t para_id, int64_t val);\n
"},{"location":"client/api-c/#xdb_bind_float","title":"xdb_bind_float","text":"

Binds a double value to the prepared statement at the specified parameter index.

xdb_ret\nxdb_bind_float (xdb_stmt_t *pStmt, uint16_t para_id, float val);\n\nxdb_ret\nxdb_bind_double (xdb_stmt_t *pStmt, uint16_t para_id, double val)\n
"},{"location":"client/api-c/#xdb_bind_str","title":"xdb_bind_str","text":"

Binds a string value to the prepared statement at the specified parameter index.

xdb_ret\nxdb_bind_str (xdb_stmt_t *pStmt, uint16_t id, const char *str, int len);\n\nxdb_ret\nxdb_bind_str2 (xdb_stmt_t *pStmt, uint16_t para_id, const char *str, int len)\n
"},{"location":"client/api-c/#xdb_stmt_exec","title":"xdb_stmt_exec","text":"

Execute a prepared statement.

xdb_res_t*\nxdb_stmt_exec (xdb_stmt_t *pStmt);\n
"},{"location":"client/api-c/#xdb_stmt_close","title":"xdb_stmt_close","text":"

Close a prepared statement.

void\nxdb_stmt_close (xdb_stmt_t *pStmt);\n
"},{"location":"client/api-c/#xdb_begin","title":"xdb_begin","text":"

Begin a transaction.

xdb_ret\nxdb_begin (xdb_conn_t* pConn);\n
  • For embedded local connection, always return XDB_OK.
"},{"location":"client/api-c/#xdb_commit","title":"xdb_commit","text":"

Commit a transaction.

xdb_ret\nxdb_commit (xdb_conn_t* pConn);\n
  • For embedded local connection, always return XDB_OK.
"},{"location":"client/api-c/#xdb_rollback","title":"xdb_rollback","text":"

Rollback a transaction.

xdb_ret\nxdb_rollback (xdb_conn_t* pConn);\n
  • For embedded local connection, always return XDB_OK.
"},{"location":"client/api-c/#xdb_print_row","title":"xdb_print_row","text":"

Print row to console.

int \nxdb_print_row (uint64_t meta, xdb_row_t *pRow, int format);\n
"},{"location":"client/api-c/#xdb_errmsg","title":"xdb_errmsg","text":"

Get error/information message in result.

const char *\nxdb_errmsg (xdb_res_t *pRes);\n
"},{"location":"client/api-c/#xdb_version","title":"xdb_version","text":"

Get CrossDB version string.

const char*\nxdb_version();\n
"},{"location":"client/api-c/#types","title":"Types","text":""},{"location":"client/api-c/#xdb_errno_e","title":"xdb_errno_e","text":"

Error Code

typedef enum {\n    XDB_OK,\n    XDB_ERROR,\n    XDB_E_PARAM,\n    XDB_E_STMT,\n    XDB_E_NODB,\n    XDB_E_NOTFOUND,\n    XDB_E_EXISTS,\n    XDB_E_FULL,\n    XDB_E_CONSTRAINT,\n    XDB_E_AUTH,\n    XDB_E_MEMORY,\n    XDB_E_FILE,\n    XDB_E_SOCK,\n} xdb_errno_e;\n

"},{"location":"client/api-c/#xdb_type_t","title":"xdb_type_t","text":"

Data Types

typedef enum {\n    XDB_TYPE_NULL       = 0,  // 1 bit\n    XDB_TYPE_TINYINT    = 1,  // 1 byte\n    XDB_TYPE_SMALLINT   = 2,  // 2 bytes\n    XDB_TYPE_INT        = 3,  // 4 bytes\n    XDB_TYPE_BIGINT     = 4,  // 8 bytes\n    XDB_TYPE_UTINYINT   = 5,  // 1 byte\n    XDB_TYPE_USMALLINT  = 6,  // 2 bytes\n    XDB_TYPE_UINT       = 7,  // 4 bytes\n    XDB_TYPE_UBIGINT    = 8,  // 8 bytes\n    XDB_TYPE_FLOAT      = 9,  // 4 bytes\n    XDB_TYPE_DOUBLE     = 10, // 8 bytes\n    XDB_TYPE_TIMESTAMP  = 11, // 8 bytes\n    XDB_TYPE_CHAR       = 12, // fixed-length string(at most 65535 byte)\n    XDB_TYPE_BINARY     = 13, // fixed-length binary(at most 65535 byte)\n    XDB_TYPE_VCHAR      = 14, // varied-length string(at most 65535 byte)\n    XDB_TYPE_VBINARY    = 15, // varied-length binary(at most 65535 byte)\n    XDB_TYPE_MAX        = 21\n} xdb_type_t;\n

"},{"location":"client/api-c/#structures","title":"Structures","text":""},{"location":"client/api-c/#xdb_res_t","title":"xdb_res_t","text":"

Result Set

typedef struct xdb_res_t {\n    uint32_t    len_type;       // MSB 4bit are type xdb_restype_t\n    uint16_t    errcode;        // 4\n    uint16_t    status;         // 6 xdb_status_t\n\n    uint32_t    meta_len;       // 8\n    uint16_t    col_count;      // 12\n    uint8_t     stmt_type;      // 14 SQL type(create/delete/drop/show/select/delete/update...)\n    uint8_t     rsvd;\n\n    uint64_t    row_count;      // 2*8 SELECT/SHOW\n    uint64_t    affected_rows;  // 3*8 INSERT/UPDATE/DELETE\n    uint64_t    insert_id;      // 4*8 INSERT\n    uint64_t    col_meta;       // 5*8 xdb_meta_t, <ptr:ptr off: 0 following is meta>\n    uint64_t    row_data;       // 6*8 xdb_rowlist_t, ptr: base ptr or error str or infomation xdb_msg_t\n    uint64_t    data_len;       // 7*8\n} xdb_res_t;\n

"},{"location":"client/api-c/#xdb_msg_t","title":"xdb_msg_t","text":"

Return Message

typedef struct {\n    uint32_t    len_type;       // LSB 4bit are type\n    uint16_t    len;\n    char        msg[];\n} xdb_msg_t;\n

"},{"location":"client/api-c/#xdb_meta_t","title":"xdb_meta_t","text":"

Query Meta information

typedef struct {\n    uint32_t    len_type;       // LSB 4bit are type\n    uint16_t    col_count;      // 3*4\n    uint16_t    null_off;       // 3*4+2\n    uint16_t    row_size;\n    uint16_t    rsvd;\n    uint64_t    col_list;       // xdb_col_t list\n    xdb_col_t   cols[];\n} xdb_meta_t;\n

"},{"location":"client/api-c/#xdb_col_t","title":"xdb_col_t","text":"

Query Column information

typedef struct {\n    uint16_t    col_len;    // colum total len\n    uint8_t     col_type;   // xdb_type_t\n    uint8_t     col_rsvd;\n    uint32_t    col_off;\n    uint16_t    col_rsvd2;\n    uint8_t     col_nmlen;\n    char        col_name[];\n} xdb_col_t;\n

"},{"location":"client/api-c/#xdb_rowdat_t","title":"xdb_rowdat_t","text":"

Query row data information

typedef struct {\n    uint32_t    len_type;       // LSB 4bit are type\n    uint8_t     rowdat[];\n} xdb_rowdat_t;\n

"},{"location":"client/api-c/#xdb_rowlist_t","title":"xdb_rowlist_t","text":"
typedef uint64_t xdb_row_t; // xdb_rowdat_t\n\ntypedef struct {\n    uint32_t    rl_count;\n    uint32_t    rl_curid;\n    xdb_row_t   rl_pRows[];\n} xdb_rowlist_t;\n
"},{"location":"client/api-python/","title":"Python","text":"

TBD

"},{"location":"develop/connect/","title":"Connect to CrossDB","text":"

You need a connection instance to connect to CrossDB and all operations will use this connection handle.

  • One thread can use only one connection. One connection can only be used by one thread.
  • All opened databases are shared with all opened connections, and they can USE DATABASE db_name to switch connection's default DB.
"},{"location":"develop/connect/#c-apis","title":"C APIs","text":"
  • Open a connection
xdb_conn_t *pConn = xdb_open (NULL);\n

Note

User has to use OPEN DATABASE '[path/]db_name' or CREATE DATABASE '[path/]db_name' or USE DATABASE db_name.

  • Open a connection and create a default memory database if not exist
xdb_conn_t *pConn = xdb_open (\":memory:\");\n
  • Open a connection and create a on-disk database school if not exist as the default database
//  In current folder\nxdb_conn_t *pConn = xdb_open (\"school\");\n
// In specified folder\nxdb_conn_t *pConn = xdb_open (\"/var/crossdb/school\");\n
"},{"location":"develop/ddl/","title":"Data Model","text":""},{"location":"develop/ddl/#create-and-use-a-database","title":"Create and Use a Database","text":"SQLC
-- Create database in current folder\nCREATE DATABASE school;\n-- Create database in specified folder (must exist)\nCREATE DATABASE '/var/crossdb/school';\n-- Create in-memory database \nCREATE DATABASE test ENGINE=memory;\n
// Create database in current folder\nxdb_res_t *pRes = xdb_exec (pConn, \"CREATE DATABASE school\");\n// Create database in specified folder (must exist)\nxdb_res_t *pRes = xdb_exec (pConn, \"CREATE DATABASE '/var/crossdb/school'\");\n// Create in-memory database \nxdb_res_t *pRes = xdb_exec (pConn, \"CREATE DATABASE test ENGINE=memory\");\n
"},{"location":"develop/ddl/#create-a-table","title":"Create a Table","text":"SQLC
CREATE TABLE IF NOT EXISTS student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(256), INDEX (name));\nCREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(256), INDEX (name));\nCREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name));\n
xdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(256), INDEX (name))\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(256), INDEX (name))\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name))\");\n
"},{"location":"develop/ddl/#create-index","title":"Create Index","text":"SQLC
CREATE INDEX idx_name ON student (age);\nCREATE INDEX idx_name ON teacher (age);\nCREATE INDEX idx_name ON student (author);\n
xdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE INDEX idx_name ON student (age)\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE INDEX idx_name ON teacher (age)\");\nxdb_res_t *pRes = pRes = xdb_exec (pConn, \"CREATE INDEX idx_name ON student (author)\");\n
"},{"location":"develop/dml/","title":"Data Manipulation","text":""},{"location":"develop/dml/#insert-rows","title":"Insert Rows","text":"SQLC
INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95);\n\nINSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')\", 'He is a boy.\\nHe likes playing football.\\nWe all like him!');\n
pRes = xdb_exec (pConn, \"INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)\");\n\npRes = xdb_pexec (pConn, \"INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')\", \"He is a boy.\\nHe likes playing football.\\nWe all like him!\");\n// check pRes->errcode = 0 and pRes->affected rows\n
"},{"location":"develop/dml/#update-rows","title":"Update Rows","text":"SQLC
UPDATE student set age=9 WHERE id = 2;\n
pRes = xdb_exec (pConn, \"UPDATE student set age=9 WHERE id = 2\");\n\npRes = xdb_pexec (pConn, \"UPDATE student set age=9 WHERE id = %d\", id);\n\n// check pRes->errcode = 0 and pRes->affected rows\n
"},{"location":"develop/dml/#delete-rows","title":"Delete Rows","text":"SQLC
DELETE FROM student WHERE id = 3;\n
pRes = xdb_exec (pConn, \"DELETE FROM student WHERE id = 3\");\n\npRes = xdb_pexec (pConn, \"DELETE FROM student WHERE id = %d\", id);\n\n// check pRes->errcode = 0 and pRes->affected rows\n
"},{"location":"develop/multi-stmts/","title":"Multi-Statements","text":"

Multi-Statements feature can improve performance a lot especailly for client-server mode. As you can run a batch of statements in one query, then get result one by one in parallel. For database doesn't support Multi-Statements, you have to send one statement, wait result, then send next one which will be low performance especailly when network lattency is big.

SQLC
SELECT COUNT(*) FROM student; SELECT id,name FROM student WHERE id=2;\n
pRes = xdb_exec (pConn, \"SELECT COUNT(*) FROM student; SELECT id,name FROM student WHERE id=2\");\nprintf (\"-- 1st result: \");\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\nprintf (\"-- 2nd result: \");\npRes = xdb_next_result (pConn);\nif (NULL != pRes) {\n    if (NULL != (pRow = xdb_fetch_row (pRes))) {\n        xdb_print_row (pRes->col_meta, pRow, 0);\n        printf (\"\\n\");\n    }\n    xdb_free_result (pRes);\n}\n
"},{"location":"develop/prep-stmts/","title":"Prepared Statements","text":"

Prepared Statements can save the SQL parsing time and improve performance.

Note

Now only support SELECT UPDATE DELETE statements.

"},{"location":"develop/prep-stmts/#steps","title":"Steps","text":"
  • Create Prepared Statments
xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, \"xxx WHERE id=?\");\n
  • Bind paramters
xdb_bind_int (pStmt, 1, id);\n

Note

Bind parameter id starts from 1. Now only support WHERE clause.

  • Execute prepared statements
xdb_res_t *pRes = xdb_stmt_exec (pStmt);\n
  • Close statements
xdb_stmt_close (pStmt);\n
"},{"location":"develop/prep-stmts/#select","title":"Select","text":"
xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, \"SELECT * FROM student WHERE id=?\");\nif (NULL != pStmt) {\n    xdb_bind_int (pStmt, 1, id);\n    pRes = xdb_stmt_exec (pStmt);\n    pRow = xdb_fetch_row (pRes);\n    // handle pRow\n    xdb_free_result (pRes);\n\n    // close when finish using\n    xdb_stmt_close (pStmt);\n    }\n}\n
"},{"location":"develop/prep-stmts/#update","title":"Update","text":"
xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, \"UPDATE student SET age=15 WHERE id=?\");\nif (NULL != pStmt) {\n    xdb_bind_int (pStmt, 1, id);\n    pRes = xdb_stmt_exec (pStmt);\n\n    // close when finish using\n    xdb_stmt_close (pStmt);\n    }\n}\n
"},{"location":"develop/prep-stmts/#delete","title":"Delete","text":"
xdb_stmt_t *pStmt = xdb_stmt_prepare (pConn, \"DELETE FROM student WHERE id=?\");\nif (NULL != pStmt) {\n    xdb_bind_int (pStmt, 1, id[i]);\n    pRes = xdb_stmt_exec (pStmt);\n\n    // close when finish using\n    xdb_stmt_close (pStmt);\n    }\n}\n
"},{"location":"develop/query/","title":"Query Rows","text":""},{"location":"develop/query/#select-rows","title":"Select Rows","text":"SQLC
SELECT id,name,age,class,score from student WHERE id = 2;\n
xdb_res_t *pRes = xdb_exec (pConn, \"SELECT id,name,age,class,score from student WHERE id = 2\");\n\nxdb_res_t *pRes = xdb_pexec (pConn, \"SELECT id,name,age,class,score from student WHERE id = %d\", id);\n\n// check pRes->errcode = 0\n
"},{"location":"develop/query/#get-row-count","title":"Get Row Count","text":"
pRes->row_count;\n
"},{"location":"develop/query/#get-column-information","title":"Get Column information","text":"
for (int i = 0; i < pRes->col_count; ++i) {\n    xdb_col_t *pCol = xdb_column_meta (pRes, i);\n    printf (\"type %d name %s\\n\", pCol->type, pCol->name);\n}\n
"},{"location":"develop/query/#fetch-one-row","title":"Fetch One Row","text":"
xdb_row_t *pRow = xdb_fetch_row (pRes);\n
"},{"location":"develop/query/#get-column-values","title":"Get Column Values","text":"
  • Access by column data type
printf (\"char value %d\\n\",      *(char*)pRow[0]);\nprintf (\"short value %d\\n\",     *(short*)pRow[1]);\nprintf (\"int value %d\\n\",       *(int*)pRow[2]);\nprintf (\"bigint value %\"PRIi64\"\\n\", *(int64_t*)pRow[3]);\nprintf (\"float value %f\\n\",     *(float*)pRow[4]);\nprintf (\"double value %d\\n\",    *(double*)pRow[5]);\nprintf (\"string value %s\\n\",    *(char*)pRow[6]);\nprintf (\"string len   %d\\n\",    *(uint16_t*)(pRow[6]-2));\n
  • Access by API
printf (\"char value %d\\n\",      xdb_column_int(pRes->col_meta, pRow, 0));\nprintf (\"short value %d\\n\",     xdb_column_int(pRes->col_meta, pRow, 1));\nprintf (\"int value %d\\n\",       xdb_column_int(pRes->col_meta, pRow, 2));\nprintf (\"bigint value %\"PRIi64\"\\n\", xdb_column_int64(pRes->col_meta, pRow, 3));\nprintf (\"float value %f\\n\",     xdb_column_float(pRes->col_meta, pRow, 4));\nprintf (\"double value %d\\n\",    xdb_column_double(pRes->col_meta, pRow, 5));\nprintf (\"string value %s\\n\",    xdb_column_str(pRes->col_meta, pRow, 6));\nint len;\nprintf (\"string value %s, len %d\\n\", xdb_column_str2(pRes->col_meta, pRow, 6, &len), len);\n
"},{"location":"develop/transaction/","title":"Transaction","text":"

CrossDB transaction supports ACID. Default isolation level is READ COMMITTED

"},{"location":"develop/transaction/#reader-writeer-mvcc","title":"Reader-Writeer MVCC","text":"

Current CrossDB uses table-level readwrite lock, only one writer connection thread can modify the table, other writer connection threads will be blocked. However the reader connection threads won't be blocked and they'll see the old values. When the writer connection change is committed, the new value is visible by these reader connections (read committed). In short writer before commit will not block readers to read old values

"},{"location":"develop/transaction/#auto-commit","title":"Auto-commit","text":"

Enabled by default.

SQLC
-- Disable auto-commit\nSET AUTOCOMMIT = 0;\n-- Enable auto-commit\nSET AUTOCOMMIT = 1;\n
// Disable auto-commit\nxdb_exec (pConn, \"SET AUTOCOMMIT = 0\");\n// Enable auto-commit\nxdb_exec (pConn, \"SET AUTOCOMMIT = 1\");\n
"},{"location":"develop/transaction/#begin-transaction","title":"Begin Transaction","text":"SQLC
BEGIN;\n
xdb_begin (pConn); // fast\n// or\nxdb_exec (pConn, \"BEGIN\");\n

Note

This operation is optional and transaction will begin automatically when changing table.

"},{"location":"develop/transaction/#commit-transaction","title":"Commit Transaction","text":"SQLC
COMMIT;\n
xdb_commit (pConn); // fast\n// or\nxdb_exec (pConn, \"COMMIT\");\n
"},{"location":"develop/transaction/#rollback-transaction","title":"Rollback Transaction","text":"SQLC
ROLLBACK;\n
xdb_rollback (pConn); // fast\n// or\nxdb_exec (pConn, \"ROLLBACK\");\n

Note

Even there's errors during statements execution, transaction won't be rollbacked automatically, and user have to issue rollback expilicitly.

"},{"location":"get-started/bench/","title":"Bench Test","text":""},{"location":"get-started/bench/#test-with-1000-rows","title":"Test with 1000 rows","text":"
crossdb/bench/c$ ./a.out 1000\n********************** INSERT 1000 with SQL **********************\nUse time 763ns, QPS 1310615\n********************** Random LKUP 5000000 with SQL **********************\nUse time 951987ns, QPS 5252172\nUse time 921033ns, QPS 5428687\nUse time 915605ns, QPS 5460870\nUse time 926288ns, QPS 5397889\n********************** UPDATE 1000 with SQL **********************\nUse time 760ns, QPS 1315789\n********************** DELETE 1000 with SQL **********************\nUse time 438ns, QPS 2283105\n\n********************** INSERT 1000 with SQL **********************\nUse time 687ns, QPS 1455604\n********************** Random LKUP 10000000 with Prepared STMT **********************\nUse time 294717ns, QPS 33930855\nUse time 297268ns, QPS 33639678\nUse time 298728ns, QPS 33475268\nUse time 295278ns, QPS 33866390\n********************** UPDATE 1000 with Prepared SMTT **********************\nUse time 576ns, QPS 1736111\n********************** DELETE 1000 with Prepared SQL **********************\nUse time 252ns, QPS 3968253\n
"},{"location":"get-started/bench/#test-with-10001000-rows","title":"Test with 1000,1000 rows","text":"
crossdb$ make bench\nor\ncrossdb/bench/c$ ./a.out\n\n********************** INSERT 1000000 with SQL **********************\nUse time 539342ns, QPS 1854111\n********************** Random LKUP 1000000 with SQL **********************\nUse time 336044ns, QPS 2975800\nUse time 333927ns, QPS 2994666\nUse time 329699ns, QPS 3033069\nUse time 331632ns, QPS 3015390\n********************** UPDATE 1000000 with SQL **********************\nUse time 579945ns, QPS 1724301\n********************** DELETE 1000000 with SQL **********************\nUse time 405004ns, QPS 2469111\n\n********************** INSERT 1000000 with SQL **********************\nUse time 527486ns, QPS 1895784\n********************** Random LKUP 10000000 with Prepared STMT **********************\nUse time 1678936ns, QPS 5956153\nUse time 1668971ns, QPS 5991715\nUse time 1670993ns, QPS 5984465\nUse time 1652815ns, QPS 6050283\n********************** UPDATE 1000000 with Prepared SMTT **********************\nUse time 381320ns, QPS 2622469\n********************** DELETE 1000000 with Prepared SQL **********************\nUse time 232181ns, QPS 4306984\n
"},{"location":"get-started/bench/#maximum-performance","title":"Maximum performance","text":"

This will build with -O3 and -march=native flags

crossdb/bench/c$ make fast\n
"},{"location":"get-started/install/","title":"Build and Install","text":""},{"location":"get-started/install/#build","title":"Build","text":"
crossdb$ make\nmake build                Build crossdb library and tool\nmake debug                Build crossdb library and tool with debug\nmake run                  Run crossdb tool\nmake clean                Clean build result\nmake install              Install crossdb(lib&tool&header) to Linux/FreeBSD\nmake uninstall            Uninstall crossdb from Linux/FreeBSD\nmake installmacos         Install crossdb(lib&tool&header) to MacOS\nmake uninstallmacos       Uninstall crossdb from MacOS\nmake example              Build and run example (need to install crossdb first)\nmake bench                Build and run bench test (need to install crossdb first)\n
"},{"location":"get-started/install/#linuxfreebsd","title":"Linux/FreeBSD","text":"
make build\nsudo make install\n
"},{"location":"get-started/install/#macos","title":"MacOS","text":"
make build\nsudo make installmacos\n
"},{"location":"get-started/install/#windows","title":"Windows","text":"

You need to install MINGW64 to build. Then set gcc path to system environment variables Path and make sure gcc can run.

build.bat\n
"},{"location":"get-started/tutorial/","title":"Turorial","text":""},{"location":"get-started/tutorial/#open-conection-and-create-default-memory-database","title":"Open conection and create default memory database","text":"
xdb_res_t   *pRes;\nxdb_row_t   *pRow;\n\nxdb_conn_t  *pConn = xdb_open (\":memory:\");\n
"},{"location":"get-started/tutorial/#create-table","title":"Create Table","text":"
pRes = xdb_exec (pConn, \"CREATE TABLE student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score FLOAT, info CHAR(255))\");\nXDB_CHECK(pRes, printf (\"Can't create table student\\n\"); goto error;);\npRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS teacher (id INT PRIMARY KEY, name CHAR(16), age INT, info CHAR(255), INDEX (name))\");\nXDB_CHECK(pRes, printf (\"Can't create table teacher\\n\"); goto error;);\npRes = xdb_exec (pConn, \"CREATE TABLE IF NOT EXISTS book (id INT PRIMARY KEY, name CHAR(64), author CHAR(32), count INT, INDEX (name))\");\nXDB_CHECK(pRes, printf (\"Can't create table book\\n\"); goto error;);\n
"},{"location":"get-started/tutorial/#insert-rows","title":"Insert Rows","text":"
pRes = xdb_exec (pConn, \"INSERT INTO student (id,name,age,class,score) VALUES (1,'jack',10,'3-1',90),(2,'tom',11,'2-5',91),(3,'jack',11,'1-6',92),(4,'rose',10,'4-2',90),(5,'tim',10,'3-1',95)\");\nXDB_CHECK(pRes, printf (\"Can't insert table student\\n\"); goto error;);\npRes = xdb_pexec (pConn, \"INSERT INTO student (id,name,age,class,score,info) VALUES (6,'Tony',10,'3-1',95,'%s')\", \"He is a boy.\\nHe likes playing football.\\nWe all like him!\");\nXDB_CHECK(pRes, printf (\"Can't insert table student\\n\"); goto error;);\npRes = xdb_pexec (pConn, \"INSERT INTO student (id,name,age,class,score,info) VALUES (7,'Wendy',10,'3-1',95,'%s')\", \"She is a girl.\\nShe likes cooking.\\nWe all love her!\");\nXDB_CHECK(pRes, printf (\"Can't insert table student\\n\"); goto error;);\npRes = xdb_exec (pConn, \"INSERT INTO teacher (id,name,age) VALUES (1,'Tomas',40),(2,'Steven',50),(3,'Bill',31),(4,'Lucy',29)\");\nXDB_CHECK(pRes, printf (\"Can't insert table teacher\\n\"); goto error;);\npRes = xdb_exec (pConn, \"INSERT INTO book (id,name,author,count) VALUES (1,'Romeo and Juliet','Shakespeare',10),(2,'Pride and Prejudice','Austen',5),(3,'Great Expectations','Dickens',8),(4,'Sorrows of Young Werther','Von Goethe',4)\");\nXDB_CHECK(pRes, printf (\"Can't insert table book\\n\"); goto error;);\n
"},{"location":"get-started/tutorial/#select-rows","title":"Select Rows","text":"
pRes = xdb_exec (pConn, \"SELECT * from student\");\nprintf (\"=== Select all %d rows\\n\", (int)pRes->row_count);\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
"},{"location":"get-started/tutorial/#update-rows","title":"Update Rows","text":"
printf (\"\\n=== Update age = 9 for id = 2\\n\");\npRes = xdb_exec (pConn, \"UPDATE student set age=9 WHERE id = 2\");\nXDB_CHECK(pRes, printf (\"Can't update id=%d\\n\",2); goto error;);\n\npRes = xdb_exec (pConn, \"SELECT id,name,age,class,score from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
"},{"location":"get-started/tutorial/#delete-rows","title":"Delete Rows","text":"
printf (\"\\n=== Delete id = 3\\n\");\npRes = xdb_exec (pConn, \"DELETE FROM student WHERE id = 3\");\nXDB_CHECK(pRes, printf (\"Can't delete id=%d\\n\",3); goto error;);\n\npRes = xdb_exec (pConn, \"SELECT * from student WHERE id = 3\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nwhile (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
"},{"location":"get-started/tutorial/#aggregation-function","title":"Aggregation function","text":"
printf (\"\\n=== AGG COUNT,MIN,MAX,SUM,AVG\\n\");\npRes = xdb_exec (pConn, \"SELECT COUNT(*),MIN(score),MAX(score),SUM(score),AVG(score) FROM student\");\nprintf (\"=== select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
"},{"location":"get-started/tutorial/#transaction-rollback","title":"Transaction Rollback","text":"
printf (\"\\n=== Rollback\\n\");\nxdb_begin (pConn);\npRes = xdb_exec (pConn, \"UPDATE student set age=15 WHERE id = 2\");\npRes = xdb_exec (pConn, \"SELECT id,name,age from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\nprintf (\"-- rollback\\n\");\nxdb_rollback (pConn);\npRes = xdb_exec (pConn, \"SELECT id,name,age from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
"},{"location":"get-started/tutorial/#transaction-commit","title":"Transaction Commit","text":"
printf (\"\\n=== Commit\\n\");\nxdb_begin (pConn);\npRes = xdb_exec (pConn, \"UPDATE student set age=15 WHERE id = 2\");\npRes = xdb_exec (pConn, \"SELECT * from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\nprintf (\"-- commit\\n\");\nxdb_commit (pConn);\npRes = xdb_exec (pConn, \"SELECT * from student WHERE id = 2\");\nprintf (\"select %d rows\\n\", (int)pRes->row_count);\nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n
"},{"location":"get-started/tutorial/#multi-statements","title":"Multi-Statements","text":"
printf (\"\\n=== Muti-Statements\\n\");\npRes = xdb_exec (pConn, \"SELECT COUNT(*) FROM student; SELECT id,name FROM student WHERE id=2\");\n// count(*) \nif (NULL != (pRow = xdb_fetch_row (pRes))) {\n    xdb_print_row (pRes->col_meta, pRow, 0);\n    printf (\"\\n\");\n}\nxdb_free_result (pRes);\n// select\npRes = xdb_next_result (pConn);\nif (NULL != pRes) {\n    if (NULL != (pRow = xdb_fetch_row (pRes))) {\n        xdb_print_row (pRes->col_meta, pRow, 0);\n        printf (\"\\n\");\n    }\n    xdb_free_result (pRes);\n}\n\nxdb_exec (pConn, \"SHELL\");\n
"},{"location":"get-started/tutorial/#enter-embedded-shell","title":"Enter Embedded Shell","text":"
xdb_exec (pConn, \"SHELL\");\n
"},{"location":"get-started/tutorial/#example-output","title":"Example Output","text":"
crossdb$ make example\n=== Select all 7 rows\nid=1 name='jack' age=10 class='3-1' score=90.000000 info=''\nid=2 name='tom' age=11 class='2-5' score=91.000000 info=''\nid=3 name='jack' age=11 class='1-6' score=92.000000 info=''\nid=4 name='rose' age=10 class='4-2' score=90.000000 info=''\nid=5 name='tim' age=10 class='3-1' score=95.000000 info=''\nid=6 name='Tony' age=10 class='3-1' score=95.000000 info='He is a boy.\nHe likes playing football.\nWe all like him!'\nid=7 name='Wendy' age=10 class='3-1' score=95.000000 info='She is a girl.\nShe likes cooking.\nWe all love her!'\n\n=== Update age = 9 for id = 2\nselect 1 rows\nid=2 name='tom' age=9 class='2-5' score=91.000000\n\n=== Delete id = 3\nselect 0 rows\n=== select 1 rows\nCOUNT(*)=6 MIN(score)=90.000000 MAX(score)=95.000000 SUM(score)=556.000000 AVG(score)=92.666667\n\n=== Muti-Statements\nCOUNT(*)=6\nid=2 name='tom'\n   _____                   _____  ____      _\n  / ____|                 |  __ \\|  _ \\   _| |_\n | |     _ __ ___  ___ ___| |  | | |_) | |_   _|\n | |    | '__/ _ \\/ __/ __| |  | |  _ <    |_|\n | |____| | | (_) \\__ \\__ \\ |__| | |_) |  0.6.0\n  \\_____|_|  \\___/|___/___/_____/|____/ crossdb.org\n\n============ Welcome to CrossDB Shell ============\n<help>: Help Info       <F1>: Shortcuts\n<exit>: Exit shell      <TAB>: Auto completion\n\nXDB> exit\n
"},{"location":"sql/backup/","title":"Backup and Restore","text":""},{"location":"sql/backup/#source","title":"Source","text":"

Load and execute SQL file into current database

SOURCE '[path/]sqlfile'\n
"},{"location":"sql/backup/#dump-database","title":"Dump Database","text":"

Dump current database to console

DUMP DATABASE\n

Dump specified database with options

DUMP DATABASE db_name [dump_option] ...\n\ndump_option:\n    NODROP      : Don't add DROP statement\n  | NOCREATE    : Don't add CREATE statement\n  | NODATA      : Don't dump ROW data\n  | INTO '[path/]outfile' : Dump into file instead of console\n
"},{"location":"sql/data-types/","title":"Data Types","text":"Type Bytes Description Note BOOL 1 Bool, the value range is {true, false}. TBD TINYINT 1 Single-byte integer, the value range is [-128, 127]. SMALLINT 2 Short integer, the value range is [-32768, 32767]. INT 4 Integer, the value range is [-2^31, 2^31-1]. BIGINT 8 Long integer, the value range is [-2^63, 2^63-1]. TINYINT UNSIGNED 1 unsigned single-byte integer, the value range is [0, 255]. TBD SMALLINT UNSIGNED 2 unsigned integer, the value range is [0, 65535]. TBD INT UNSIGNED 4 Unsigned integer, the value range is [0, 2^32-1]. TBD BIGINT UNSIGNED 8 unsigned long integer, the value range is [0, 2^64-1]. TBD TIMESTAMP 8 Default precision is microsecond. TBD FLOAT 4 Floating point number. DOUBLE 8 Double precision floating point number. CHAR [COLLATE collation_name] User-defined, max 65535 Fixed-length UTF-8 string. VARCHAR [COLLATE collation_name] User-defined, max 65535 Variable-Length UTF-8 string. TBD BINARY User-defined, max 65535 Fixed-length binary data. TBD VARBINARY User-defined, max 65535 Variable-Length binary data. TBD"},{"location":"sql/data-types/#collation","title":"Collation","text":"Type Description NOCASE Case insensitive [Default]. BINARY Case sensitive."},{"location":"sql/data-types/#escape-characters","title":"Escape Characters","text":"Escape Character Actual Meaning \\n Line Break \\r Carriage Return \\t tab \\' Single quote ' \\\" Double quote \" ` backtick ` \\ Back Slash \\ \\% % see below for details _ _ see below for details"},{"location":"sql/database/","title":"Database","text":""},{"location":"sql/database/#create-database","title":"Create Database","text":"
CREATE DATABASE [IF NOT EXISTS] {db_name | '[path/]db_name'} [db_option] ...\n\ndb_option:\n    ENGINE = {MMAP | MEMORY}\n  | LOCKMODE = {THREAD | PROCESS | NOLOCK}\n
LOCKMODE Lock used Description THREAD [default] high-performance thread read-write lock For single process multiple threads access. PROCESS file read-write lock For multiple processes multiple threads access. NOLOCK no lock For test/diag purpose only.

Note

'[path]/db_name' is only valid for embedded database. db_options are default values for new created tables and you can use table_options to overwrite these default values.

"},{"location":"sql/database/#open-database","title":"Open Database","text":"
OPEN DATABASE {db_name | '[path/]db_name'} [dbg_option] ...\n\ndbg_option:\n    FLUSHMODE = {ASYNC | SYNC | NOSYNC}\n  | LOCKMODE = {THREAD | PROCESS | NOLOCK}\n

Note

This command can only be used for embedded database. dbg_option is only valid for current session and only for debug purpose.

"},{"location":"sql/database/#close-database","title":"Close Database","text":"
CLOSE DATABASE [IF EXISTS] db_name\n

Note

This command can only be used for embedded database.

"},{"location":"sql/database/#drop-database","title":"Drop Database","text":"
DROP DATABASE [IF EXISTS] db_name\n
"},{"location":"sql/database/#use-database","title":"Use Database","text":"
USE db_name\n
"},{"location":"sql/database/#show-databases","title":"Show Databases","text":"
SHOW DATABASES [WHERE expr]\n
XDB> show DATABASES ;\n+----------+--------+-----------+\n| database | engine | data_path |\n+----------+--------+-----------+\n| system   |        |           |\n| memory   |        |           |\n+----------+--------+-----------+\n2 rows in set (0.012 ms)\n
"},{"location":"sql/dml/","title":"Data Manipulation","text":""},{"location":"sql/dml/#insert","title":"Insert","text":"
INSERT INTO tbl_name \n    [(col_name,...)] \n    VALUES (val,...), ...\n\nINSERT INTO tbl_name SET col_name = value, [col_name = value], ...\n
"},{"location":"sql/dml/#replace","title":"Replace","text":"
REPLACE INTO tbl_name \n    [(col_name,...)] \n    VALUES (val,...), ...\n
"},{"location":"sql/dml/#select","title":"Select","text":"
SELECT col_name,... FROM tbl_name\n    [WHERE expr]\n    [ORDER BY col_name [ASC | DESC], ...]\n    [LIMIT {[offset,] row_count | row_count OFFSET offset}]\n
"},{"location":"sql/dml/#update","title":"Update","text":"
UPDATE tbl_name\n    SET col_name=val, ... \n    [WHERE expr]\n    [ORDER BY col_name [ASC | DESC], ...]\n    [LIMIT {[offset,] row_count | row_count OFFSET offset}]\n
"},{"location":"sql/dml/#delete","title":"Delete","text":"
DELETE FROM tbl_name\n    [WHERE expr]\n    [ORDER BY col_name [ASC | DESC], ...]\n    [LIMIT {[offset,] row_count | row_count OFFSET offset}]\n
"},{"location":"sql/dml/#explain","title":"Explain","text":"
EXPLAIN SELECT statement\n
"},{"location":"sql/functions/","title":"Functions","text":""},{"location":"sql/functions/#aggregate-functions","title":"Aggregate Functions","text":"Function Return Type Description COUNT(*) BIGINT The number of rows. COUNT(col_name) BIGINT The number of rows in the specified column. MIN(col_name) Same with column The minimum value of a specific column MAX(col_name) Same with column The maximum value of a specific column. SUM(col_name) DOUBLE or BIGINT The sum of a specific column in a table AVG(col_name) DOUBLE The average value of the specified column."},{"location":"sql/indexes/","title":"Index","text":""},{"location":"sql/indexes/#create-index","title":"Create Index","text":"
CREATE [UNIQUE] INDEX idx_name \n    [USING {HASH | BTREE}] \n    ON tbl_name (col_name,...)\n
"},{"location":"sql/indexes/#drop-index","title":"Drop Index","text":"
DROP INDEX idx_name ON tbl_name\n
"},{"location":"sql/indexes/#show-index","title":"Show Index","text":"
SHOW {INDEX | INDEXES | KEYS} [FROM tbl_name] [WHERE expr]\n
XDB> show INDEXES ;\n+---------+---------+------+----------+\n| table   | idx_key | type | col_list |\n+---------+---------+------+----------+\n| student | PRIMARY | HASH | id       |\n| student | name_2  | HASH | name     |\n| teacher | PRIMARY | HASH | id       |\n| teacher | name_2  | HASH | name     |\n| book    | PRIMARY | HASH | id       |\n| book    | name_2  | HASH | name     |\n+---------+---------+------+----------+\n6 rows in set (0.016 ms)\n
"},{"location":"sql/misc/","title":"Misc","text":""},{"location":"sql/misc/#shell","title":"Shell","text":"

Enter interactive shell

SHELL\n
"},{"location":"sql/misc/#help","title":"Help","text":"
HELP [topic] [subtopic]\n
"},{"location":"sql/name-limit/","title":"Name and Limit","text":""},{"location":"sql/name-limit/#case-sensitive","title":"Case Sensitive","text":"Type Case-sensitive Keyword False Function False DB Name False Table Name False Column Name False Index Name False"},{"location":"sql/name-limit/#limit","title":"Limit","text":"Type Limit DB Name 64 Table Name 64 Column Name 64 Index Name 64 Single SQL statement 1048576 (1M) DB per process 1024 Table per DB 4095 Rows per Table 2,000,000,000 (2B) Row size 524288 (512K) Index per Table 16 Filter Fields 64"},{"location":"sql/operators/","title":"Operators","text":""},{"location":"sql/operators/#comparison-operators","title":"Comparison Operators","text":"Operator Description Note = Equal to <>, != Not equal to TBD > Greater than TBD < Less than TBD >= Greater than or equal to TBD <= Less than or equal to TBD IS NULL NULL value test TBD IS NOT NULL NOT NULL value test TBD BETWEEN ... AND ... Whether a value is within a range of values TBD NOT BETWEEN ... AND ... Whether a value is not within a range of values TBD IN Whether a value is not within a set of values TBD NOT IN Negation of simple pattern matching TBD LIKE Wildcard match TBD

LIKE is used together with wildcards to match strings. Its usage is described as follows:

  • '%' matches 0 or any number of characters, '_' matches any single ASCII character.
  • \\_ is used to match the _ in the string.
"},{"location":"sql/operators/#logical-operators","title":"Logical Operators","text":"Operator Description Note AND Logical AND OR Logical OR TBD"},{"location":"sql/statements/","title":"SQL Statements","text":"Statement Descritpion Note BEGIN Start a new transaction. COMMIT Commits the open transaction if exists. CLOSE DATABASE Close an opened database. Embedded Mode only CREATE DATABASE Create a database. CREATE INDEX Create an index on the specified table. CREATE TABLE Create a new table. DELETE Delete rows in a table. DESCRIBE Describe the specified table. DROP DATABASE Drop a database. DROP INDEX Drop the specified index on the specified table. DROP TABLE Drop the specified table. DUMP DATABASE Dump database into file. EXPLAIN Returns detailed information on how the query is executed. HELP SQL statements help. INSERT Insert data into a table. OPEN DATABASE Open a database on disk. Embedded Mode only ROLLBACK Roll back the open transaction if exists. SELECT Retrieves data from a table. SET AUTOCOMMIT Set session transaction auto-commit. SHELL Enter interactive shell. SHOW COLUMNS Show the list of columns within a given table. SHOW CREATE TABLE Show the CREATE TABLE statement. SHOW DATABASE Show the list of databases. SHOW INDEXES Show the list of indexes associated with a given table. SHOW TABLES Show the list of tables in database. SOURCE Load and execute SQL file. UPDATE Modifies rows in a table. USE Use the database as the current default database."},{"location":"sql/table/","title":"Table","text":""},{"location":"sql/table/#create-table","title":"Create Table","text":"
CREATE TABLE [IF NOT EXISTS] tbl_name (create_definition, ...) [table_option] ...\n\nCREATE OR REPLACE TABLE tbl_name (create_definition, ...)  [table_option] ...\n\ncreate_definition:\n    col_name data_type [column_option] ...\n  | PRIMARY KEY index_definition\n  | UNIQUE [KEY | INDEX] [idx_name] index_definition\n  | {KEY | INDEX} [idx_name] index_definition\n\ndata_type:\n    BOOL\n  | TINYINT [UNSIGNED]\n  | SMALLINT [UNSIGNED]\n  | {INT | INTEGER} [UNSIGNED]\n  | BIGINT [UNSIGNED]\n  | TIMESTAMP\n  | CHAR[(n)] [COLLATE <collation_name>]\n  | VARCHAR[(n)] [COLLATE <collation_name>]\n  | BINARY[(n)]\n  | VBINARY[(n)]\n\ncollation_name:\n    BINARY\n  | NOCASE\n\ncolumn_option:\n    {NOT NULL | NULL} \n  | DEFAULT value\n  | AUTO_INCREMENT \n  | [PRIMARY] KEY\n  | UNIQUE [KEY]\n\nindex_definition: [USING {HASH | BTREE}] (col_name, ...)\n\ntable_option:\n    ENGINE = MEMORY\n  | MAX_ROWS = value\n  | MIN_ROWS = value\n  | LOCKMODE = {THREAD | PROCESS | NOLOCK}\n  | ROWLOCK = {0 | 1}\n  | MVCC = {0 | 1}\n
"},{"location":"sql/table/#drop-table","title":"Drop Table","text":"
DROP TABLE [IF EXISTS] tbl_name\n
"},{"location":"sql/table/#show-tables","title":"Show Tables","text":""},{"location":"sql/table/#show-all-tables","title":"Show All Tables","text":"
SHOW TABLES [LIKE pattern] [WHERE expr]\n
XDB> show TABLES ;\n+---------+--------+-------------+-----------+\n| table   | engine | primary_key | data_path |\n+---------+--------+-------------+-----------+\n| student |        |             |           |\n| teacher |        |             |           |\n| book    |        |             |           |\n+---------+--------+-------------+-----------+\n3 rows in set (0.022 ms)\n
"},{"location":"sql/table/#show-create-table","title":"Show Create Table","text":"
SHOW CREATE TABLE tbl_name\n
XDB> show CREATE TABLE student ;\n+-------------------------------+\n| schema                        |\n+-------------------------------+\n| CREATE TABLE student (        |\n|   id               INT,       |\n|   name             CHAR(16),  |\n|   age              INT,       |\n|   class            CHAR(16),  |\n|   score            FLOAT,     |\n|   info             CHAR(256), |\n|   PRIMARY KEY (id),           |\n|   KEY         name_2 (name)   |\n| );                            |\n+-------------------------------+\n1 row in set (0.026 ms)\n
"},{"location":"sql/table/#show-table-columns","title":"Show Table Columns","text":"
{DESC | DESCRIBE} tbl_name\n\nSHOW COLUMNS [FROM tbl_name] [WHERE expr]\n
XDB> DESCRIBE student ;\n+--------+-------+-----+\n| column | type  | len |\n+--------+-------+-----+\n| id     | INT   | 4   |\n| name   | CHAR  | 16  |\n| age    | INT   | 4   |\n| class  | CHAR  | 16  |\n| score  | FLOAT | 4   |\n| info   | CHAR  | 256 |\n+--------+-------+-----+\n6 rows in set (0.023 ms)\n
"},{"location":"sql/transaction/","title":"Transaction and Lock","text":""},{"location":"sql/transaction/#begin-transaction","title":"Begin Transaction","text":"
BEGIN\n\nSTART TRANSACTION [READ WRITE | READ ONLY]\n

Note

Will commit any existing open transaction

"},{"location":"sql/transaction/#commit-transaction","title":"Commit Transaction","text":"
COMMIT\n
"},{"location":"sql/transaction/#rollback-transaction","title":"Rollback Transaction","text":"
ROLLBACK\n
"},{"location":"sql/transaction/#lock-tables","title":"Lock Tables","text":"
-- TBD\nLOCK {TABLE | TABLES} tbl_name { READ | WRITE } [, tbl_name { READ | WRITE }] ...\n

Note

This command must be executed after BEGIN transaction for performance or prevent other sessions to , and locks will be released after commit transaction.

"},{"location":"sql/transaction/#set-isolation-level","title":"Set Isolation Level","text":"
-- TBD\nSET TRANSACTION ISOLATION LEVEL { READ COMMITTED | REPEATABLE READ | READ UNCOMMITTED | SERIALIZABLE }\n

Note

TBD, default is READ COMMITTED.

"},{"location":"sql/transaction/#set-auto-commit","title":"Set Auto Commit","text":"
SET AUTOCOMMIT = {0 | 1}\n

Note

Default AUTOCOMMIT = 1.

"},{"location":"sysdb/information-schema/","title":"INFORMATION_SCHEMA","text":"

TBD

"},{"location":"sysdb/system/","title":"system","text":""},{"location":"sysdb/system/#databases","title":"Databases","text":"
XDB> SELECT * FROM system.databases;\n+----------+--------+-----------+\n| database | engine | data_path |\n+----------+--------+-----------+\n| system   |        |           |\n| memory   |        |           |\n+----------+--------+-----------+\n2 rows in set (0.010 ms)\n
"},{"location":"sysdb/system/#tables","title":"Tables","text":"
XDB> SELECT * FROM system.tables where database='memory';\n+----------+---------+--------+-----------+-------------------------------+\n| database | table   | engine | data_path | schema                        |\n+----------+---------+--------+-----------+-------------------------------+\n| memory   | student |        |           | CREATE TABLE student (        |\n|          |         |        |           |   id               INT,       |\n|          |         |        |           |   name             CHAR(16),  |\n|          |         |        |           |   age              INT,       |\n|          |         |        |           |   class            CHAR(16),  |\n|          |         |        |           |   score            FLOAT,     |\n|          |         |        |           |   info             CHAR(256), |\n|          |         |        |           |   PRIMARY KEY (id),           |\n|          |         |        |           |   KEY         name_2 (name)   |\n|          |         |        |           | );                            |\n| memory   | teacher |        |           | CREATE TABLE teacher (        |\n|          |         |        |           |   id               INT,       |\n|          |         |        |           |   name             CHAR(16),  |\n|          |         |        |           |   age              INT,       |\n|          |         |        |           |   info             CHAR(256), |\n|          |         |        |           |   PRIMARY KEY (id),           |\n|          |         |        |           |   KEY         name_2 (name)   |\n|          |         |        |           | );                            |\n| memory   | book    |        |           | CREATE TABLE book (           |\n|          |         |        |           |   id               INT,       |\n|          |         |        |           |   name             CHAR(64),  |\n|          |         |        |           |   author           CHAR(32),  |\n|          |         |        |           |   count            INT,       |\n|          |         |        |           |   PRIMARY KEY (id),           |\n|          |         |        |           |   KEY         name_2 (name)   |\n|          |         |        |           | );                            |\n+----------+---------+--------+-----------+-------------------------------+\n3 rows in set (0.020 ms)\n
"},{"location":"sysdb/system/#columns","title":"Columns","text":"
XDB> SELECT * FROM system.columns where database='memory';\n+----------+---------+--------+-------+-----+\n| database | table   | column | type  | len |\n+----------+---------+--------+-------+-----+\n| memory   | student | id     | INT   | 4   |\n| memory   | student | name   | CHAR  | 16  |\n| memory   | student | age    | INT   | 4   |\n| memory   | student | class  | CHAR  | 16  |\n| memory   | student | score  | FLOAT | 4   |\n| memory   | student | info   | CHAR  | 256 |\n| memory   | teacher | id     | INT   | 4   |\n| memory   | teacher | name   | CHAR  | 16  |\n| memory   | teacher | age    | INT   | 4   |\n| memory   | teacher | info   | CHAR  | 256 |\n| memory   | book    | id     | INT   | 4   |\n| memory   | book    | name   | CHAR  | 64  |\n| memory   | book    | author | CHAR  | 32  |\n| memory   | book    | count  | INT   | 4   |\n+----------+---------+--------+-------+-----+\n14 rows in set (0.017 ms)\n
"},{"location":"sysdb/system/#indexes","title":"Indexes","text":"
XDB> SELECT * FROM system.indexes where database='memory';\n+----------+---------+---------+------+----------+\n| database | table   | idx_key | type | col_list |\n+----------+---------+---------+------+----------+\n| memory   | student | PRIMARY | HASH | id       |\n| memory   | student | name_2  | HASH | name     |\n| memory   | teacher | PRIMARY | HASH | id       |\n| memory   | teacher | name_2  | HASH | name     |\n| memory   | book    | PRIMARY | HASH | id       |\n| memory   | book    | name_2  | HASH | name     |\n+----------+---------+---------+------+----------+\n6 rows in set (0.016 ms)\n
"}]} \ No newline at end of file diff --git a/server/server/index.html b/server/server/index.html deleted file mode 100755 index 346daf8..0000000 --- a/server/server/index.html +++ /dev/null @@ -1,50 +0,0 @@ - Server - CrossDB

Server

Create Server

CREATE SERVER [IF NOT EXISTS] server_name [server_option ...]
-
-server_option:
-    IP = ipaddr
-  | PORT = xxx 
-  | TYPE = {SERVER | WEBUI | MYSQL}
-  | AUTH = {NO | PASSWORD | ACL}
-  | ENABLE = {true | false}
-  | PASSWORD = 'string'
-  | DB = (db_name,...)
-

Modify Server

ALTER SERVER server_name [server_option ...]
-
-server_option:
-  | AUTH = {NO | PASSWORD | ACL}
-  | ENABLE = {true | false}
-  | PASSWORD = xxxx
-  | DB = (db_name,...)
-

Drop Server

DROP SERVER [IF EXISTS] server_name
-

Show Server

SHOW SERVERS
-

Comments

\ No newline at end of file diff --git a/server/status/index.html b/server/status/index.html deleted file mode 100755 index 709c845..0000000 --- a/server/status/index.html +++ /dev/null @@ -1,33 +0,0 @@ - Status - CrossDB

Status

Show Status

SHOW [SESSION | GLOBAL] STATUS
-
global status, uptime, dbs, tables, sql stats

Show Sessions

SHOW SESSIONS
-
pid, connect time, (telnet|client), ip, port, user, sql stats

Comments

\ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index 8796c0c..b43fd97 100755 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,222 +2,197 @@ https://crossdb.org/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/CHANGELOG/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/community/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/faq/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/glossary/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/intro/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/about/buy/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/about/privacy/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/about/refund/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/about/terms/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/admin/data-backup/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/admin/data-restore/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/admin/shell/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/client/api-c/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/client/api-python/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/develop/connect/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/develop/ddl/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/develop/dml/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/develop/multi-stmts/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/develop/prep-stmts/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/develop/query/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/develop/transaction/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/get-started/bench/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/get-started/install/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/get-started/tutorial/ - 2024-08-18 - daily - - - https://crossdb.org/replication/logic-replication/ - 2024-08-18 - daily - - - https://crossdb.org/replication/pubsub/ - 2024-08-18 - daily - - - https://crossdb.org/replication/replication/ - 2024-08-18 - daily - - - https://crossdb.org/server/server/ - 2024-08-18 - daily - - - https://crossdb.org/server/status/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/backup/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/data-types/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/database/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/dml/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/functions/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/indexes/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/misc/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/name-limit/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/operators/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/statements/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/table/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sql/transaction/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sysdb/information-schema/ - 2024-08-18 + 2024-08-19 daily https://crossdb.org/sysdb/system/ - 2024-08-18 + 2024-08-19 daily \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 703fbe487edcb34d3da1f6750e49bbd9b13e3ce2..f48a2b7fc0779f45b069aba6b7b9e6b3f4701ee0 100755 GIT binary patch literal 493 zcmVgcD#u-Z4JMnN zPvgG%`Qvl@*gW@l-CP49Z=`XeeKRqa_r{#h=Ph~02!*z}j)v?cH)P%_&2IbD^miLM zE*)G;>(Pa5`%5n*-PoFm+_3i0nah*ghCm#%>mPOx@7mpCd;cU&-s*0e*$L8!hlKyi3X5}K-^x3gbOKAoqS<$xQQMmB4~;7%0?S@o zEE$nyNTD)1GsymJ(#!KnO4^dxEs$r){vMPG=@^X0b<@SQu9|o$NIGo;5Gs^Kg;Pv6 zG;4TMIFdd&eAPI`q9?0Ql^|jpeDti(mJ3#pD64QVB?~Y{**7S(NhAvj1DV=Y5iL@Z jxN*oe!iCpfe^6^w%30>!|Cg;7LhgS9P}TFT`WFBI+H&~b literal 531 zcmV+u0_^=CiwFn+$-rg;|8r?{Wo=<_E_iKh0L|IGZrd;r0N_1OVQ81>1R2~yR!|g8 zIuz~FKER1QOGNo+-qDWUzLcC49=jAc4Hiuk^aqi?HEux^EWt>WF=kJ~V8+{^3^23<=-(xYY3$pog1NwV)$P}-U8oyHjgfo3Z$ zmW;@CNg*>DHPrfTlFPH9wxlJoTOgO3{VfO+)*r328rH4n;%Iey+as2m%0Ok1>l6DB z3G*5A`%NT`fs3#lLMNvrRu_wFtu1&?NHT2$5DJt@JLfH^TK2Dp0D&uMgTYscTg+S1 z@>Bslw$6IX@@z3-hI$qexR^`qM_;RJfwmgSoWMXPwsxSowrbos#_ZRFP<#CwN20R6 V)_wQ?W$TTQ`#($3i?ARY007#D0(<}f diff --git a/sql/backup/index.html b/sql/backup/index.html index 2cfad18..b407630 100755 --- a/sql/backup/index.html +++ b/sql/backup/index.html @@ -1,4 +1,4 @@ - Backup and Restore - CrossDB

Backup and Restore

Source

Load and execute SQL file into current database

SOURCE '[path/]sqlfile'
+ Backup and Restore - CrossDB      

Data Types

Type Bytes Description Note
BOOL 1 Bool, the value range is {true, false}. TBD
TINYINT 1 Single-byte integer, the value range is [-128, 127].
SMALLINT 2 Short integer, the value range is [-32768, 32767].
INT 4 Integer, the value range is [-2^31, 2^31-1].
BIGINT 8 Long integer, the value range is [-2^63, 2^63-1].
TINYINT UNSIGNED 1 unsigned single-byte integer, the value range is [0, 255]. TBD
SMALLINT UNSIGNED 2 unsigned integer, the value range is [0, 65535]. TBD
INT UNSIGNED 4 Unsigned integer, the value range is [0, 2^32-1]. TBD
BIGINT UNSIGNED 8 unsigned long integer, the value range is [0, 2^64-1]. TBD
TIMESTAMP 8 Default precision is microsecond. TBD
FLOAT 4 Floating point number.
DOUBLE 8 Double precision floating point number.
CHAR [COLLATE collation_name] User-defined, max 65535 Fixed-length UTF-8 string.
VARCHAR [COLLATE collation_name] User-defined, max 65535 Variable-Length UTF-8 string. TBD
BINARY User-defined, max 65535 Fixed-length binary data. TBD
VARBINARY User-defined, max 65535 Variable-Length binary data. TBD

Collation

Type Description
NOCASE Case insensitive [Default].
BINARY Case sensitive.

Escape Characters

Escape Character Actual Meaning
\n Line Break
\r Carriage Return
\t tab
\' Single quote '
\" Double quote "
` backtick `
\ Back Slash \
\% % see below for details
_ _ see below for details

Comments

Data Types

Type Bytes Description Note
BOOL 1 Bool, the value range is {true, false}. TBD
TINYINT 1 Single-byte integer, the value range is [-128, 127].
SMALLINT 2 Short integer, the value range is [-32768, 32767].
INT 4 Integer, the value range is [-2^31, 2^31-1].
BIGINT 8 Long integer, the value range is [-2^63, 2^63-1].
TINYINT UNSIGNED 1 unsigned single-byte integer, the value range is [0, 255]. TBD
SMALLINT UNSIGNED 2 unsigned integer, the value range is [0, 65535]. TBD
INT UNSIGNED 4 Unsigned integer, the value range is [0, 2^32-1]. TBD
BIGINT UNSIGNED 8 unsigned long integer, the value range is [0, 2^64-1]. TBD
TIMESTAMP 8 Default precision is microsecond. TBD
FLOAT 4 Floating point number.
DOUBLE 8 Double precision floating point number.
CHAR [COLLATE collation_name] User-defined, max 65535 Fixed-length UTF-8 string.
VARCHAR [COLLATE collation_name] User-defined, max 65535 Variable-Length UTF-8 string. TBD
BINARY User-defined, max 65535 Fixed-length binary data. TBD
VARBINARY User-defined, max 65535 Variable-Length binary data. TBD

Collation

Type Description
NOCASE Case insensitive [Default].
BINARY Case sensitive.

Escape Characters

Escape Character Actual Meaning
\n Line Break
\r Carriage Return
\t tab
\' Single quote '
\" Double quote "
` backtick `
\ Back Slash \
\% % see below for details
_ _ see below for details

Comments

Database

Create Database

CREATE DATABASE [IF NOT EXISTS] {db_name | '[path/]db_name'} [db_option] ...
+ Database - CrossDB      

Database

Create Database

CREATE DATABASE [IF NOT EXISTS] {db_name | '[path/]db_name'} [db_option] ...
 
 db_option:
     ENGINE = {MMAP | MEMORY}
diff --git a/sql/dml/index.html b/sql/dml/index.html
index 2a78d85..9b3eadc 100755
--- a/sql/dml/index.html
+++ b/sql/dml/index.html
@@ -1,4 +1,4 @@
- Data manipulation - CrossDB      

Data manipulation

Insert

INSERT INTO tbl_name 
+ Data Manipulation - CrossDB      

Data Manipulation

Insert

INSERT INTO tbl_name 
     [(col_name,...)] 
     VALUES (val,...), ...
 
diff --git a/sql/functions/index.html b/sql/functions/index.html
index f30045b..e91ce69 100755
--- a/sql/functions/index.html
+++ b/sql/functions/index.html
@@ -1,4 +1,4 @@
- Functions - CrossDB      

Functions

Aggregate Functions

Function Return Type Description
COUNT(*) BIGINT The number of rows.
COUNT(col_name) BIGINT The number of rows in the specified column.
MIN(col_name) Same with column The minimum value of a specific column
MAX(col_name) Same with column The maximum value of a specific column.
SUM(col_name) DOUBLE or BIGINT The sum of a specific column in a table
AVG(col_name) DOUBLE The average value of the specified column.

Comments

Functions

Aggregate Functions

Function Return Type Description
COUNT(*) BIGINT The number of rows.
COUNT(col_name) BIGINT The number of rows in the specified column.
MIN(col_name) Same with column The minimum value of a specific column
MAX(col_name) Same with column The maximum value of a specific column.
SUM(col_name) DOUBLE or BIGINT The sum of a specific column in a table
AVG(col_name) DOUBLE The average value of the specified column.

Comments

Index

Create Index

CREATE [UNIQUE] INDEX idx_name 
+ Index - CrossDB      
\ No newline at end of file +
\ No newline at end of file diff --git a/sql/misc/index.html b/sql/misc/index.html index 0e42465..cd670f6 100755 --- a/sql/misc/index.html +++ b/sql/misc/index.html @@ -1,4 +1,4 @@ - Misc - CrossDB

Misc

Shell

Enter interactive shell

SHELL
+ Misc - CrossDB      

Name and Limit

Case Sensitive

Type Case-sensitive
Keyword False
Function False
DB Name False
Table Name False
Column Name False
Index Name False

Limit

Type Limit
DB Name 64
Table Name 64
Column Name 64
Index Name 64
Single SQL statement 1048576 (1M)
DB per process 1024
Table per DB 4095
Rows per Table 2,000,000,000 (2B)
Row size 524288 (512K)
Index per Table 16
Filter Fields 64

Comments

Name and Limit

Case Sensitive

Type Case-sensitive
Keyword False
Function False
DB Name False
Table Name False
Column Name False
Index Name False

Limit

Type Limit
DB Name 64
Table Name 64
Column Name 64
Index Name 64
Single SQL statement 1048576 (1M)
DB per process 1024
Table per DB 4095
Rows per Table 2,000,000,000 (2B)
Row size 524288 (512K)
Index per Table 16
Filter Fields 64

Comments

Operators

Comparison Operators

Operator Description Note
= Equal to
<>, != Not equal to TBD
> Greater than TBD
< Less than TBD
>= Greater than or equal to TBD
<= Less than or equal to TBD
IS NULL NULL value test TBD
IS NOT NULL NOT NULL value test TBD
BETWEEN ... AND ... Whether a value is within a range of values TBD
NOT BETWEEN ... AND ... Whether a value is not within a range of values TBD
IN Whether a value is not within a set of values TBD
NOT IN Negation of simple pattern matching TBD
LIKE Wildcard match TBD

LIKE is used together with wildcards to match strings. Its usage is described as follows:

  • '%' matches 0 or any number of characters, '_' matches any single ASCII character.
  • \_ is used to match the _ in the string.

Logical Operators

Operator Description Note
AND Logical AND
OR Logical OR TBD

Comments

Operators

Comparison Operators

Operator Description Note
= Equal to
<>, != Not equal to TBD
> Greater than TBD
< Less than TBD
>= Greater than or equal to TBD
<= Less than or equal to TBD
IS NULL NULL value test TBD
IS NOT NULL NOT NULL value test TBD
BETWEEN ... AND ... Whether a value is within a range of values TBD
NOT BETWEEN ... AND ... Whether a value is not within a range of values TBD
IN Whether a value is not within a set of values TBD
NOT IN Negation of simple pattern matching TBD
LIKE Wildcard match TBD

LIKE is used together with wildcards to match strings. Its usage is described as follows:

  • '%' matches 0 or any number of characters, '_' matches any single ASCII character.
  • \_ is used to match the _ in the string.

Logical Operators

Operator Description Note
AND Logical AND
OR Logical OR TBD

Comments

SQL Statements

Statement Descritpion Note
BEGIN Start a new transaction.
COMMIT Commits the open transaction if exists.
CLOSE DATABASE Close an opened database. Embedded Mode only
CREATE DATABASE Create a database.
CREATE INDEX Create an index on the specified table.
CREATE TABLE Create a new table.
DELETE Delete rows in a table.
DESCRIBE Describe the specified table.
DROP DATABASE Drop a database.
DROP INDEX Drop the specified index on the specified table.
DROP TABLE Drop the specified table.
DUMP DATABASE Dump database into file.
EXPLAIN Returns detailed information on how the query is executed.
HELP SQL statements help.
INSERT Insert data into a table.
OPEN DATABASE Open a database on disk. Embedded Mode only
ROLLBACK Roll back the open transaction if exists.
SELECT Retrieves data from a table.
SET AUTOCOMMIT Set session transaction auto-commit.
SHELL Enter interactive shell.
SHOW COLUMNS Show the list of columns within a given table.
SHOW CREATE TABLE Show the CREATE TABLE statement.
SHOW DATABASE Show the list of databases.
SHOW INDEXES Show the list of indexes associated with a given table.
SHOW TABLES Show the list of tables in database.
SOURCE Load and execute SQL file.
UPDATE Modifies rows in a table.
USE Use the database as the current default database.
CrossDB

SQL Statements

Statement Descritpion Note
BEGIN Start a new transaction.
COMMIT Commits the open transaction if exists.
CLOSE DATABASE Close an opened database. Embedded Mode only
CREATE DATABASE Create a database.
CREATE INDEX Create an index on the specified table.
CREATE TABLE Create a new table.
DELETE Delete rows in a table.
DESCRIBE Describe the specified table.
DROP DATABASE Drop a database.
DROP INDEX Drop the specified index on the specified table.
DROP TABLE Drop the specified table.
DUMP DATABASE Dump database into file.
EXPLAIN Returns detailed information on how the query is executed.
HELP SQL statements help.
INSERT Insert data into a table.
OPEN DATABASE Open a database on disk. Embedded Mode only
ROLLBACK Roll back the open transaction if exists.
SELECT Retrieves data from a table.
SET AUTOCOMMIT Set session transaction auto-commit.
SHELL Enter interactive shell.
SHOW COLUMNS Show the list of columns within a given table.
SHOW CREATE TABLE Show the CREATE TABLE statement.
SHOW DATABASE Show the list of databases.
SHOW INDEXES Show the list of indexes associated with a given table.
SHOW TABLES Show the list of tables in database.
SOURCE Load and execute SQL file.
UPDATE Modifies rows in a table.
USE Use the database as the current default database.
CrossDB

Table

Create Table

CREATE TABLE [IF NOT EXISTS] tbl_name (create_definition, ...) [table_option] ...
+ Table - CrossDB      

Table

Create Table

CREATE TABLE [IF NOT EXISTS] tbl_name (create_definition, ...) [table_option] ...
 
 CREATE OR REPLACE TABLE tbl_name (create_definition, ...)  [table_option] ...
 
diff --git a/sql/transaction/index.html b/sql/transaction/index.html
index 3af1cab..7d5011d 100755
--- a/sql/transaction/index.html
+++ b/sql/transaction/index.html
@@ -1,4 +1,4 @@
- Transaction and Lock - CrossDB      

Transaction and Lock

Begin Transaction

BEGIN
+ Transaction and Lock - CrossDB      

Transaction and Lock

Begin Transaction

BEGIN
 
 START TRANSACTION [READ WRITE | READ ONLY]
 

Note

Will commit any existing open transaction

Commit Transaction

COMMIT
@@ -38,4 +38,4 @@
   	}
     })
   })
-   
\ No newline at end of file +
\ No newline at end of file diff --git a/sysdb/information-schema/index.html b/sysdb/information-schema/index.html index a850197..6607c9a 100755 --- a/sysdb/information-schema/index.html +++ b/sysdb/information-schema/index.html @@ -1,4 +1,4 @@ - INFORMATION_SCHEMA - CrossDB

system

Databases

XDB> SELECT * FROM system.databases;
+ system - CrossDB