pgpool2.git / summary / log / commit / refs

commit    d549074d30355ec0e239cd0e4d3ce21a64448ad0
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Fri Apr 19 05:57:43 2013 +0000

    Fix bug with on memory query cache in handling UPDATE/DELETE with table alias.
    
    If UPDATE/DELETE is with table alias (UPDATE t1 AS foo...) pgpool
    thinks the table name is "t1 AS foo" and fails to invalidate query
    cache. This is caused by _outRangeVar() called from nodeToString()
    which generates a query string from RangeVar node in raw parse
    tree. The solution is removing "AS foo" part from the output of the
    string. But reported in bugtrack #56.


pool_memqcache.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/pool_memqcache.c b/pool_memqcache.c index ae4083484..a1bb45386 100644 --- a/pool_memqcache.c +++ b/pool_memqcache.c @@ -3,7 +3,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2012 PgPool Global Development Group + * Copyright (c) 2003-2013 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -114,6 +114,7 @@ static int pool_hash_insert(POOL_QUERY_HASH *key, POOL_CACHEID *cacheid, bool up static uint32 create_hash_key(POOL_QUERY_HASH *key); static volatile POOL_HASH_ELEMENT *get_new_hash_element(void); static void put_back_hash_element(volatile POOL_HASH_ELEMENT *element); +static char *get_relation_without_alias(RangeVar *relation); /* * Connect to Memcached @@ -884,12 +885,12 @@ int pool_extract_table_oids(Node *node, int **oidsp) else if (IsA(node, UpdateStmt)) { UpdateStmt *stmt = (UpdateStmt *)node; - table = nodeToString(stmt->relation); + table = get_relation_without_alias(stmt->relation); } else if (IsA(node, DeleteStmt)) { DeleteStmt *stmt = (DeleteStmt *)node; - table = nodeToString(stmt->relation); + table = get_relation_without_alias(stmt->relation); } #ifdef NOT_USED @@ -999,6 +1000,37 @@ int pool_extract_table_oids(Node *node, int **oidsp) return num_oids; } +/* + * Get relation name without alias. NodeToString() calls + * _outRangeVar(). Unfortunately _outRangeVar() returns table with + * alias ("t1 AS foo") as a table name if table alias is used. This + * function just trim down "AS..." part from the table name when table + * alias is used. + */ +static char *get_relation_without_alias(RangeVar *relation) +{ + char *table; + char *p; + + if (!IsA(relation, RangeVar)) + { + pool_error("get_relation_without_alias: not RangeVar(%d)", relation->type); + return ""; + } + table = nodeToString(relation); + if (relation->alias) + { + p = strchr(table, ' '); + if (!p) + { + pool_error("get_relation_without_alias: cannot locate space;%s", table); + return ""; + } + *p = '\0'; + } + return table; +} + #define POOL_OIDBUF_SIZE 1024 static int* oidbuf; static int oidbufp; [parent: eaff7d90a07e]