diff -u -r pgpool2-3d2093e.org/src/include/utils/pool_relcache.h pgpool2-3d2093e.new/src/include/utils/pool_relcache.h --- pgpool2-3d2093e.org/src/include/utils/pool_relcache.h 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/include/utils/pool_relcache.h 2015-12-18 12:18:16.929736755 +0900 @@ -69,7 +69,7 @@ func_ptr register_func, func_ptr unregister_func, bool issessionlocal); extern void pool_discard_relcache(POOL_RELCACHE *relcache); -extern void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, char *table); +extern void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, char *table, bool forceInvalidate); extern char *remove_quotes_and_schema_from_relname(char *table); extern void *int_register_func(POOL_SELECT_RESULT *res); extern void *int_unregister_func(void *data); diff -u -r pgpool2-3d2093e.org/src/include/utils/pool_select_walker.h pgpool2-3d2093e.new/src/include/utils/pool_select_walker.h --- pgpool2-3d2093e.org/src/include/utils/pool_select_walker.h 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/include/utils/pool_select_walker.h 2015-12-18 12:18:16.978859961 +0900 @@ -58,7 +58,7 @@ extern bool pool_has_pgpool_regclass(void); extern bool pool_has_to_regclass(void); extern bool raw_expression_tree_walker(Node *node, bool (*walker) (), void *context); -extern int pool_table_name_to_oid(char *table_name); +extern int pool_table_name_to_oid(char *table_name, bool forceInvalidate); 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); diff -u -r pgpool2-3d2093e.org/src/protocol/pool_process_query.c pgpool2-3d2093e.new/src/protocol/pool_process_query.c --- pgpool2-3d2093e.org/src/protocol/pool_process_query.c 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/protocol/pool_process_query.c 2015-12-18 12:18:17.054984649 +0900 @@ -2876,11 +2876,11 @@ * Search relcache. */ #ifdef USE_TABLE_LOCK - result = pool_search_relcache(relcache, backend, table)==0?0:1; + result = pool_search_relcache(relcache, backend, table, false)==0?0:1; #elif USE_SEQUENCE_LOCK - result = pool_search_relcache(relcache, backend, table)==0?0:2; + result = pool_search_relcache(relcache, backend, table, false)==0?0:2; #else - result = pool_search_relcache(relcache, backend, table)==0?0:3; + result = pool_search_relcache(relcache, backend, table, false)==0?0:3; #endif return result; } @@ -2973,7 +2973,7 @@ /* * Search relcache. */ - adsrc = pool_search_relcache(relcache, backend, table); + adsrc = pool_search_relcache(relcache, backend, table, false); if (adsrc == NULL) { /* could not get adsrc */ @@ -3184,7 +3184,7 @@ errdetail("error while creating relcache"))); } - result = pool_search_relcache(relcache, backend, "insert_lock")==0?0:1; + result = pool_search_relcache(relcache, backend, "insert_lock", false)==0?0:1; return result; } diff -u -r pgpool2-3d2093e.org/src/query_cache/pool_memqcache.c pgpool2-3d2093e.new/src/query_cache/pool_memqcache.c --- pgpool2-3d2093e.org/src/query_cache/pool_memqcache.c 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/query_cache/pool_memqcache.c 2015-12-18 12:18:17.135749986 +0900 @@ -1003,10 +1003,10 @@ } table = nodeToString(makeRangeVarFromNameList(lfirst(cell))); - oid = pool_table_name_to_oid(table); + oid = pool_table_name_to_oid(table, false); if (oid > 0) { - oids[num_oids++] = pool_table_name_to_oid(table); + oids[num_oids++] = pool_table_name_to_oid(table, true); ereport(DEBUG1, (errmsg("memcache: extracting table oids: table: \"%s\" oid:%d", table, oids[num_oids-1]))); } @@ -1029,10 +1029,10 @@ } table = nodeToString(lfirst(cell)); - oid = pool_table_name_to_oid(table); + oid = pool_table_name_to_oid(table, false); if (oid > 0) { - oids[num_oids++] = pool_table_name_to_oid(table); + oids[num_oids++] = pool_table_name_to_oid(table, false); ereport(DEBUG1, (errmsg("memcache: extracting table oids: table: \"%s\" oid:%d", table, oids[num_oids-1]))); } @@ -1046,10 +1046,10 @@ return 0; } - oid = pool_table_name_to_oid(table); + oid = pool_table_name_to_oid(table, false); if (oid > 0) { - oids[num_oids++] = pool_table_name_to_oid(table); + oids[num_oids++] = pool_table_name_to_oid(table, false); ereport(DEBUG1, (errmsg("memcache: extracting table oids: table: \"%s\" oid:%d", table, oid))); } @@ -1251,7 +1251,7 @@ * Search relcache. */ oid = (int)(intptr_t)pool_search_relcache(relcache, backend, - MASTER_CONNECTION(backend)->sp->database); + MASTER_CONNECTION(backend)->sp->database, false); return oid; } diff -u -r pgpool2-3d2093e.org/src/rewrite/pool_lobj.c pgpool2-3d2093e.new/src/rewrite/pool_lobj.c --- pgpool2-3d2093e.org/src/rewrite/pool_lobj.c 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/rewrite/pool_lobj.c 2015-12-18 12:18:17.197734791 +0900 @@ -108,7 +108,7 @@ /* * Get lo_creat oid */ - lo_creat_oid = (int)(intptr_t)pool_search_relcache(relcache_lo_creat, backend, "pg_proc"); + lo_creat_oid = (int)(intptr_t)pool_search_relcache(relcache_lo_creat, backend, "pg_proc", false); memmove(&orig_fcall_oid, packet, sizeof(int32)); orig_fcall_oid = ntohl(orig_fcall_oid); @@ -141,7 +141,7 @@ /* * Get lo_create oid */ - lo_create_oid = (int)(intptr_t)pool_search_relcache(relcache_lo_create, backend, "pg_proc"); + lo_create_oid = (int)(intptr_t)pool_search_relcache(relcache_lo_create, backend, "pg_proc", false); ereport(DEBUG1, (errmsg("rewriting LO CREATE"), diff -u -r pgpool2-3d2093e.org/src/rewrite/pool_timestamp.c pgpool2-3d2093e.new/src/rewrite/pool_timestamp.c --- pgpool2-3d2093e.org/src/rewrite/pool_timestamp.c 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/rewrite/pool_timestamp.c 2015-12-18 12:18:17.256735062 +0900 @@ -190,7 +190,7 @@ } } - return (TSRel *) pool_search_relcache(ts_relcache, ctx->backend, table_name); + return (TSRel *) pool_search_relcache(ts_relcache, ctx->backend, table_name, false); } static Node * diff -u -r pgpool2-3d2093e.org/src/utils/pool_relcache.c pgpool2-3d2093e.new/src/utils/pool_relcache.c --- pgpool2-3d2093e.org/src/utils/pool_relcache.c 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/utils/pool_relcache.c 2015-12-18 12:18:17.314735134 +0900 @@ -90,8 +90,10 @@ /* * Search relcache. If found, return user data. Otherwise return 0. * If not found in cache, do the query and store the result into cache and return it. + * Specify forceInvalidate true if it is necessary to invalidate this relcache + * after used (like when DROP TABLE, oid must be updated). */ -void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, char *table) +void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, char *table, bool forceInvalidate) { char *dbname; int i; @@ -144,7 +146,16 @@ /* Found */ if (relcache->cache[i].refcnt < INT_MAX) relcache->cache[i].refcnt++; - + + /* invalidate this relcache */ + if (forceInvalidate){ + relcache->cache[i].refcnt = 0; + memset((char *) &relcache->cache[i].relname, 0, sizeof(relcache->cache[i].relname)); + memset((char *) &relcache->cache[i].dbname, 0, sizeof(relcache->cache[i].dbname)); + ereport(DEBUG1, + (errmsg("searching relcache"), + errdetail("relcache of database:%s table:%s was invalidated.", dbname, table))); + } return relcache->cache[i].data; } } @@ -207,7 +218,7 @@ /* Register cache */ result = (*relcache->register_func)(res); - if (!relcache->no_cache_if_zero || result) + if (!forceInvalidate && (!relcache->no_cache_if_zero || result)) { strlcpy(relcache->cache[index].dbname, dbname, MAX_ITEM_LENGTH); strlcpy(relcache->cache[index].relname, table, MAX_ITEM_LENGTH); diff -u -r pgpool2-3d2093e.org/src/utils/pool_select_walker.c pgpool2-3d2093e.new/src/utils/pool_select_walker.c --- pgpool2-3d2093e.org/src/utils/pool_select_walker.c 2015-12-02 20:54:37.000000000 +0900 +++ pgpool2-3d2093e.new/src/utils/pool_select_walker.c 2015-12-18 12:18:17.365734889 +0900 @@ -460,7 +460,7 @@ } } - hasreliscatalog = pool_search_relcache(hasreliscatalog_cache, backend, "pg_namespace")==0?0:1; + hasreliscatalog = pool_search_relcache(hasreliscatalog_cache, backend, "pg_namespace", false)==0?0:1; if (hasreliscatalog) { @@ -499,7 +499,7 @@ /* * Search relcache. */ - result = pool_search_relcache(relcache, backend, table_name)==0?false:true; + result = pool_search_relcache(relcache, backend, table_name, false)==0?false:true; return result; } @@ -568,7 +568,7 @@ } } - hasrelistemp = pool_search_relcache(hasrelistemp_cache, backend, "pg_class")==0?0:1; + hasrelistemp = pool_search_relcache(hasrelistemp_cache, backend, "pg_class", false)==0?0:1; if (hasrelistemp) query = ISTEMPQUERY84; else @@ -593,7 +593,7 @@ /* * Search relcache. */ - result = pool_search_relcache(is_temp_table_relcache, backend, table_name)==0?false:true; + result = pool_search_relcache(is_temp_table_relcache, backend, table_name, false)==0?false:true; return result; } @@ -662,7 +662,7 @@ } } - hasrelpersistence = pool_search_relcache(hasrelpersistence_cache, backend, "pg_class")==0?0:1; + hasrelpersistence = pool_search_relcache(hasrelpersistence_cache, backend, "pg_class", false)==0?0:1; if (hasrelpersistence) { bool result; @@ -702,7 +702,7 @@ /* * Search relcache. */ - result = pool_search_relcache(relcache, backend, table_name)==0?false:true; + result = pool_search_relcache(relcache, backend, table_name, false)==0?false:true; return result; } else @@ -772,7 +772,7 @@ /* * Search relcache. */ - result = pool_search_relcache(relcache, backend, table_name)==0?false:true; + result = pool_search_relcache(relcache, backend, table_name, false)==0?false:true; return result; } @@ -807,7 +807,7 @@ } } - result = pool_search_relcache(relcache, backend, user)==0?0:1; + result = pool_search_relcache(relcache, backend, user, false)==0?0:1; return result; } @@ -842,7 +842,7 @@ } } - result = pool_search_relcache(relcache, backend, user)==0?0:1; + result = pool_search_relcache(relcache, backend, user, false)==0?0:1; return result; } @@ -974,7 +974,7 @@ errdetail("relcache created"))); } - result = (pool_search_relcache(relcache, backend, fname)==0) ? 0 : 1; + result = (pool_search_relcache(relcache, backend, fname, false)==0) ? 0 : 1; ereport(DEBUG1, (errmsg("checking if the function is IMMUTABLE"), @@ -984,8 +984,10 @@ /* * Convert table_name(possibly including schema name) to oid + * Specify forceInvalidate true if it is necessary to invalidate + * relcache of specified table. */ -int pool_table_name_to_oid(char *table_name) +int pool_table_name_to_oid(char *table_name, bool forceInvalidate) { /* * Query to convert table name to oid @@ -1047,7 +1049,7 @@ /* * Search relcache. */ - oid = (int)(intptr_t)pool_search_relcache(relcache, backend, table_name); + oid = (int)(intptr_t)pool_search_relcache(relcache, backend, table_name, forceInvalidate); return oid; } @@ -1088,7 +1090,7 @@ int oid; table = make_table_name_from_rangevar(rgv); - oid = pool_table_name_to_oid(table); + oid = pool_table_name_to_oid(table, false); if (oid) {