pgpool2.git / summary / log / commit / refs
commit 51dba1bb66b2447849d8df40cbbced7e2514a795
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Tue May 22 03:37:35 2012 +0000
Change the meaning of white_memqcache_table_list. Before only tables
specified in the list are allowed to cache. Now if a table is in the
list, even the table is VIEW or unlogged table, it's allowed to
cache. This is more intuitive and easier to use, I believe. This also
means it is possible to use both white list and black list at the same
time.
Disallow to cache if SELECT includes unlogged tables(as long as it's
not specified in the white list of course).
pool_memqcache.c | 77 +++++++++++++++++++++++++++++++++++++---------------
pool_select_walker.c | 6 ++--
pool_select_walker.h | 2 ++
3 files changed, 59 insertions(+), 26 deletions(-)
diff --git a/pool_memqcache.c b/pool_memqcache.c
index 21359a6b1..b8a158b9b 100644
--- a/pool_memqcache.c
+++ b/pool_memqcache.c
@@ -665,10 +665,32 @@ bool pool_is_allow_to_cache(Node *node, char *query)
{
SelectStmt *stmt;
int i = 0;
- int num_oids;
+ int num_oids = -1;
+ SelectContext ctx;
stmt = (SelectStmt *)node;
+ /*
+ * Check black table list first.
+ */
+ if (pool_config->num_black_memqcache_table_list > 0)
+ {
+ /* Extract oids in from clause of SELECT, and check if SELECT to them could be cached. */
+ num_oids = pool_extract_table_oids_from_select_stmt(node, &ctx);
+ if (num_oids > 0)
+ {
+ for (i = 0; i < num_oids; i++)
+ {
+ pool_debug("pool_is_allow_to_cache: check table_names[%d] = %s", i, ctx.table_names[i]);
+ if (pool_is_table_to_cache(ctx.table_names[i]) == false)
+ {
+ pool_debug("pool_is_allow_to_cache: false");
+ return false;
+ }
+ }
+ }
+ }
+
/* SELECT INTO or SELECT FOR SHARE or UPDATE cannot be cached */
if (pool_has_insertinto_or_locking_clause(node))
return false;
@@ -688,33 +710,44 @@ bool pool_is_allow_to_cache(Node *node, char *query)
return false;
/*
- * If SELECT uses views, it's not allowed to cache.
+ * If the table is in the while list, allow to cache even if it is
+ * VIEW or unlogged table.
*/
- if (pool_has_view(node))
- return false;
-
- /* Cache any tables in the case that both of list are empty */
- if (pool_config->num_white_memqcache_table_list == 0 &&
- pool_config->num_black_memqcache_table_list == 0)
- return true;
-
- /* Extract oids in from clause of SELECT, and check if SELECT to them could be cached. */
- SelectContext ctx;
- num_oids = pool_extract_table_oids_from_select_stmt(node, &ctx);
- if (num_oids == 0)
- return false;
-
- for (i = 0; i < num_oids; i++)
+ if (pool_config->num_white_memqcache_table_list > 0)
+ {
+ if (num_oids < 0)
+ num_oids = pool_extract_table_oids_from_select_stmt(node, &ctx);
+ }
+ if (num_oids > 0)
{
- pool_debug("pool_is_allow_to_cache: check table_names[%d] = %s", i, ctx.table_names[i]);
- if (pool_is_table_to_cache(ctx.table_names[i]) == false)
+ for (i = 0; i < num_oids; i++)
{
- pool_debug("pool_is_allow_to_cache: false");
- return false;
+ char *table = ctx.table_names[i];
+ pool_debug("pool_is_allow_to_cache: check table_names[%d] = %s", i, table);
+ if (is_view(table) || is_unlogged_table(table))
+ {
+ if (pool_is_table_to_cache(table) == false)
+ {
+ pool_debug("pool_is_allow_to_cache: false");
+ return false;
+ }
+ }
}
}
+ else
+ {
+ /*
+ * If SELECT uses views, it's not allowed to cache.
+ */
+ if (pool_has_view(node))
+ return false;
- pool_debug("pool_is_allow_to_cache: true");
+ /*
+ * If SELECT uses unlogged tables, it's not allowed to cache.
+ */
+ if (pool_has_unlogged_table(node))
+ return false;
+ }
return true;
}
diff --git a/pool_select_walker.c b/pool_select_walker.c
index f89594d84..d3651cb97 100644
--- a/pool_select_walker.c
+++ b/pool_select_walker.c
@@ -38,8 +38,6 @@ static bool temp_table_walker(Node *node, void *context);
static bool unlogged_table_walker(Node *node, void *context);
static bool view_walker(Node *node, void *context);
static bool is_temp_table(char *table_name);
-static bool is_unlogged_table(char *table_name);
-static bool is_view(char *table_name);
static bool insertinto_or_locking_clause_walker(Node *node, void *context);
static bool is_immutable_function(char *fname);
static bool select_table_walker(Node *node, void *context);
@@ -565,7 +563,7 @@ static bool is_temp_table(char *table_name)
* Judge the table used in a query represented by node is a unlogged
* table or not.
*/
-static bool is_unlogged_table(char *table_name)
+bool is_unlogged_table(char *table_name)
{
/*
* Query to know if pg_class has relpersistence column or not.
@@ -654,7 +652,7 @@ static bool is_unlogged_table(char *table_name)
/*
* Judge the table used in a query is a view or not.
*/
-static bool is_view(char *table_name)
+bool is_view(char *table_name)
{
/*
* Query to know if the target table is a view.
diff --git a/pool_select_walker.h b/pool_select_walker.h
index 028321dea..5bf8afc28 100644
--- a/pool_select_walker.h
+++ b/pool_select_walker.h
@@ -60,5 +60,7 @@ extern int pool_table_name_to_oid(char *table_name);
extern int pool_extract_table_oids_from_select_stmt(Node *node, SelectContext *ctx);
extern RangeVar *makeRangeVarFromNameList(List *names);
extern int pattern_compare(char *str, const int type, const char *param_name);
+extern bool is_unlogged_table(char *table_name);
+extern bool is_view(char *table_name);
#endif /* POOL_SELECT_WALKER_H */
[parent: e7ed7c286353]