📣
TiDB Cloud Premium 开放公测中。为企业级工作负载提供无限扩展、即时弹性伸缩和高级安全保障。此页面由 AI 自动翻译,英文原文请见此处。

RESULT_SCAN



通过查询 ID 检索先前查询的缓存结果。

另请参阅:system.query_cache

语法

RESULT_SCAN('<query_id>' | LAST_QUERY_ID())

示例

以下示例展示了如何启用查询结果缓存,并运行一个其结果将被缓存的查询:

# Enable the query result cache feature mysql> SET enable_query_result_cache = 1; Query OK, 0 rows affected (0.01 sec) # Cache all queries regardless of how fast they execute mysql> SET query_result_cache_min_execute_secs = 0; Query OK, 0 rows affected (0.01 sec) # Execute a query and cache its result mysql> SELECT * FROM t1 ORDER BY a; +------+ | a | +------+ | 1 | | 2 | | 3 | +------+ 3 rows in set (0.02 sec) Read 0 rows, 0.00 B in 0.006 sec., 0 rows/sec., 0.00 B/sec.

结果被缓存后,你可以使用 RESULT_SCAN 检索该结果,而无需重新运行查询:

# Retrieve the cached result of the previous query using its query ID mysql> SELECT * FROM RESULT_SCAN(LAST_QUERY_ID()) ORDER BY a; +------+ | a | +------+ | 1 | | 2 | | 3 | +------+ 3 rows in set (0.02 sec) Read 3 rows, 13.00 B in 0.006 sec., 464.06 rows/sec., 1.96 KiB/sec.

文档内容是否有帮助?