ApsaraDB for SelectDB uses a two-tier caching architecture — in-memory cache on compute nodes and a persistent data cache on cloud disks — to minimize reads from object storage and accelerate queries. This topic covers how the data cache works, which cache policy to use, and how to prefetch data into a new cluster.
How the data cache works
ApsaraDB for SelectDB provides two cache types that operate at different layers:
| Cache type | Storage | Cached content | Eviction |
|---|---|---|---|
| In-memory cache | Compute node memory | Metadata (table structures, partition info, statistics) and columnar data blocks (Parquet, ORC) | LRU; cold data evicted first when memory is full |
| Data cache | Cloud disk (SSD) | Columnar data blocks, column indexes, and dictionary encodings loaded from object storage | LRU or TTL policy; acts as a secondary cache between memory and object storage |
The data cache reduces object storage reads by persisting warm data locally on disk. This topic focuses on the data cache.
How data enters the cache
Data reaches the data cache through three paths:
Import: Newly imported data is asynchronously written to the cache to accelerate initial access.
Query: If requested data is not in the cache, the system reads it from remote storage into memory and writes it to the local disk cache for subsequent queries.
New cluster: A newly created cluster starts with an empty cache. Use cache prefetch to proactively load data from remote storage before queries run.
Cache policies
ApsaraDB for SelectDB supports two cache policies: Least Recently Used (LRU) and Time-to-Live (TTL). Both are set at the table level.
Choose a cache policy
| Policy | When to use | How it works |
|---|---|---|
| LRU (default) | Most workloads | Maintains a queue. Accessed blocks move to the head; the tail is evicted when the cache is full. Newly written data is also placed at the head to prevent premature eviction. |
| TTL | Total data volume far exceeds cache capacity AND some tables are accessed much more frequently than others | Keeps high-priority data in the cache for a fixed period after import. Eviction time = Import time + TTL period. TTL data has the highest eviction priority — the system evicts LRU data to make room for new TTL data. All TTL data is treated equally during eviction, regardless of remaining time-to-live. |
Example: A database has 10 tables totaling 1 TB, but cache capacity is 200 GB. One table is accessed far more frequently than the others. Set TTL on that table to prevent it from being evicted.
The TTL policy is an experimental feature and is not recommended for production environments.
TTL edge case: If the cache fills entirely with TTL data, no new data is written to the cache — including newly imported data with a TTL policy and cold data read from remote storage.
Cache policy parameters
| Parameter | Scope | Default | Description |
|---|---|---|---|
file_cache_ttl_seconds | Table | None | Time in seconds for newly imported data to remain in the cache. Set in PROPERTIES during CREATE TABLE or via ALTER TABLE. |
Cache prefetch
Clusters in an ApsaraDB for SelectDB instance share stored data but do not share cache data. A newly created cluster starts with an empty cache, which slows down initial queries.
Cache prefetch loads data from remote storage into the local cache before queries run. It supports three modes:
| Mode | SQL command | Description |
|---|---|---|
| Cross-cluster | WARM UP CLUSTER cluster_b WITH CLUSTER cluster_a | Prefetches data based on hotspot information periodically collected from cluster A and stored in an internal table |
| By table | WARM UP CLUSTER cluster_b WITH TABLE <table> | Prefetches all data for the specified table |
| By partition | WARM UP CLUSTER cluster_b WITH TABLE <table> PARTITION <partition> | Prefetches data for a specific partition |
Only one cache prefetch job can run in a cluster at a time.
For a step-by-step walkthrough, see Use the cache prefetch feature.
Manage cache space
Set the cache size
Specify the cache size when creating an instance and cluster. See Create an instance.
View the cache size
Log in to the SelectDB console. On the Instance List page, click the target instance ID to go to the Instance Details page, then click Cluster Management to view the Cache Size.
Example: Use the cache prefetch feature
This example shows all three cache prefetch modes by prefetching data from cluster_name0 to cluster_name1.
Step 1: Identify hot data
Query which clusters have cached hotspot information.
SHOW CACHE HOTSPOT '/';The result shows that cluster_name0 has cached hotspot data.
+------------------------+-----------------------+----------------------------------------+ | cluster_name | total_file_cache_size | top_table_name | +------------------------+-----------------------+----------------------------------------+ | cluster_name0 | 751620511367 | regression_test.selectdb_cache_hotspot | +------------------------+-----------------------+----------------------------------------+View the hotspot information for cluster_name0.
SHOW CACHE HOTSPOT '/cluster_name0';The
top_partition_namecolumn shows that p20230529 is a hot partition in thecustomertable.+-----------------------------------------------------------+---------------------+--------------------+ | table_name | last_access_time | top_partition_name | +-----------------------------------------------------------+---------------------+--------------------+ | regression_test.selectdb_cache_hotspot | 2023-05-29 12:38:02 | p20230529 | | regression_test_cloud_load_copy_into_tpch_sf1_p1.customer | 2023-06-06 10:56:12 | p20230529 | | regression_test_cloud_load_copy_into_tpch_sf1_p1.nation | 2023-06-06 10:56:12 | nation | +-----------------------------------------------------------+---------------------+--------------------+View the hot partitions for the
customertable.NoteIf a table has only one partition, the partition name is the same as the table name.
SHOW CACHE HOTSPOT '/cluster_name0/regression_test_cloud_load_copy_into_tpch_sf1_p1.customer';+----------------+---------------------+ | partition_id | partition_name | +----------------+---------------------+ | 422831494463 | p20230529 | +----------------+---------------------+
Step 2: Create a cache prefetch job
The following examples show all three prefetch modes.
Only one cache prefetch job can run in a cluster at a time.
Cross-cluster prefetch — prefetch cluster_name0's cache into cluster_name1:
WARM UP CLUSTER cluster_name1 WITH CLUSTER cluster_name0Table prefetch — prefetch the
customertable into cluster_name1:WARM UP CLUSTER cluster_name1 WITH TABLE customerPartition prefetch — prefetch the p20230529 partition of the
customertable into cluster_name1:WARM UP CLUSTER cluster_name1 WITH TABLE customer PARTITION p20230529
Step 3: Monitor and manage the prefetch job
Get the job ID by running the prefetch command. The output includes a
JobId.WARM UP CLUSTER cluster_name1 WITH TABLE customer;+-------+ | JobId | +-------+ | 13418 | +-------+ 1 row in set (0.01 sec)Check the job progress using the
JobId. TrackFinishBatchagainstAllBatch— each batch is approximately 10 GB.SHOW WARM UP JOB WHERE ID = 13418;+-------+-------------------+---------+-------+-------------------------+-------------+----------+------------+ | JobId | ClusterName | Status | Type | CreateTime | FinishBatch | AllBatch | FinishTime | +-------+-------------------+---------+-------+-------------------------+-------------+----------+------------+ | 13418 | cluster_name1 | RUNNING | TABLE | 2023-05-30 20:19:34.059 | 0 | 1 | NULL | +-------+-------------------+---------+-------+-------------------------+-------------+----------+------------+ 1 row in set (0.02 sec)(Optional) Cancel the job by its
JobId.CANCEL WARM UP JOB where id = 13418;Verify the cancellation — the status should be
CANCELLED.SHOW WARM UP JOB WHERE ID = 13418;+-------+-------------------+-----------+-------+-------------------------+-------------+----------+-------------------------+ | JobId | ClusterName | Status | Type | CreateTime | FinishBatch | AllBatch | FinishTime | +-------+-------------------+-----------+-------+-------------------------+-------------+----------+-------------------------+ | 13418 | cluster_name1 | CANCELLED | TABLE | 2023-05-30 20:19:34.059 | 0 | 1 | 2023-05-30 20:27:14.186 | +-------+-------------------+-----------+-------+-------------------------+-------------+----------+-------------------------+ 1 row in set (0.00 sec)
Example: Use the TTL policy
Set a TTL policy
Set file_cache_ttl_seconds in the PROPERTIES clause when creating a table. The value specifies how long, in seconds, newly imported data remains in the cache.
The following example retains all newly imported data in the customer table for 300 seconds.
CREATE TABLE IF NOT EXISTS customer (
C_CUSTKEY INTEGER NOT NULL,
C_NAME VARCHAR(25) NOT NULL,
C_ADDRESS VARCHAR(40) NOT NULL,
C_NATIONKEY INTEGER NOT NULL,
C_PHONE CHAR(15) NOT NULL,
C_ACCTBAL DECIMAL(15,2) NOT NULL,
C_MKTSEGMENT CHAR(10) NOT NULL,
C_COMMENT VARCHAR(117) NOT NULL
)
DUPLICATE KEY(C_CUSTKEY, C_NAME)
DISTRIBUTED BY HASH(C_CUSTKEY) BUCKETS 32
PROPERTIES(
"file_cache_ttl_seconds"="300"
);Modify a TTL policy
Use ALTER TABLE to update the TTL for an existing table.
ALTER TABLE customer SET ("file_cache_ttl_seconds"="3000");Changes to file_cache_ttl_seconds may take a short time to propagate.
FAQ
Q: If my cache fills with TTL data, will newly imported data still be cached?
No. If the cache is entirely occupied by TTL data, no new data is written to the cache — including data imported with a TTL policy and cold data read from remote storage.
Q: Does changing `file_cache_ttl_seconds` take effect immediately?
No. There may be a short delay before the change propagates.
Q: Can multiple prefetch jobs run at the same time?
No. Only one cache prefetch job can run in a cluster at a time.