You need to enable JavaScript to run this app.
ByteHouse Cloud Data Warehouse Version

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
Appearance
Hive external table metadata cache
Copy page
Download PDF
Hive external table metadata cache

To accelerate access to Hive external tables, ByteHouse has developed a Hive metadata cache capability that stores metadata information in server memory. This reduces the overhead of accessing the Hive Metastore and significantly improves query performance when the same table or partition is frequently accessed by business operations. This article introduces the Hive metadata cache feature and its usage.

Feature overview

Hive metadata cache process

ByteHouse supports caching Hive external table metadata in the dedicated server's memory at four levels: table structure, partition name, partition information, and remote file.

Hive metadata cache levels

The Hive metadata cache includes four levels: Schema Cache (table structure cache), Partition Name Cache (partition name cache), Partition Cache (partition information cache), and Remote File Cache (remote file cache). Details are as follows:

Cache level

Cache key

Cache value

Cache content

Schema Cache
(Table structure cache)

Hive database, table name, such as db.table_name.

StorageInMemoryMetadata

Stores cached table structure, column name, column type, partition key.

Partition Name Cache
(Partition name cache)

Hive table name.

Set of partition name strings (List<String>)

Stores all partition names of the current table, such as dt=2025-05-20/region=us.

Partition Cache
(Partition information cache)

Hive partition name. For example, db.table/dt=2025-05-20/region=us.

DataLakeCache::Partition

Stores the physical path information and other metadata attributes of the partitions contained in the table.

Remote File Cache
(Remote file cache)

The partition stores the remote path, which contains the Hive table name and partition name.

List<DataLakeCache::RemoteFile>

Store all file names, file sizes, modification times, and other information for this partition to avoid retrieving directory content from remote storage (such as HDFS or S3) during each scan.

Cache strategy

The metadata cache strategy uses a combination of "Least Recently Used (LRU) cache" and "Time to Live (TTL)". The specific logic is as follows:

  • An independent TTL is set for the cache key of each metadata record. Within the TTL validity period, the system does not repeatedly send data requests to the remote source but reads data directly from the local cache to improve access efficiency.

  • When the cache key's TTL expires, the system will automatically delete the cache content corresponding to that key, then send a request to the Hive Metastore to obtain the latest data, and update the TTL for that key to ensure the timeliness of the cached data.

  • The TTL for different cache levels is as follows:

    Cache level

    TTL time

    Schema Cache (Table structure cache)

    900 seconds

    Partition Name Cache (Partition name cache)

    900 seconds

    Partition Cache (Partition information cache)

    21600 seconds

    Remote File Cache (Remote file cache)

    21600 seconds

Prerequisites

The Hive metadata cache feature depends on a dedicated server. You need to purchase a dedicated server before use. Enabling the Hive metadata cache will occupy the memory of the dedicated server. For an introduction and activation instructions for the dedicated server, see Private server.

Using metadata cache

ByteHouse supports enabling the Hive metadata cache by configuring user SQL-level parameters. After enabling, you can monitor the usage of the Hive metadata cache through the tenant bh_system.query_log system table. Note that the relevant parameters must be added for each query; otherwise, ByteHouse will not enable the Hive metadata cache.

Enable metadata cache

You can control the enabled state of the Hive metadata cache and the expiration time for each cache level at the query level by adding user SQL-level settings parameters each time you execute an SQL statement. Currently, enabling this feature during table creation is not supported.
ByteHouse supports two methods to enable this feature: configure via SQL parameter group, or directly add settings parameters in the query statement.

Enable via SQL parameter group

When executing SQL statements in the ByteHouse cloud data warehouse console, you can add Hive metadata-related parameters as an SQL parameter group. Select this parameter group before executing the SQL statement, and ByteHouse will add this parameter group by default when executing the SQL statement. For configuration instructions, please refer to use SQL Param Group. For currently supported settings parameters, see Parameter description. Examples are as follows:

<sql_parameters>
       <enable_hive_schema_cache>false</enable_hive_schema_cache>
       <hive_schema_cache_ttl>1000</hive_schema_cache_ttl>
</sql_parameters>

Enable via settings parameter

You can add settings parameters each time you execute an SQL statement to enable the Hive metadata cache. For currently supported settings parameters, see Parameter description. Examples are as follows:

-- Enable during query
SELECT * FROM ext.las 
SETTINGS 
    enable_hive_schema_cache = 'true', -- Enable Hive table structure cache
    hive_schema_cache_ttl = '1000'; -- Set Hive table structure cache expiration time to 1000 seconds

tip

For instructions on creating and using Hive external tables, please refer to Hive external table.

Parameter description

Parameter items

Parameter description

enable_hive_schema_cache

