REST API Server Index SCAN API#
The REST API Server supports index scan operations in addition to primary key read operations. An index scan allows retrieving multiple rows matching filter conditions, optionally using an ordered index to limit the scan range and control the ordering of results.
Example table definition#
Assume we have the following table.
CREATE TABLE `tbl` (
`pk` int NOT NULL,
`val_1` int DEFAULT NULL,
`val_2` int DEFAULT NULL,
`val_3` double DEFAULT NULL,
`content` varchar(1024) DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `idx_val` (`val_1`,`val_2`)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SCAN API request#
POST /{api-version}/DB/TABLE/scan
Body:
{
"limit": 10,
"readColumns": [
{
"column": "pk"
},
{
"column": "val_1"
},
{
"column": "val_2"
},
{
"column": "content"
}
],
"filters": {
"op": "AND",
"args": [
{
"op": "AND",
"args": [
{
"op": "ISNOTNULL",
"column": "content"
},
{
"op": "CMP",
"column": "pk",
"cond": "GT",
"value": 2
}
]
},
{
"op": "OR",
"args": [
{
"op": "CMP",
"column": "val_1",
"cond": "LE",
"value": 30
},
{
"op": "CMP",
"column": "val_2",
"cond": "GT",
"value": 500
}
]
}
]
},
"index": {
"name": "idx_val",
"key_columns": [
"val_1",
"val_2"
],
"ranges": [
{
"lower": {
"values": [
10,
100
],
"inclusive": true
},
"upper": {
"values": [
70,
700
],
"inclusive": false
}
}
],
"order": "asc"
}
}
SCAN API explanation#
The request body consists of 4 parts:
limit (required)#
Used to specify the maximum number of rows to return.
readColumn (optional)#
Used to specify the columns to be returned.
filters (optional)#
Used to define filter conditions.
For example, the filter shown above is equivalent to:
Filters are defined using a logical-expression format, which allows
applying AND / OR / NAND / NOR operations to two or more
sub-filters. Sub-filters are specified in the args field:
Each entry in the args array represents a sub-filter. A sub-filter can
either be a comparison filter or another nested logical filter.
A comparison filter is defined as follows:
index (optional)#
Used to define an index scan.
The index object consists of the following fields:
name#
Specifies the name of the index to be used.
column#
Must match the index columns of the specified index. This ensures that the user selects the correct index and provides range values properly. It acts as an additional validation step.
ranges#
Specifies the lower and upper bounds for the index scan.
Typically, values for all index columns should be provided. However, partial (prefix) values are supported. For example:
-
Providing
val_1 = 10without specifyingval_2is valid, sinceval_1is the prefix column of the index. -
Providing
val_2withoutval_1is invalid.
order#
Indicates whether the returned rows should be ordered by the index, and
specifies the order (ASC / DESC).