From 58e8c05c8a035fb1d73660adef0a83dace4671e2 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 31 Aug 2014 20:19:47 +0300 Subject: [PATCH] added detection of drop table targeting a temporary table --- query_classifier/query_classifier.cc | 6 +++ query_classifier/query_classifier.h | 3 +- .../routing/readwritesplit/readwritesplit.c | 50 ++++++++++++------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/query_classifier/query_classifier.cc b/query_classifier/query_classifier.cc index 14fa7ec44..92931e7ab 100644 --- a/query_classifier/query_classifier.cc +++ b/query_classifier/query_classifier.cc @@ -540,7 +540,13 @@ static skygw_query_type_t resolve_query_type( { type |= QUERY_TYPE_CREATE_TMP_TABLE; } + } + + if(lex->sql_command == SQLCOM_DROP_TABLE) + { + type |= QUERY_TYPE_DROP_TABLE; + } goto return_qtype; } diff --git a/query_classifier/query_classifier.h b/query_classifier/query_classifier.h index 595ba502b..86d5033d4 100644 --- a/query_classifier/query_classifier.h +++ b/query_classifier/query_classifier.h @@ -46,7 +46,8 @@ typedef enum { QUERY_TYPE_PREPARE_STMT = 0x0800, /*< Prepared stmt with id provided by server */ QUERY_TYPE_EXEC_STMT = 0x1000, /*< Execute prepared statement */ QUERY_TYPE_CREATE_TMP_TABLE = 0x2000, /*< Create temporary table */ - QUERY_TYPE_READ_TMP_TABLE = 0x4000 /*< Read temporary table */ + QUERY_TYPE_READ_TMP_TABLE = 0x4000, /*< Read temporary table */ + QUERY_TYPE_DROP_TABLE = 0x8000 } skygw_query_type_t; diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 05afbf587..72fe0c03a 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -1364,6 +1364,31 @@ static int routeQuery( * doesn't exist then create it first. */ + if(QUERY_IS_TYPE(qtype, QUERY_TYPE_CREATE_TMP_TABLE) || + QUERY_IS_TYPE(qtype, QUERY_TYPE_DROP_TABLE)){ + + tbl = skygw_get_table_names(querybuf,&tsize); + + if(tsize == 1 && tbl[0]) + { /**One valid table created*/ + + klen = strlen(dbname) + strlen(tbl[0]) + 2; + hkey = calloc(klen,sizeof(char)); + strcpy(hkey,dbname); + strcat(hkey,"."); + strcat(hkey,tbl[0]); + } + + + if(tsize > 0){ + for(i = 0;irses_prop_data.temp_tables, @@ -1431,15 +1445,15 @@ static int routeQuery( #endif } - if(tsize > 0){ - for(i = 0;irses_prop_data.temp_tables){ + hashtable_delete(rses_prop_tmp->rses_prop_data.temp_tables, (void *)hkey); } } - + + free(hkey); + if (master_dcb == NULL) { succp = get_dcb(&master_dcb, router_cli_ses, BE_MASTER);