pgpool分析五,query cache

来源:互联网 发布:想做淘宝直播 编辑:程序博客网 时间:2024/05/21 14:34

pgpool的query cache没有存放在内存中,是存放在systemdb中的,通过libpq连到systemdb中,

在child的进程中,存在QueryCacheInfo结构体,用于暂存将来存入systemdb的cache

/* data structure to store RowDescription and DataRow cache */
typedef struct
{
char *md5_query;    /* query in md5 hushed format*/
char *query;     /* query string */
char *cache;     /* cached data */
int   cache_size;    /* cached data size */
int   cache_offset;    /* points the end of cache */
char *db_name;     /* database name */
char *create_time;    /* cache create timestamp in ISO format */
} QueryCacheInfo;

在systemdb之中存在一个query_cache表,create_time 是创建cache的时间戳,pgpool会定时的根据时间戳把过期的cache删掉

SELECT hash, query, value, dbname, create_time FROM query_cache

查询的时候是根据SQL的MD5哈希值和数据库名字确定的

SELECT value FROM query_cache WHERE hash = ‘md5_query' AND dbname = 'database'

创建cache其实就是向表中增加一条记录

INSERT INTO query_cache VALUES ( $1, $2, $3, $4, $5 )

总的来说,pgpool的query cache比较简单,可以改成memcached,这样只用内存,不用和数据库通信这种缓存,以提高速度

原创粉丝点击