Kai Data Storage Model

By default, tables created using SingleStore Kai store data in the BSON format. The _id field of the document is added to the _id column, and the rest of the fields in the document are added to the _more column of the table in SingleStore.

Tables created using SingleStore Kai have the following columns:

Column Name

Data Type

Description

_id

BSON NOT NULL

The _id field required in all MongoDB® documents.

_more

BSON NOT NULL

Contains all the fields in the document, except the _id field.

$_id

PERSISTED LONGBLOB

Used to implement SingleStore unique indexes on MongoDB® collections, similar to BSON unique indexes. This column contains the _id field normalized using the BSON_NORMALIZE or BSON_NORMALIZE_NO_ARRAY function, which transform the BSON data into a byte stream that preserves the BSON comparison when compared byte-by-byte.

View the BSON Data

To view the BSON data, SingleStore recommends the following:

  • Use the Kai Shell or other supported MongoDB® tools, such as MongoDB® Compass.

  • Cast the columns to JSON using the following SQL command:

    SELECT _id :> JSON , _more :> JSON FROM <table_name>;

Example

For example, run the following command on a Kai-enabled workspace to create a collection named exampleCollection:

db.exampleCollection.insertMany( [
{ _id: 1, Code: "xv1f", Qty: 45 },
{ _id: 2, Code: "nm3w", Qty: 30 },
{ _id: 3, Code: "qoma", Qty: 20 },
{ _id: 4, Code: "hr3k", Qty: 15 } ] )

This exampleCollection is stored in SingleStore as:

db.runCommand({sql:"SHOW CREATE TABLE dbTest.exampleCollection"}).cursor.firstBatch[0]["Create Table"]
CREATE TABLE `exampleCollection` (
  `_id` bson NOT NULL,
  `_more` bson NOT NULL COMMENT 'KAI_MORE' ,
  `$_id` as BSON_NORMALIZE_NO_ARRAY(`_id`) PERSISTED longblob COMMENT 'KAI_AUTO' ,
  SHARD KEY `__SHARDKEY` (`$_id`),
  UNIQUE KEY `__PRIMARY` (`$_id`) USING HASH,
  SORT KEY `__UNORDERED` ()
) COMMENT 'KAI_CID:2QZxxxx1xxxxxxxx' AUTOSTATS_CARDINALITY_MODE=INCREMENTAL AUTOSTATS_HISTOGRAM_MODE=CREATE AUTOSTATS_SAMPLING=ON SQL_MODE='STRICT_ALL_TABLES'

To view the documents in exampleCollection using the Kai Shell, run the following command:

db.exampleCollection.find()
[ { _id: 4, Code: 'hr3k', Qty: 15 },
  { _id: 3, Code: 'qoma', Qty: 20 },
  { _id: 1, Code: 'xv1f', Qty: 45 },
  { _id: 2, Code: 'nm3w', Qty: 30 } ]

To view the documents in exampleCollection using SQL commands, run the following command in the SQL command-line:

SELECT _id :> JSON AS _id, _more :> JSON AS _more FROM exampleCollection;
+-----+--------------------------+
| _id | _more                    |
+-----+--------------------------+
| 4   | {"Code":"hr3k","Qty":15} |
| 3   | {"Code":"qoma","Qty":20} |
| 1   | {"Code":"xv1f","Qty":45} |
| 2   | {"Code":"nm3w","Qty":30} |
+-----+--------------------------+

Last modified: August 2, 2024

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK