Skip to content

ShannonBase Introduction

Shannon Data AI Lab edited this page Nov 16, 2026 · 16 revisions

The practice cases of ShannonBase.

0: Compiling & Installation

Getting Started

  • How to build ShannonBase from source code

ShannonBase is a MySQL 8.4.11 LTS fork. The build is the normal MySQL CMake build plus a few bundled dependencies; nothing has to be installed from source by hand.

Supported build hosts: Ubuntu 22.04 / 24.04 / 26.04, x86_64 and aarch64. macOS and Windows are not covered by CI.

image

step 0: Requirement Installation

1: compiler and build tools (a C++20-capable compiler — GCC 11+ or Clang 14+, CMake 3.19+):

apt-get install -y build-essential cmake
apt-get install -y bison pkg-config
apt-get install -y clang-format-18    # only needed for the lint check

2: libraries the server links against:

apt-get install -y libssl-dev libncurses-dev libudev-dev
apt-get install -y libnuma-dev libaio-dev libzstd-dev libtirpc-dev

3: tools

apt-get install -y git wget tar bzip2 unzip curl ca-certificates

4: test-suite only (MTR/perl)

apt-get install -y libexpect-perl libjson-perl

Notes:

  • Boost is bundled. cmake/boost.cmake always uses extra/boost/boost_1_84_0 and ignores -DWITH_BOOST. Do not install or download Boost. (libboost-all-dev is installed in CI only because some tooling pulls it in; it is not what the build uses.)
  • Protobuf and curl are bundled (-DWITH_PROTOBUF=bundled -DWITH_CURL=bundled).
  • ONNX Runtime is fetched at configure time unless you provide your own. See step 3.
  • The Rust tokenizer is prebuilt. Static libraries for x86_64/aarch64 live in extra/tokenizer-ffi/lib/; no Rust toolchain is needed unless you rebuild that crate.

step 1: clone the source code, including submodules

The build needs two git submodules: extra/jerryscript (JavaScript stored routines) and extra/lightgbm (ML training).

git clone --recursive https://github.com/Shannon-Data/ShannonBase.git

The submodule URLs in .gitmodules are SSH (git@github.com:...). Without an SSH key, rewrite them to HTTPS before the recursive clone (or before git submodule update --init --recursive):

git config --global url."https://github.com/".insteadOf git@github.com:

step 2: make a directory where we build the source code

cd ShannonBase && mkdir cmake_build && cd cmake_build

step 3: (optional) ONNX Runtime and models

cmake/FindONNXRuntime.cmake resolves ONNX Runtime in this order:

  1. a native build under extra/onnxruntime/{include,lib/<arch>},
  2. a system installation,
  3. the official release package (default 1.24.4), downloaded during cmake — the configure step therefore needs network access.

Set USE_GPU=1 in the environment to resolve the GPU package instead of the CPU one. The runtime is required: it serves generation, embeddings, PII detection and the query-routing classifier.

Model files are not in the repository. Without them the server still starts and runs everything except the ML/GenAI surface that needs a model (rapid_schema_embedding is ON by default and does need one — turn it off, or install a model):

python3 -m pip install --break-system-packages huggingface_hub
hf download shannondata/multilingual-e5-small \
   --local-dir extra/llm-models/multilingual-e5-small

Models are looked up as <base>/llm-models/<model_id>/onnx/*.onnx, where <base> is --llm-dir=<path> when the server was started with it, otherwise <basedir>. The directory name is the model_id (case-sensitive) and must also contain tokenizer.json:

<base>/llm-models/multilingual-e5-small/
  onnx/model.onnx
  tokenizer.json

make install copies extra/llm-models into the install prefix, so downloading into extra/llm-models before installing is the simplest workflow. The router model extra/llm-models/shannon_rapid_classifier.onnx is committed and is found in the same directory.

step 4: run cmake

Release build (what CI ships; RelWithDebInfo is the project default when CMAKE_BUILD_TYPE is omitted):

cmake ../ \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/path-to-shannon-bin \
  -DMYSQL_DATADIR=/path-to-shannon-bin/data \
  -DSYSCONFDIR=/path-to-shannon-bin \
  -DMYSQL_UNIX_ADDR=/path-to-shannon-bin/tmp/mysql.sock \
  -DWITH_MYISAM_STORAGE_ENGINE=1 \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DMYSQL_TCP_PORT=3306 \
  -DENABLED_LOCAL_INFILE=1 \
  -DWITH_PROTOBUF=bundled \
  -DWITH_CURL=bundled \
  -DWITH_UNIT_TESTS=ON \
  -DWITH_HYPERGRAPH_OPTIMIZER=ON \
  -DCOMPILATION_COMMENT="MySQL Community Server, and Shannon Data AI Alpha V."

Debug build with assertions and O2 (what CI uses; still fast enough to run):

cmake ../ \
  -DCMAKE_BUILD_TYPE=Debug \
  -DWITH_DEBUG=ON \
  -DOPTIMIZE_DEBUG_BUILDS=OFF \
  -DENABLE_LTO=OFF \
  -DCMAKE_C_FLAGS_DEBUG="-O2 -g -fPIC" \
  -DCMAKE_CXX_FLAGS_DEBUG="-O2 -g -fPIC" \
  -DMYSQL_MAINTAINER_MODE=OFF \
  -DCMAKE_INSTALL_PREFIX=/path-to-shannon-bin \
  -DMYSQL_DATADIR=/path-to-shannon-bin/data \
  -DSYSCONFDIR=/path-to-shannon-bin \
  -DMYSQL_UNIX_ADDR=/path-to-shannon-bin/tmp/mysql.sock \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DMYSQL_TCP_PORT=3306 \
  -DENABLED_LOCAL_INFILE=1 \
  -DWITH_PROTOBUF=bundled \
  -DWITH_CURL=bundled \
  -DWITH_UNIT_TESTS=ON \
  -DWITH_HYPERGRAPH_OPTIMIZER=ON

Options worth knowing:

Option Meaning
-DWITH_ASAN=1 -DOPTIMIZE_SANITIZER_BUILDS=OFF -DWITH_ASAN_SCOPE=OFF AddressSanitizer build (CI's Release job)
-DWITH_ZSTD=system -DWITH_SSL=system link the distribution's zstd/OpenSSL (must match at runtime)
-DWITH_UNIT_TESTS=ON gunit targets; the Rapid ones are EXCLUDE_FROM_ALL, see step 6
-DWITH_HYPERGRAPH_OPTIMIZER=ON needed for the vectorized/hypergraph plans the tests exercise
-DSHANNONBASE_JERRY_HEAP_KB=2048 JerryScript heap per inference context (default 2048)
-DENABLE_LTO=ON/OFF link-time optimization; CI turns it off for Debug

step 5: compile and install

make -j5 && make install

Use -j5, not -j$(nproc): this tree wants roughly 2 GB RSS per compile job, so -j5 is the value that holds on an 11 GB machine. CI can use more only because its runners have more memory.

step 6: build and run the Rapid gunit tests (optional)

The Rapid unit tests are EXCLUDE_FROM_ALL + SKIP_INSTALL, so make all does not build them. Build the targets explicitly, then run them from the build tree:

RAPID_UNIT_TESTS=$(awk '/^SET\(RAPID_TESTS/{f=1;next} f&&/^\)/{f=0} f{sub(/#.*/,""); gsub(/[ \t\r]/,""); if($0!="") print $0"-t"}' ../unittest/gunit/CMakeLists.txt)
make -j5 $RAPID_UNIT_TESTS
for t in $RAPID_UNIT_TESTS; do ./runtime_output_directory/$t --gtest_color=no '--gtest_filter=-Microbenchmarks.*' || break; done

step 7: initialize the database

/path-to-shannon-bin/bin/mysqld \
  --defaults-file=/path-to-shannon-bin/my.cnf \
  --initialize-insecure --user=xxx

--initialize-insecure leaves root without a password; use --initialize if you want a temporary random password printed to the error log.

A minimal my.cnf (the container image ships a fuller one):

[mysqld]
user      = mysql
basedir   = /path-to-shannon-bin
datadir   = /path-to-shannon-bin/data
socket    = /path-to-shannon-bin/tmp/mysql.sock
port      = 3306
character-set-server = utf8mb4

