简体   繁体   English

Postgres +从缓存中选择查询

[英]Postgres + Select query from Cache

I was wondering if Postgres had a feature like SQL_CACHE in mySQL. 我想知道Postgres是否在mySQL中具有SQL_CACHE之类的功能。 For example in mySQL I can do a query like "SELECT SQL_CACHE Product_ID, Product_Name, Product_Sku FROM Products" I want to know if I can do something similar in Postgres. 例如,在mySQL中,我可以执行类似“ SELECT SQL_CACHE Pr​​oduct_ID,Product_Name,Product_Sku FROM Products”的查询,我想知道是否可以在Postgres中执行类似的操作。

PostgreSQL automatically caches recently accessed data in memory, depending on your shared_buffers configuration parameter. PostgreSQL根据您的shared_buffers配置参数自动将最近访问的数据缓存在内存中。 There's really no need for an SQL_CACHE feature, since Postgres already does a great job of managing the tuple cache. 确实不需要SQL_CACHE功能,因为Postgres已经在管理元组缓存方面做得很好。

只需简单地转到/etc/postgresql/YOUREVERSION/main/posgresql.conf(* nix)(C:\\ Program Files \\ PostgreSQL \\ YOUREVERSION \\ data \\ postgresql.conf(win))找到shared_buffers,取消注释并指定需要的缓存大小。

In MySQL , SQL_CACHE doesn not select from cache, depending on query_cache_type , this happens: MySQL ,根据query_cache_type不会从缓存中选择SQL_CACHE ,发生这种情况:

  • 1 or ON : Cache all cacheable query results except for those that begin with SELECT SQL_NO_CACHE . 1或ON :缓存所有以SELECT SQL_NO_CACHE开头的可缓存查询结果。
  • 2 or DEMAND : Cache results only for cacheable queries that begin with SELECT SQL_CACHE . 2或DEMAND :仅对以SELECT SQL_CACHE开头的可缓存查询的缓存结果。

In essence, using SQL_NO_CACHE with any setting other the 1 or SQL_CACHE with any other setting the 2 is meaningless . 本质上,将SQL_NO_CACHE与其他设置1或将SQL_CACHE与其他设置2没有意义的

If this is still what you need in PostgreSQL: no idea, but I had to make this very clear. 如果这仍然是您在PostgreSQL中需要的:不知道,但是我必须非常清楚地说明这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM