英文:
Does QuestDB cache query results?
问题
Query results cached in QuestDB?
i.q.c.p.PGConnectionContext query cache used [fd=34248] appearing in logs mean?
当我第一次运行
SELECT colX FROM (SUBQUERY)
需要1秒。在下一个查询中,只需要50毫秒。
英文:
Are query results cached in QuestDB ?
What does i.q.c.p.PGConnectionContext query cache used [fd=34248] appearing in logs mean ?
When I'm running
SELECT colX FROM (SUBQUERY)
for the first time it takes 1 second. On the next query it takes only 50 milliseconds.
答案1
得分: 1
QuestDB不缓存查询结果。运行查询可能会从存储中获取数据到操作系统页缓存,将数据预热。第二次运行时,整个数据集可能在RAM中,无需等待IO操作。
为了加速查询解析、分析和查询计划构建,QuestDB会缓存执行计划。
*i.q.c.p.PGConnectionContext查询缓存已使用[fd=34248]*表示在pgwire缓存中找到了兼容的计划,QuestDB可以跳过上述的查询执行阶段。
您可以使用以下server.conf设置来调整查询缓存大小:
HTTP
启用查询缓存
#http.query.cache.enabled=true
设置查询缓存的块数。缓存容量为块数*行数
#http.query.cache.block.count=4
设置查询缓存的行数。缓存容量为块数*行数
#http.query.cache.row.count=16
PG Wire协议
启用选择查询缓存
#pg.select.cache.enabled=true
设置选择查询缓存的块数。缓存容量为块数*行数
#pg.select.cache.block.count=16
设置选择查询缓存的行数。缓存容量为块数*行数
#pg.select.cache.row.count=16
启用插入查询缓存
#pg.insert.cache.enabled=true
设置插入查询缓存的块数。缓存容量为块数*行数
#pg.insert.cache.block.count=8
设置插入查询缓存的行数。缓存容量为块数*行数
#pg.insert.cache.row.count=8
英文:
QuestDB doesn't cache query results .
Running a query is likely to fetch data from storage to OS page cache, warm up the data. On the second run it's possible that whole data set is in RAM and there's no need to wait on IO operations.
To speed up query parsing, analysis and query plan building, QuestDB does cache execution plans.
i.q.c.p.PGConnectionContext query cache used [fd=34248] means that compatible plan was found in pgwire cache and QuestDB can skip aforementioned query execution stages.
You can adjust query cache sizes with the following server.conf settings :
HTTP
# enables the query cache
#http.query.cache.enabled=true
# sets the number of blocks for the query cache. Cache capacity is number_of_blocks * number_of_rows
#http.query.cache.block.count=4
# sets the number of rows for the query cache. Cache capacity is number_of_blocks * number_of_rows
#http.query.cache.row.count=16
PG wire protocol
# enables select query cache
#pg.select.cache.enabled=true
# sets the number of blocks for the select query cache. Cache capacity is number_of_blocks * number_of_rows
#pg.select.cache.block.count=16
# sets the number of rows for the select query cache. Cache capacity is number_of_blocks * number_of_rows
#pg.select.cache.row.count=16
# enables insert query cache
#pg.insert.cache.enabled=true
# sets the number of blocks for the insert query cache. Cache capacity is number_of_blocks * number_of_rows
#pg.insert.cache.block.count=8
# sets the number of rows for the insert query cache. Cache capacity is number_of_blocks * number_of_rows
#pg.insert.cache.row.count=8
答案2
得分: -2
是的,QuestDB使用查询缓存来提高查询性能。在日志中出现的 i.q.c.p.PGConnectionContext 查询缓存消息表示查询结果是从缓存中检索而不是再次执行的。
查询缓存通过将 SELECT 查询的结果存储在内存中来工作,因此如果再次执行相同的查询,结果可以从缓存中检索,而不必再次执行查询。这可以显著提高频繁执行的查询性能。
在您的情况下,似乎第一次运行查询时,QuestDB不得不执行查询并检索结果,这花了1秒钟。然而,在第二次查询中,QuestDB能够从查询缓存中检索结果,仅花费了50毫秒。
请注意,查询缓存仅对返回相同输入参数的 SELECT 查询有效。如果底层数据发生更改,或者查询的输入参数发生更改,那么查询缓存将不会被使用,查询将需要再次执行。
英文:
Yes, QuestDB uses a query cache to improve query performance. The i.q.c.p.PGConnectionContext query cache message appearing in the logs indicates that a query result was retrieved from the cache rather than being executed again.
The query cache works by storing the results of SELECT queries in memory, so that if the same query is executed again, the result can be retrieved from the cache rather than executing the query again. This can significantly improve query performance for frequently executed queries.
In your case, it appears that the first time you ran the query, QuestDB had to execute the query and retrieve the result, which took 1 second. However, on the second query, QuestDB was able to retrieve the result from the query cache, which only took 50 milliseconds.
Note that the query cache is only effective for SELECT queries that return the same result for the same input parameters. If the underlying data changes, or if the input parameters to the query change, then the query cache will not be used and the query will need to be executed again.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论