# Rapid: reload the column store after a restart (engine default is OFF).
loose-rapid_reload_on_restart = ON
# Rapid memory budget, in bytes/suffixes. Default 2G, capped at 64G.
loose-rapid_memory_size_max   = 4G
# Only if no ONNX model is installed under <basedir>/llm-models:
# loose-rapid_schema_embedding = OFF

step 8: run ShannonBase

/path-to-shannon-bin/bin/mysqld \
  --defaults-file=/path-to-shannon-bin/my.cnf --user=xxx &

step 9: verify the install

mysql -uroot
mysql> SHOW ENGINES;                          -- "Rapid" must be listed
mysql> SHOW VARIABLES LIKE 'rapid%';
mysql> SHOW GLOBAL STATUS LIKE 'rapid%';
mysql> SELECT * FROM performance_schema.rpd_tables;

step 10: run the MTR test suite

MTR runs from the install tree, not from the build tree:

cd /path-to-shannon-bin/mysql-test
./mysql-test-run.pl \
  --suite=secondary_engine,ml,agent \
  --mysqld=--loose-rapid_schema_embedding=OFF \
  --nowarnings --force --retry=3 --parallel=5

--sanitize enables sanitizer report checking for ASAN builds; add --repeat=N when you suspect a flake rather than trusting one pass.

Docker

The image builds the same tree (Release/RelWithDebInfo, no test suite) and bakes the runtime library set:

docker build -f docker/Dockerfile -t shannondata/shannonbase:dev .
# optionally bake in the embedding model:
docker build -f docker/Dockerfile --build-arg WITH_MODELS=true -t shannondata/shannonbase:dev .

1: Using TPC-H

Data generation and the load scripts live in the repository under storage/rapid_engine/tools/tpch/ (queries/ holds q1..q22, load_tpch.sh loads tables into Rapid, run_tpch.sh runs the InnoDB-vs-Rapid comparison, compare_tpch.py compares two binaries and records plans/timings). The TPC-H schema and .tbl generation are external (https://github.com/Shannon-Data/heatwave-tpch/tree/main/TPCH).

Taking NATION as an instance:

create database tpch_1g;
alter database tpch_1g CHARACTER SET ascii COLLATE ascii_bin;
use tpch_1g;

CREATE TABLE NATION  ( N_NATIONKEY  INTEGER NOT NULL,
                       N_NAME       CHAR(25) NOT NULL,
                       N_REGIONKEY  INTEGER NOT NULL,
                       N_COMMENT    VARCHAR(152),
                       PRIMARY KEY (N_NATIONKEY));

Load the .tbl files, then move the tables into Rapid (a table must have a primary key to be loadable):

LOAD DATA INFILE '/path/nation.tbl' INTO TABLE NATION
  FIELDS TERMINATED BY '|' LINES TERMINATED BY '|\n';

ALTER TABLE NATION SECONDARY_ENGINE=RAPID;
ALTER TABLE NATION SECONDARY_LOAD;

load_tpch.sh does the last two statements for NATION, REGION, SUPPLIER, CUSTOMER, PART, PARTSUPP, ORDERS and LINEITEM.

Column-level encoding is chosen from the column comment, for example:

CREATE TABLE LINEITEM (
  L_ORDERKEY    BIGINT NOT NULL,
  L_LINENUMBER  INT    NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=BITPACK',
  L_PARTKEY     BIGINT NOT NULL,
  L_QUANTITY    DECIMAL(15,2),
  L_COMMENT     VARCHAR(44) COMMENT 'RAPID_COLUMN=ENCODING=VARLEN',
  PRIMARY KEY (L_ORDERKEY, L_LINENUMBER)
) SECONDARY_ENGINE=RAPID;

BITPACK applies to integer columns only (a domain wider than 32 bits silently stays canonical); SORTED/VARLEN are for string columns.

2: Using ML functions

The sys.ML_* routines are installed into sys during initialization and are HeatWave-compatible. Model objects live in ML_SCHEMA_<user>.MODEL_CATALOG (created on first training).

Two rules apply to the ML routines that create tables (for example ML_TRAIN):

  • it needs autocommit=1 and no active transaction (ML_SESSION_IN_TRANSACTION() must be 0), otherwise it raises ML routine requires autocommit and no active transaction;
  • model files must exist under <basedir>/llm-models (or --llm-dir), see step 3 above.

Train a model and keep the handle in a session variable:

SET @iris_model = 'iris_manual';
CALL sys.ML_TRAIN('ml_data.iris_train', 'class',
                  JSON_OBJECT('task', 'classification'), @iris_model);

Load it for the session (the batched-predict path caches the booster, so repeated predictions do not reload it):

CALL sys.ML_MODEL_LOAD(@iris_model, NULL);

Score it and predict:

CALL sys.ML_SCORE('ml_data.iris_test', 'class', @iris_model,
                  'balanced_accuracy', @score, NULL);
SELECT @score;

SELECT sys.ML_PREDICT_ROW(JSON_OBJECT('sepal_length', 6.4,
                                      'sepal_width', 3.2,
                                      'petal_length', 4.5,
                                      'petal_width', 1.5),
                          @iris_model, NULL);

CALL sys.ML_PREDICT_TABLE('ml_data.iris_test', @iris_model,
                          'ml_data.iris_predictions', NULL);

Explain, embed, generate:

CALL sys.ML_EXPLAIN('ml_data.iris_train', 'class', @iris_model, NULL);
SELECT sys.ML_EXPLAIN_ROW(JSON_OBJECT('sepal_length', 6.4), @iris_model, NULL);

SELECT sys.ML_EMBED_ROW('What is artificial intelligence?',
                        JSON_OBJECT('model_id', 'multilingual-e5-small'))
  INTO @vec;

CALL sys.ML_EMBED_TABLE('demo_db.docs.body', 'demo_db.vecs.v',
                        JSON_OBJECT('model_id', 'multilingual-e5-small',
                                    'batch_size', 500));

SELECT sys.ML_GENERATE('Explain HTAP in one sentence.', NULL);

RAG and natural language to SQL:

CALL sys.ML_RAG('How do I reset my password?', @answer,
                JSON_OBJECT('vector_store', JSON_ARRAY('demo_db.vecs'),
                            'n_citations', 3,
                            'distance_metric', 'COSINE'));

CALL sys.nl_sql('how many orders were placed last month', @out,
                JSON_OBJECT('execute', false));

3: Using automatic changes population

Load the data into rapid engine.

alter table NATION secondary_load;

and if you want to use rapid mandatorily.

set use_secondary_engine=forced;

or you can use it according to cost

set secondary_engine_cost_threshold = xxx;

then do query, it will use rapid to do query.

  select * from NATION;

Change propagation is controlled by rapid_change_propagation_mode, which can only be changed while nothing is loaded:

Mode Meaning
CAPTURE (default) the source DML notification hooks hand row images to Rapid before commit; the source transaction outcome commits or undoes them
COMMITTED_BINLOG a background binlog reader decodes committed source transactions (needs a usable binlog: binlog_order_commits=ON, etc.)
SHOW VARIABLES LIKE 'rapid_change_propagation_mode';

-- inspect state
SELECT * FROM performance_schema.rpd_tables;
SHOW GLOBAL STATUS LIKE 'rapid_pop%';
SHOW GLOBAL STATUS LIKE 'rapid_change_propagation_status';

If a table cannot keep up or a propagation failure cannot be undone, it is quarantined and Rapid refuses to serve it with table has failed DML propagation and must be reloaded; fix the problem and run SECONDARY_UNLOAD + SECONDARY_LOAD to rebuild the image.

With rapid_reload_on_restart=ON, Rapid checkpoints the loaded tables and recovers them at startup from the checkpoint plus committed binlog replay; with it OFF (the default), tables must be reloaded after every restart.

4: Using master-replica

Takes the following steps to build up ShannonBase master-replica. The syntax below is the MySQL 8.4 SOURCE/REPLICA terminology; the old CHANGE MASTER TO/START SLAVE forms are deprecated.

Rapid on the replica is not fed from the primary's Rapid copies: each instance loads and propagates its own tables. If you want committed-binlog propagation on the replica, enable the binlog there as well.

1. Prepare the source (master) instance

Enable binary logging on the source server:

Edit the MySQL configuration file (/etc/my.cnf or /etc/mysql/my.cnf) to add or enable the following options:

[mysqld]
log_bin = mysql-bin                        # Enable binary logging
server_id = 1                              # Unique server ID for the source
binlog_format = ROW                        # Use row-based replication
binlog_order_commits = ON                  # Required by COMMITTED_BINLOG
gtid_mode = ON                             # Recommended
enforce_gtid_consistency = ON
  1. Restart the server to apply the changes.

  2. Create a replication user on the source:

CREATE USER 'replica_user'@'%' IDENTIFIED BY 'replica_password';
GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%';
FLUSH PRIVILEGES;
  1. Get the source log file and position (not needed with GTID):
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
UNLOCK TABLES;

2. Configure the replica instance

  1. Prepare the replica server: On the replica server, configure the MySQL configuration file with a unique server ID:
[mysqld]
server_id = 2                              # Unique server ID for the replica
relay_log = relay-bin                      # Optional
log_bin = mysql-bin                        # Needed for rapid COMMITTED_BINLOG
gtid_mode = ON                             # Required with SOURCE_AUTO_POSITION
enforce_gtid_consistency = ON
  1. Restart Replica Service.

  2. Set up replication on the replica:

With GTID (recommended):

CHANGE REPLICATION SOURCE TO
  SOURCE_HOST = 'source_ip_address',
  SOURCE_USER = 'replica_user',
  SOURCE_PASSWORD = 'replica_password',
  SOURCE_AUTO_POSITION = 1;

START REPLICA;

Without GTID, use the file/position from SHOW MASTER STATUS:

CHANGE REPLICATION SOURCE TO
  SOURCE_HOST = 'source_ip_address',
  SOURCE_USER = 'replica_user',
  SOURCE_PASSWORD = 'replica_password',
  SOURCE_LOG_FILE = 'mysql-bin.xxxxx',
  SOURCE_LOG_POS = xxxxx;

START REPLICA;
  1. Monitor and maintain replication.
SHOW REPLICA STATUS\G

If there are errors, the replication relationship will be broken:

*************************** 1. row ***************************
             Replica_IO_State: Waiting for source to send event
                  Source_Host: source_ip_address
                  Source_User: replica_user
                  Source_Port: 3306
                Connect_Retry: 60
              Source_Log_File: mysql-bin.000234
          Read_Source_Log_Pos: 3866
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 511
        Relay_Source_Log_File: mysql-bin.000234
           Replica_IO_Running: Yes
          Replica_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 1007
                   Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction 'ANONYMOUS' at source log mysql-bin.000234, end_log_pos 3266. See the error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
                 Skip_Counter: 0
          Exec_Source_Log_Pos: 3081
              Relay_Log_Space: 1500
              Until_Condition: None

5: Using the GenAI agent

sys.shannon_chat is a stored procedure (JavaScript, installed from scripts/sys_schema/agent/) that turns a natural-language request into SQL or tool calls, executes them safely and returns the answer as a result set.

SET @chat_options = JSON_OBJECT(
  'conversation_id', UUID(),
  'model_options', JSON_OBJECT(
     'provider', 'deepseek',
     'model_id', 'deepseek-v4-pro',
     'api_key',  'sk-...'
  ),
  'history_length', 5
);

CALL sys.shannon_chat('show me the tables that are loaded into Rapid');

Behaviour worth knowing:

  • keep the same conversation_id for multi-turn context; omit it to continue the last conversation on the connection, or set it to "new";
  • the agent has 34 registry-defined tools (SQL, transaction, schema, RAG, the ml_* family, memory) and 4 execution routes (catalog match, rule planner, RAG, LLM loop);
  • writes/DDL go through a review/approval state machine and a transaction lease with automatic rollback;
  • it needs the LLM provider and (for RAG) the embedding models from step 3.

The full reference — chat_options, tool list, review flow, audit tables and troubleshooting — is in scripts/sys_schema/agent/HOW_TO_USE.md.