Whether to use table structure cache. Supports setting to false or true. You can also set to 0 (corresponds to false) or 1 (corresponds to true), and the system will convert accordingly.
The default value is true. Data type is Bool.

hive_schema_cache_ttl

Set the lifetime of the table structure cache, in seconds.
The default value is 900. Data type is UInt64.

enable_hive_partition_name_cache

Whether to use partition name cache. Supports setting to false or true. You can also set to 0 (corresponds to false) or 1 (corresponds to true), and the system will convert accordingly.
The default value is true. Data type is Bool.

hive_partition_name_cache_ttl

Set the lifetime of the partition name cache, in seconds.
The default value is 900. Data type is UInt64.

enable_hive_partition_cache

Whether to use Hive partition metadata cache. Supports setting to false or true. You can also set to 0 (corresponds to false) or 1 (corresponds to true), and the system will convert accordingly.
The default value is true. Data type is Bool.

hive_partition_cache_ttl

Set the lifetime of the Hive partition cache, in seconds.
The default value is 21600. Data type is UInt64.

enable_hive_remote_file_cache

Whether to use remote file cache. Supports setting to false or true. You can also set to 0 (corresponds to false) or 1 (corresponds to true), and the system will convert accordingly.
The default value is true. Data type is Bool.

hive_remote_file_cache_ttl

Set the lifetime of the remote file cache, in seconds.
The default value is 21600. Data type is UInt64.

Monitor cache metrics

You can view cache metrics by querying the tenant's bh_system.query_log system table, including whether the SQL hit the Hive metadata cache and the number of expired cache discoveries.

warning

bh_system.query_log system table is a non-public function and requires allowlist privilege to use. Before using, please submit a ticket or contact the ByteHouse team to obtain allowlist privilege. For details on function usage, please refer to View detailed log (query_log).

You can query and obtain the numerical value of the corresponding cache metric in the bh_system.query_log system table according to the specific Key in the event source ProfileEvents. The correspondence between cache metrics and event source keys is described as follows:

Cache metrics

Key in event source (query_log.ProfileEvents)

Cache hits

The metric is presented in the form DataLake{Schema|PartitionName|Partition|RemoteFiles}CacheHits, with the following meanings:

  • DataLakeSchemaCacheHits: Number of cache hits for table structure cache
  • DataLakePartitionNameCacheHits: Number of cache hits for partition name cache
  • DataLakePartitionCacheHits: Number of cache hits for partition cache
  • DataLakeRemoteFilesCacheHits: Number of remote file cache hits

Number of cache misses

The metric is presented in the form DataLake{Schema|PartitionName|Partition|RemoteFiles}CacheMisses, with the description as follows:

  • DataLakeSchemaCacheMisses: Number of table structure cache misses
  • DataLakePartitionNameCacheMisses: Number of partition name cache misses
  • DataLakePartitionCacheMisses: Number of partition cache misses
  • DataLakeRemoteFilesCacheMisses: Number of remote file cache misses

Number of expired cache discoveries (retrieved again from remote)

The metric is presented in the form DataLake{Schema|PartitionName|Partition|RemoteFiles}CacheExpired, with the description as follows:

  • DataLakeSchemaCacheExpired: Lifetime of table structure cache
  • DataLakePartitionNameCacheExpired: Lifetime of partition name cache
  • DataLakePartitionCacheExpired: Lifetime of partition cache
  • DataLakeRemoteFilesCacheExpired: Lifetime of remote file cache

Examples of query methods are as follows:

SELECT
    k,
    v
FROM bh_system.query_log
ARRAY JOIN
    mapKeys(ProfileEvents) AS k,
    mapValues(ProfileEvents) AS v
WHERE (query_id = '4e9xxxxx-xxxx-xxxx-xxxx-0bxxxxxxxxxx') AND (k LIKE '%DataLake%')

Parameter description

Parameter items

Parameter description

k

Setting k indicates querying the metric names of currently enabled cache events.

v

Setting v indicates querying the statistical value of the metric, that is, the number of occurrences of each type of cache event.

ARRAY JOIN...AS...

Match the extracted keys and values one by one to form multiple records. Here, it is used to analyze the key-value pair data in the ProfileEvents field and expand them into multiple records.

  • mapKeys(ProfileEvents) AS k: Analyze all cache metric names stored in the ProfileEvents field.
  • mapValues(ProfileEvents) AS v: Analyze the statistical values corresponding to each metric in the ProfileEvents field.

WHERE...AND...

Use WHERE to filter the data, retaining only records that meet the condition.

  • AND: Indicates that both conditions must be satisfied.
  • query_id: Specifies the target SQL statement ID to query.
  • k LIKE '%DataLake%': Filter condition, indicating that only metrics related to Hive metadata cache are retained.

Examples of output results are as follows:
Image

Last updated: 2026.03.31 16:24:12