Switched over to hashtables for users and columns.

This commit is contained in:
Markus Makela
2014-10-15 15:23:14 +03:00
parent 104e79a591
commit effe8f3297
3 changed files with 211 additions and 98 deletions

View File

@ -1186,60 +1186,122 @@ bool is_drop_table_query(GWBUF* querybuf)
lex->sql_command == SQLCOM_DROP_TABLE;
}
char* skygw_get_where_clause(GWBUF* buf)
inline void add_str(char** buf, int* buflen, int* bufsize, char* str)
{
int isize = strlen(str) + 1;
if(*buf == NULL || isize + *buflen >= *bufsize)
{
char *tmp = (char*)calloc((*bufsize) * 2 + isize, sizeof(char));
if(tmp){
memcpy(tmp,*buf,*bufsize);
if(*buf){
free(*buf);
}
*buf = tmp;
*bufsize = (*bufsize) * 2 + isize;
}
}
if(*buflen > 0){
strcat(*buf," ");
}
strcat(*buf,str);
*buflen += isize;
}
/**
* Returns all the fields that the query affects.
* @param buf Buffer to parse
* @return Pointer to newly allocated string or NULL if nothing was found
*/
char* skygw_get_affected_fields(GWBUF* buf)
{
LEX* lex;
unsigned int buffsz = 0,bufflen = 0;
int buffsz = 0,bufflen = 0;
char* where = NULL;
Item* item;
Item* item;
Item::Type itype;
if(!query_is_parsed(buf)){
parse_query(buf);
}
if((lex = get_lex(buf)) == NULL){
return NULL;
}
lex->current_select = lex->all_selects_list;
lex->current_select = lex->all_selects_list;
while(lex->current_select)
{
List_iterator<Item> ilist(lex->current_select->item_list);
item = (Item*)ilist.next();
for (item; item != NULL; item=(Item*)ilist.next())
{
itype = item->type();
if(item->name && itype == Item::FIELD_ITEM){
add_str(&where,&buffsz,&bufflen,item->name);
}
}
if(lex->current_select->where){
for (item=lex->current_select->where; item != NULL; item=item->next)
{
Item::Type tp = item->type();
if(item->name && tp == Item::FIELD_ITEM){
int isize = strlen(item->name) + 1;
if(where == NULL || isize + bufflen >= buffsz)
{
char *tmp = (char*)calloc(buffsz*2 + isize,sizeof(char));
if(tmp){
memcpy(tmp,where,buffsz);
if(where){
free(where);
}
where = tmp;
buffsz = buffsz*2 + isize;
}else{
return NULL;
}
}
if(bufflen > 0){
strcat(where," ");
}
strcat(where,item->name);
bufflen += isize;
itype = item->type();
if(item->name && itype == Item::FIELD_ITEM){
add_str(&where,&buffsz,&bufflen,item->name);
}
}
}
if(lex->current_select->having){
for (item=lex->current_select->having; item != NULL; item=item->next)
{
itype = item->type();
if(item->name && itype == Item::FIELD_ITEM){
add_str(&where,&buffsz,&bufflen,item->name);
}
}
}
lex->current_select = lex->current_select->next_select_in_list();
}
return where;
}
bool skygw_query_has_clause(GWBUF* buf)
{
LEX* lex;
bool clause = false;
if(!query_is_parsed(buf)){
parse_query(buf);
}
if((lex = get_lex(buf)) == NULL){
return false;
}
lex->current_select = lex->all_selects_list;
while(lex->current_select)
{
if(lex->current_select->where || lex->current_select->having){
clause = true;
}
lex->current_select = lex->current_select->next_select_in_list();
}
return clause;
}
/*
* Replace user-provided literals with question marks. Return a copy of the
* querystr with replacements.