缓存 (增量 Lake on Azure Databricks) CACHE (Delta Lake on Azure Databricks)

CACHE SELECT column_name[, column_name, ...] FROM [db_name.]table_name [ WHERE boolean_expression ]

SELECT增量缓存中缓存指定简单查询访问的数据。Cache the data accessed by the specified simple SELECT query in the Delta cache. 可以通过提供列名列表并通过提供谓词来选择行的子集,来选择要缓存的列的子集。You can choose a subset of columns to be cached by providing a list of column names and choose a subset of rows by providing a predicate. 这样,后续查询便可以避免尽可能多地扫描原始文件。This enables subsequent queries to avoid scanning the original files as much as possible. 此构造仅适用于 Parquet 表。This construct is applicable only to Parquet tables. 还支持视图,但扩展的查询仅限于简单查询,如上所述。Views are also supported, but the expanded queries are restricted to the simple queries, as described above.

有关 RDD 缓存和 Databricks IO 缓存之间的差异,请参阅 增量和 Apache Spark 缓存See Delta and Apache Spark caching for the differences between the RDD cache and the Databricks IO cache.

示例Examples

CACHE SELECT * FROM boxes
CACHE SELECT width, length FROM boxes WHERE height=3