diff -Nur mysql-4.0.24.orig/configure.in mysql-4.0.24/configure.in --- mysql-4.0.24.orig/configure.in 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/configure.in 2005-07-01 03:28:18.000000000 +0900 @@ -776,6 +776,9 @@ ;; esac +# For senna +AC_CHECK_LIB(senna, sen_log) +AC_CHECK_LIB(mecab, mecab_new3, [],[echo "No libmecab found (You need a patched version, if using mecab without mecab_new3)"; exit 1]) #-------------------------------------------------------------------- # Check for TCP wrapper support #-------------------------------------------------------------------- diff -Nur mysql-4.0.24.orig/include/myisam.h mysql-4.0.24/include/myisam.h --- mysql-4.0.24.orig/include/myisam.h 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/include/myisam.h 2005-07-01 03:28:18.000000000 +0900 @@ -29,6 +29,10 @@ #include #endif +//#ifdef SENNA +#include +//#endif + /* defines used by myisam-funktions */ /* The following defines can be increased if necessary */ @@ -149,6 +153,11 @@ struct st_mi_s_param *s_temp); void (*store_key)(struct st_mi_keydef *keyinfo, uchar *key_pos, struct st_mi_s_param *s_temp); + +//#ifdef SENNA + sen_index *senna; +//#endif + } MI_KEYDEF; diff -Nur mysql-4.0.24.orig/libmysqld/item_create.cc mysql-4.0.24/libmysqld/item_create.cc --- mysql-4.0.24.orig/libmysqld/item_create.cc 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/libmysqld/item_create.cc 2005-07-01 03:31:39.000000000 +0900 @@ -455,3 +455,9 @@ { return new Item_func_quote(a); } + + +Item *create_func_sen_skipmode_set(Item* a) +{ + return new Item_func_sen_skipmode_set(a); +} diff -Nur mysql-4.0.24.orig/libmysqld/item_func.cc mysql-4.0.24/libmysqld/item_func.cc --- mysql-4.0.24.orig/libmysqld/item_func.cc 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/libmysqld/item_func.cc 2005-07-01 03:38:08.000000000 +0900 @@ -2472,3 +2472,25 @@ return 1; return 0; } + + + +#include +extern "C" { +extern pthread_key_t THR_SEN_skipmode; +} +longlong Item_func_sen_skipmode_set::val_int() +{ + longlong arg1= (longlong) args[0]->val_int(); + long *skipmode; +#ifdef THREAD + skipmode = (long *) pthread_getspecific(THR_SEN_skipmode); + if (!skipmode) { + skipmode = (long *) calloc(1, sizeof(long)); + pthread_setspecific(THR_SEN_skipmode, skipmode); + } + *skipmode = arg1; +#endif + return (longlong) arg1; +} + diff -Nur mysql-4.0.24.orig/libmysqld/sql_db.cc mysql-4.0.24/libmysqld/sql_db.cc --- mysql-4.0.24.orig/libmysqld/sql_db.cc 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/libmysqld/sql_db.cc 2005-07-01 03:28:18.000000000 +0900 @@ -252,6 +252,36 @@ (file->name[1] == '.' && !file->name[2]))) continue; + /* senna files is skip */ + /* ".SEN",".SEN.i",".SEN.i.c",".SEN.l" */ + { + int len = strlen(file->name); + if (len > 4 && file->name[len-1] == 'N') { + if (file->name[len-4] == '.' && + file->name[len-3] == 'S' && + file->name[len-2] == 'E') + continue; + } + if (len > 6 && file->name[len-2] == '.' && + (file->name[len-1] == 'l' || file->name[len-1] == 'i')) { + if (file->name[len-6] == '.' && + file->name[len-5] == 'S' && + file->name[len-4] == 'E' && + file->name[len-3] == 'N') + continue; + } + if (len > 8 && file->name[len-1] == 'c') { + if (file->name[len-8] == '.' && + file->name[len-7] == 'S' && + file->name[len-6] == 'E' && + file->name[len-5] == 'N' && + file->name[len-4] == '.' && + file->name[len-3] == 'i' && + file->name[len-2] == '.') + continue; + } + } + /* Check if file is a raid directory */ if ((isdigit(file->name[0]) || (file->name[0] >= 'a' && file->name[0] <= 'f')) && diff -Nur mysql-4.0.24.orig/libmysqld/sql_select.cc mysql-4.0.24/libmysqld/sql_select.cc --- mysql-4.0.24.orig/libmysqld/sql_select.cc 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/libmysqld/sql_select.cc 2005-07-01 03:31:49.000000000 +0900 @@ -21,6 +21,15 @@ #pragma implementation // gcc: Class implementation #endif +#include +extern "C" { +//#include +//extern pthread_key(long, THR_SEN_select_limit); +//extern pthread_key(long, THR_SEN_offset_limit); +extern pthread_key_t THR_SEN_select_limit; +extern pthread_key_t THR_SEN_offset_limit; +} + #include "mysql_priv.h" #include "sql_select.h" @@ -247,6 +256,25 @@ thd->used_tables=0; // Updated by setup_fields /* select_limit is used to decide if we are likely to scan the whole table */ select_limit= thd->select_limit; + +#ifdef THREAD +{ + long *tmp = (long *) pthread_getspecific(THR_SEN_offset_limit); + if (!tmp) { + tmp = (long *) calloc(1, sizeof(long)); + pthread_setspecific(THR_SEN_offset_limit, tmp); + } + *tmp = thd->offset_limit; + + tmp = (long *) pthread_getspecific(THR_SEN_select_limit); + if (!tmp) { + tmp = (long *) calloc(1, sizeof(long)); + pthread_setspecific(THR_SEN_select_limit, tmp); + } + *tmp = thd->select_limit; +} +#endif + if (having || (select_options & OPTION_FOUND_ROWS)) select_limit= HA_POS_ERROR; diff -Nur mysql-4.0.24.orig/myisam/ft_boolean_search.c mysql-4.0.24/myisam/ft_boolean_search.c --- mysql-4.0.24.orig/myisam/ft_boolean_search.c 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/myisam/ft_boolean_search.c 2005-07-01 03:30:20.000000000 +0900 @@ -22,6 +22,14 @@ #include "ftdefs.h" #include +#ifdef THREAD +extern pthread_key(long, THR_SEN_nhit); +extern pthread_key(long, THR_SEN_skipmode); +extern pthread_key(long, THR_SEN_select_limit); +extern pthread_key(long, THR_SEN_offset_limit); +extern pthread_key(long, THR_SEN_current_row); +#endif + /* search with boolean queries */ static double _wghts[11]= @@ -85,6 +93,9 @@ uint ndepth; int len; /* ... docid cache can be added here. SerG */ + my_off_t *pos; + int hit; + int cursor; byte word[1]; } FTB_WORD; @@ -104,6 +115,20 @@ MEM_ROOT mem_root; } FTB; +long * _get_current_row_num (void) +{ +#ifdef THREAD + long *tmp = pthread_getspecific(THR_SEN_current_row); + if (!tmp) { + tmp = (long *) calloc(1, sizeof(long)); + pthread_setspecific(THR_SEN_current_row, tmp); + *tmp = 0; + } + return tmp; +#endif + return 0; +} + static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b) { int i; @@ -154,6 +179,9 @@ sizeof(FTB_WORD) + (param.trunc ? MI_MAX_KEY_BUFF : w.len+extra)); + ftbw->pos = NULL; + ftbw->hit = 0; + ftbw->cursor = -1; ftbw->len=w.len+1; ftbw->flags=0; if (param.yesno>0) ftbw->flags|=FTB_FLAG_YES; @@ -197,6 +225,20 @@ return CMP_NUM((*((my_off_t*)a)), (*((my_off_t*)b))); } +int _ftb_record_sort(const void *a, const void *b) { + my_off_t aa = *(my_off_t *)a; + my_off_t bb = *(my_off_t *)b; + return aa - bb; +} +my_off_t _ftb_record_next(FTB_WORD *ftbw) { + my_off_t ret; + if (ftbw->cursor < 0) ftbw->cursor = 0; + if (ftbw->hit <= ftbw->cursor) return -1; + ret = ftbw->pos[ftbw->cursor]; + ftbw->cursor++; + return ret; +} + static void _ftb_init_index_search(FT_INFO *ftb) { int i, r; @@ -262,6 +304,51 @@ else reset_tree(& ftb->no_dupes); } + + { + char *query; + const int *pos; + my_off_t pos2; + int hit, i; + sen_records *sir; + long *current_row; + + current_row = _get_current_row_num(); + if (current_row) + *current_row = 0; + + query = calloc(ftbw->len + 1, sizeof(char)); + memcpy(query, (uchar*) ftbw->word + 1, ftbw->len - 1); + + sir = sen_index_sel(keyinfo->senna, query); + free(query); + + if (!sir || !(hit = sen_records_nhits(sir))) { + if (sir) { sen_records_close(sir); } + if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0) { + ftb->state=INDEX_DONE; + return; + } + continue; + } + + ftbw->hit = hit; + ftbw->pos = (my_off_t *) calloc(hit, sizeof(my_off_t)); + i = 0; + while ((pos = sen_records_next(sir))) { + ftbw->pos[i] = *pos; + i++; + } + sen_records_close(sir); + qsort(ftbw->pos, ftbw->hit, sizeof(my_off_t), _ftb_record_sort); + pos2 = _ftb_record_next(ftbw); + + info->lastpos = pos2; + //memcpy(ftbw->word, info->lastkey, info->lastkey_length); + ftbw->docid[0] = info->lastpos; + continue; + } + for ( r=_mi_search(info, keyinfo, (uchar*) ftbw->word, ftbw->len, SEARCH_FIND | SEARCH_BIGGER, keyroot) ; @@ -502,6 +589,25 @@ { _ftb_climb_the_tree(ftb, ftbw, 0); + { + //const int *pos; + my_off_t pos2; + pos2 = _ftb_record_next(ftbw); + + if (pos2 >= 0) { + info->lastpos = pos2; + //memcpy(ftbw->word, info->lastkey, info->lastkey_length); + ftbw->docid[0]=info->lastpos; + } else { + ftbw->docid[0]=HA_OFFSET_ERROR; + if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0) { + ftb->state=INDEX_DONE; + } + } + queue_replaced(& ftb->queue); + continue; + } + /* update queue */ for ( r=_mi_search(info, keyinfo, (uchar*) ftbw->word, USE_WHOLE_KEY, @@ -538,7 +644,6 @@ } queue_replaced(& ftb->queue); } - ftbe=ftb->root; if (ftbe->docid[0]==curdoc && ftbe->cur_weight>0 && ftbe->yesses>=(ftbe->ythresh-ftbe->yweaks) && !ftbe->nos) @@ -549,6 +654,44 @@ /* but it managed to get past this line once */ continue; + { + info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); + info->lastpos=curdoc; + +#ifdef THREAD +{ + long *skipmode = pthread_getspecific(THR_SEN_skipmode); + long *current_row = _get_current_row_num(); + + if (skipmode) { + if (*skipmode) { + long *select_limit, *offset_limit; + select_limit = pthread_getspecific(THR_SEN_select_limit); + offset_limit = pthread_getspecific(THR_SEN_offset_limit); + if (select_limit && offset_limit) { + if (*offset_limit > *current_row || *select_limit <= *current_row) { + my_errno = 0; + (*current_row)++; + goto err; + } + } + } + } +#endif + if (!(*info->read_record)(info,info->lastpos,record)) { + info->update|= HA_STATE_AKTIV; /* Record is read */ + if (ftb->with_scan && ft_boolean_find_relevance(ftb,record,0)==0) + continue; + my_errno = 0; + } +#ifdef THREAD +if (current_row) + (*current_row)++; +} +#endif + goto err; + } + info->lastpos=curdoc; info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); @@ -585,6 +728,8 @@ if (!ftb->queue.elements) return 0; + return 1.0; + if (ftb->state != INDEX_SEARCH && docid <= ftb->lastpos) { FTB_EXPR *x; @@ -655,6 +800,13 @@ void ft_boolean_close_search(FT_INFO *ftb) { + int i; + for (i = 0;i < ftb->queue.elements;i++) { + FTB_WORD *ftbw = (FTB_WORD *)(ftb->list[i]); + if (ftbw->pos) + free(ftbw->pos); + } + if (is_tree_inited(& ftb->no_dupes)) { delete_tree(& ftb->no_dupes); diff -Nur mysql-4.0.24.orig/myisam/ft_nlq_search.c mysql-4.0.24/myisam/ft_nlq_search.c --- mysql-4.0.24.orig/myisam/ft_nlq_search.c 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/myisam/ft_nlq_search.c 2005-07-01 03:28:18.000000000 +0900 @@ -33,6 +33,7 @@ MI_INFO *info; int ndocs; int curdoc; + sen_records *sir; FT_DOC doc[1]; }; @@ -176,8 +177,15 @@ FT_DOC *dptr; FT_INFO *dlist=NULL; my_off_t saved_lastpos=info->lastpos; + sen_records *sir; DBUG_ENTER("ft_init_nlq_search"); + // sen_log("ft_init_nlq_search(%p,%d,%p,%d,%d)", info, keynr, query, query_len, presort); + + sir = sen_index_sel(info->s->keyinfo[keynr].senna, query); + + // sen_log("sen_index_search done"); + /* black magic ON */ if ((int) (keynr = _mi_check_index(info,keynr)) < 0) DBUG_RETURN(NULL); @@ -221,6 +229,8 @@ dlist->info=aio.info; dptr=dlist->doc; + dlist->sir = sir; + tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy, &dptr, left_root_right); @@ -240,6 +250,32 @@ int ft_nlq_read_next(FT_INFO *handler, char *record) { MI_INFO *info= (MI_INFO *) handler->info; + // sen_log("ft_nlq_read_next(%p,%p)", handler, record); + + if (handler->sir) { + const int *pos; + + info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); + + if ((pos = sen_records_next(handler->sir))) { + + info->lastpos=*pos; + + if (!(*info->read_record)(info,info->lastpos,record)) + { + + // sen_log("ft_nlq_read_next' %p %x %d", info, *((uint *)record), info->lastpos); + + info->update|= HA_STATE_AKTIV; /* Record is read */ + return 0; + } + + return my_errno; + + } else { + return HA_ERR_END_OF_FILE; + } + } if (++handler->curdoc >= handler->ndocs) { @@ -267,9 +303,17 @@ FT_DOC *docs=handler->doc; my_off_t docid=handler->info->lastpos; + // sen_log("ft_nlq_find_relevance(docid=%d)", docid); + if (docid == HA_POS_ERROR) return -5.0; + if (!handler->sir) { return 0.0; } + + // sen_log("score = %d", sen_records_find(handler->sir, &docid)); + + return 1.0 * sen_records_find(handler->sir, &docid); + /* Assuming docs[] is sorted by dpos... */ for (a=0, b=handler->ndocs, c=(a+b)/2; b-a>1; c=(a+b)/2) @@ -289,18 +333,28 @@ void ft_nlq_close_search(FT_INFO *handler) { + sen_log("ft_nlq_close_search(%p)", handler); + sen_records_close(handler->sir); my_free((gptr)handler,MYF(0)); } float ft_nlq_get_relevance(FT_INFO *handler) { + // sen_log("ft_nlq_get_relevance(%p)", handler); + + if (!handler->sir) { return 0.0; } + + return 1.0 * sen_records_curr_score(handler->sir); + return (float) handler->doc[handler->curdoc].weight; } void ft_nlq_reinit_search(FT_INFO *handler) { + sen_log("ft_nlq_reinit_search(%p)", handler); + sen_records_rewind(handler->sir); handler->curdoc=-1; } diff -Nur mysql-4.0.24.orig/myisam/ft_update.c mysql-4.0.24/myisam/ft_update.c --- mysql-4.0.24.orig/myisam/ft_update.c 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/myisam/ft_update.c 2005-07-01 03:28:18.000000000 +0900 @@ -107,13 +107,12 @@ byte *keybuf __attribute__((unused)), const byte *record) { - TREE ptree; - - bzero((char*) &ptree, sizeof(ptree)); - if (_mi_ft_parse(&ptree, info, keynr, record)) + FT_WORD *wlist; + if (!(wlist = (FT_WORD *) my_malloc(sizeof(FT_WORD), MYF(0)))) { return NULL; - - return ft_linearize(/*info, keynr, keybuf, */ &ptree); + } + wlist->pos = 0; + return wlist; } static int _mi_ft_store(MI_INFO *info, uint keynr, byte *keybuf, @@ -170,6 +169,54 @@ return GEE_THEY_ARE_ABSOLUTELY_IDENTICAL; } +int ft_sen_index_add(MI_INFO *info, uint keynr, const byte *record, my_off_t pos) +{ + FT_SEG_ITERATOR ftsi; + char *buf, *p; + int len; + _mi_ft_segiterator_init(info, keynr, record, &ftsi); + for (len = 0; _mi_ft_segiterator(&ftsi); len += ftsi.len + 1) { + // sen_log("len=%d", ftsi.len); + } + if (!len) { return -1; } + p = buf = malloc(len); + _mi_ft_segiterator_init(info, keynr, record, &ftsi); + while (_mi_ft_segiterator(&ftsi)) { + if (ftsi.pos) { + if (p != buf) { *p++ = ' '; } + memcpy(p, ftsi.pos, ftsi.len); + p += ftsi.len; + } + } + *p = '\0'; + sen_index_upd(info->s->keyinfo[keynr].senna, &pos, NULL, buf); + free(buf); + return 0; +} + +int ft_sen_index_del(MI_INFO *info, uint keynr, const byte *record, my_off_t pos) +{ + FT_SEG_ITERATOR ftsi; + char *buf, *p; + int len; + _mi_ft_segiterator_init(info, keynr, record, &ftsi); + for (len = 0; _mi_ft_segiterator(&ftsi); len += ftsi.len) { + // sen_log("len=%d", ftsi.len); + } + if (!len) { return -1; } + p = buf = malloc(len + 1); + _mi_ft_segiterator_init(info, keynr, record, &ftsi); + while (_mi_ft_segiterator(&ftsi)) { + if (ftsi.pos) { + memcpy(p, ftsi.pos, ftsi.len); + p += ftsi.len; + } + } + *p = '\0'; + sen_index_upd(info->s->keyinfo[keynr].senna, &pos, buf, NULL); + free(buf); + return 0; +} /* update a document entry */ @@ -182,6 +229,11 @@ uint key_length; int cmp, cmp2; + // sen_log("_mi_ft_update(%p,%d,%p,%p,%p,%d)", info, keynr, keybuf, oldrec, newrec, pos); + + ft_sen_index_del(info, keynr, oldrec, pos); + ft_sen_index_add(info, keynr, newrec, pos); + if (!(old_word=oldlist=_mi_ft_parserecord(info, keynr, keybuf, oldrec))) goto err0; if (!(new_word=newlist=_mi_ft_parserecord(info, keynr, keybuf, newrec))) @@ -222,7 +274,6 @@ return error; } - /* adds a document to the collection */ int _mi_ft_add(MI_INFO *info, uint keynr, byte *keybuf, const byte *record, @@ -231,6 +282,10 @@ int error= -1; FT_WORD *wlist; + // sen_log("_mi_ft_add(%p,%d,%p,%p,%d)", info, keynr, keybuf, record, pos); + + ft_sen_index_add(info, keynr, record, pos); + if ((wlist=_mi_ft_parserecord(info, keynr, keybuf, record))) { error=_mi_ft_store(info,keynr,keybuf,wlist,pos); @@ -247,6 +302,11 @@ { int error= -1; FT_WORD *wlist; + + // sen_log("_mi_ft_del(%p,%d,%p,%p,%d)", info, keynr, keybuf, record, pos); + + ft_sen_index_del(info, keynr, record, pos); + if ((wlist=_mi_ft_parserecord(info, keynr, keybuf, record))) { error=_mi_ft_erase(info,keynr,keybuf,wlist,pos); diff -Nur mysql-4.0.24.orig/myisam/ftdefs.h mysql-4.0.24/myisam/ftdefs.h --- mysql-4.0.24.orig/myisam/ftdefs.h 2005-03-05 09:38:16.000000000 +0900 +++ mysql-4.0.24/myisam/ftdefs.h 2005-07-01 03:28:18.000000000 +0900 @@ -22,7 +22,8 @@ #include #include -#define true_word_char(X) (isalnum(X) || (X)=='_') +//#define true_word_char(X) (isalnum(X) || (X)=='_') +#define true_word_char(X) (((X)!='+'&&(X)!='-'&&(X)!='<'&&(X)!='>'&&(X)!='('&&(X)!=')'&&(X)!='~'&&(X)!='*'&&(X)!='"'&&(X)!=' ')) #define misc_word_char(X) ((X)=='\'') #define word_char(X) (true_word_char(X) || misc_word_char(X)) diff -Nur mysql-4.0.24.orig/myisam/mi_check.c mysql-4.0.24/myisam/mi_check.c --- mysql-4.0.24.orig/myisam/mi_check.c 2005-03-05 09:38:16.000000000 +0900 +++ mysql-4.0.24/myisam/mi_check.c 2005-07-01 03:28:18.000000000 +0900 @@ -1819,6 +1819,8 @@ ulonglong key_map=share->state.key_map; DBUG_ENTER("mi_repair_by_sort"); + sen_log("mi_repair_by_sort"); + start_records=info->state->records; got_error=1; new_file= -1; @@ -2598,6 +2600,7 @@ my_free((char*) wptr, MYF(MY_ALLOW_ZERO_PTR)); if ((error=sort_get_next_record(sort_param))) DBUG_RETURN(error); + ft_sen_index_add(info, sort_param->key, sort_param->record, sort_param->filepos); if (!(wptr=_mi_ft_parserecord(info,sort_param->key, key,sort_param->record))) DBUG_RETURN(1); diff -Nur mysql-4.0.24.orig/myisam/mi_close.c mysql-4.0.24/myisam/mi_close.c --- mysql-4.0.24.orig/myisam/mi_close.c 2005-03-05 09:38:16.000000000 +0900 +++ mysql-4.0.24/myisam/mi_close.c 2005-07-01 03:28:18.000000000 +0900 @@ -31,6 +31,8 @@ DBUG_PRINT("enter",("base: %lx reopen: %u locks: %u", info,(uint) share->reopen, (uint) share->tot_locks)); + sen_log("closing index_file_name %s", share->index_file_name); + pthread_mutex_lock(&THR_LOCK_myisam); if (info->lock_type == F_EXTRA_LCK) info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */ @@ -98,6 +100,27 @@ keys = share->state.header.keys; for(i=0; ikey_root_lock[i])); + + if (share->keyinfo[i].flag & HA_FULLTEXT) + { + sen_log("share->delay_key_write=%d", share->delay_key_write); + sen_log("unique_file_name %s", share->unique_file_name); + sen_log("data_file_name %s", share->data_file_name); + sen_log("index_file_name %s", share->index_file_name); + + { + char buf[PATH_MAX]; + strcpy(buf, share->unique_file_name); + sprintf(buf + strlen(buf) - 3, "%03d", i); + sen_log("closing (%s)", buf); + if (share->keyinfo[i].senna) { + sen_index_close(share->keyinfo[i].senna); + } + } + + } + + } } #endif diff -Nur mysql-4.0.24.orig/myisam/mi_delete_table.c mysql-4.0.24/myisam/mi_delete_table.c --- mysql-4.0.24.orig/myisam/mi_delete_table.c 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/myisam/mi_delete_table.c 2005-07-01 03:28:18.000000000 +0900 @@ -31,6 +31,7 @@ #endif DBUG_ENTER("mi_delete_table"); + sen_log("mi_delete_table(%s)", name); #ifdef EXTRA_DEBUG check_table_is_closed(name,"delete"); #endif @@ -49,6 +50,20 @@ #endif #endif /* USE_RAID */ + { + int i; + for (i = 0; i < 100; i++) { + snprintf(from, FN_REFLEN, "%s.%03d.SEN", name, i); + unlink(from); + snprintf(from, FN_REFLEN, "%s.%03d.SEN.i", name, i); + unlink(from); + snprintf(from, FN_REFLEN, "%s.%03d.SEN.i.c", name, i); + unlink(from); + snprintf(from, FN_REFLEN, "%s.%03d.SEN.l", name, i); + unlink(from); + } + } + fn_format(from,name,"",MI_NAME_IEXT,4); if (my_delete_with_symlink(from, MYF(MY_WME))) DBUG_RETURN(my_errno); diff -Nur mysql-4.0.24.orig/myisam/mi_open.c mysql-4.0.24/myisam/mi_open.c --- mysql-4.0.24.orig/myisam/mi_open.c 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/myisam/mi_open.c 2005-07-01 03:28:18.000000000 +0900 @@ -329,6 +329,25 @@ } if (share->keyinfo[i].flag & HA_FULLTEXT) { + sen_log("share->delay_key_write=%d", share->delay_key_write); + sen_log("unique_file_name %s", share->unique_file_name); + sen_log("data_file_name %s", share->data_file_name); + sen_log("index_file_name %s", share->index_file_name); + sen_log("share->keyinfo[%d].seg=%d", i, pos-FT_SEGS); + + { + char buf[PATH_MAX]; + strcpy(buf, share->unique_file_name); + sprintf(buf + strlen(buf) - 3, "%03d", i); + sen_log("open (%s)", buf); + share->keyinfo[i].senna = sen_index_open(buf); + if (!share->keyinfo[i].senna) { + /* make index files */ + sen_log("create index (%s)", buf); + share->keyinfo[i].senna = sen_index_create(buf, sizeof(my_off_t), SEN_INDEX_NORMALIZE, 0, sen_enc_default); + } + } + share->keyinfo[i].seg=pos-FT_SEGS; share->fulltext_index=1; } diff -Nur mysql-4.0.24.orig/myisam/mi_rename.c mysql-4.0.24/myisam/mi_rename.c --- mysql-4.0.24.orig/myisam/mi_rename.c 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/myisam/mi_rename.c 2005-07-01 03:28:18.000000000 +0900 @@ -49,6 +49,25 @@ #endif #endif /* USE_RAID */ + sen_log("mi_rename(%s,%s)", old_name, new_name); + { + int i; + for (i = 0; i < 100; i++) { + snprintf(from, FN_REFLEN, "%s.%03d.SEN", old_name, i); + snprintf(to, FN_REFLEN, "%s.%03d.SEN", new_name, i); + rename(from, to); + snprintf(from, FN_REFLEN, "%s.%03d.SEN.i", old_name, i); + snprintf(to, FN_REFLEN, "%s.%03d.SEN.i", new_name, i); + rename(from, to); + snprintf(from, FN_REFLEN, "%s.%03d.SEN.i.c", old_name, i); + snprintf(to, FN_REFLEN, "%s.%03d.SEN.i.c", new_name, i); + rename(from, to); + snprintf(from, FN_REFLEN, "%s.%03d.SEN.l", old_name, i); + snprintf(to, FN_REFLEN, "%s.%03d.SEN.l", new_name, i); + rename(from, to); + } + } + fn_format(from,old_name,"",MI_NAME_IEXT,4); fn_format(to,new_name,"",MI_NAME_IEXT,4); if (my_rename_with_symlink(from, to, MYF(MY_WME))) diff -Nur mysql-4.0.24.orig/mysys/my_thr_init.c mysql-4.0.24/mysys/my_thr_init.c --- mysql-4.0.24.orig/mysys/my_thr_init.c 2005-03-05 09:38:16.000000000 +0900 +++ mysql-4.0.24/mysys/my_thr_init.c 2005-07-01 03:30:08.000000000 +0900 @@ -23,6 +23,10 @@ #include #ifdef THREAD +pthread_key(long, THR_SEN_skipmode); +pthread_key(long, THR_SEN_select_limit); +pthread_key(long, THR_SEN_offset_limit); +pthread_key(long, THR_SEN_current_row); #ifdef USE_TLS pthread_key(struct st_my_thread_var*, THR_KEY_mysys); #else @@ -55,6 +59,11 @@ 1 error (Couldn't create THR_KEY_mysys) */ +void _pthread_key_create_sen_dest (void *p) +{ + free(p); +} + my_bool my_thread_global_init(void) { if (pthread_key_create(&THR_KEY_mysys,0)) @@ -62,6 +71,26 @@ fprintf(stderr,"Can't initialize threads: error %d\n",errno); return 1; } + if (pthread_key_create(&THR_SEN_skipmode, _pthread_key_create_sen_dest)) + { + fprintf(stderr,"Can't initialize threads: error %d\n",errno); + return 1; + } + if (pthread_key_create(&THR_SEN_select_limit, _pthread_key_create_sen_dest)) + { + fprintf(stderr,"Can't initialize threads: error %d\n",errno); + return 1; + } + if (pthread_key_create(&THR_SEN_offset_limit, _pthread_key_create_sen_dest)) + { + fprintf(stderr,"Can't initialize threads: error %d\n",errno); + return 1; + } + if (pthread_key_create(&THR_SEN_current_row, _pthread_key_create_sen_dest)) + { + fprintf(stderr,"Can't initialize threads: error %d\n",errno); + return 1; + } #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP pthread_mutexattr_init(&my_fast_mutexattr); pthread_mutexattr_setkind_np(&my_fast_mutexattr,PTHREAD_MUTEX_ADAPTIVE_NP); @@ -102,6 +131,10 @@ void my_thread_global_end(void) { pthread_key_delete(THR_KEY_mysys); + pthread_key_delete(THR_SEN_skipmode); + pthread_key_delete(THR_SEN_select_limit); + pthread_key_delete(THR_SEN_offset_limit); + pthread_key_delete(THR_SEN_current_row); #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP pthread_mutexattr_destroy(&my_fast_mutexattr); #endif diff -Nur mysql-4.0.24.orig/sql/item_create.cc mysql-4.0.24/sql/item_create.cc --- mysql-4.0.24.orig/sql/item_create.cc 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/sql/item_create.cc 2005-07-01 03:29:44.000000000 +0900 @@ -455,3 +455,9 @@ { return new Item_func_quote(a); } + + +Item *create_func_sen_skipmode_set(Item* a) +{ + return new Item_func_sen_skipmode_set(a); +} diff -Nur mysql-4.0.24.orig/sql/item_create.h mysql-4.0.24/sql/item_create.h --- mysql-4.0.24.orig/sql/item_create.h 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/sql/item_create.h 2005-07-01 03:29:44.000000000 +0900 @@ -95,3 +95,6 @@ Item *create_load_file(Item* a); Item *create_func_is_free_lock(Item* a); Item *create_func_quote(Item* a); + +Item *create_func_sen_skipmode_set(Item* a); + diff -Nur mysql-4.0.24.orig/sql/item_func.cc mysql-4.0.24/sql/item_func.cc --- mysql-4.0.24.orig/sql/item_func.cc 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/sql/item_func.cc 2005-07-01 03:29:44.000000000 +0900 @@ -2472,3 +2472,25 @@ return 1; return 0; } + + + +#include +extern "C" { +extern pthread_key_t THR_SEN_skipmode; +} +longlong Item_func_sen_skipmode_set::val_int() +{ + longlong arg1= (longlong) args[0]->val_int(); + long *skipmode; +#ifdef THREAD + skipmode = (long *) pthread_getspecific(THR_SEN_skipmode); + if (!skipmode) { + skipmode = (long *) calloc(1, sizeof(long)); + pthread_setspecific(THR_SEN_skipmode, skipmode); + } + *skipmode = arg1; +#endif + return (longlong) arg1; +} + diff -Nur mysql-4.0.24.orig/sql/item_func.h mysql-4.0.24/sql/item_func.h --- mysql-4.0.24.orig/sql/item_func.h 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/sql/item_func.h 2005-07-01 03:29:44.000000000 +0900 @@ -1041,3 +1041,15 @@ void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;} unsigned int size_of() { return sizeof(*this);} }; + + + +class Item_func_sen_skipmode_set :public Item_int_func +{ + String value; +public: + Item_func_sen_skipmode_set(Item *a) :Item_int_func(a) {} + longlong val_int(); + const char *func_name() const { return "sen_skipmode_set"; } + unsigned int size_of() { return sizeof(*this);} +}; diff -Nur mysql-4.0.24.orig/sql/lex.h mysql-4.0.24/sql/lex.h --- mysql-4.0.24.orig/sql/lex.h 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/sql/lex.h 2005-07-01 03:29:18.000000000 +0900 @@ -496,6 +496,7 @@ { "RPAD", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_rpad)}, { "RTRIM", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_rtrim)}, { "SEC_TO_TIME", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sec_to_time)}, + { "SEN_SKIPMODE_SET", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sen_skipmode_set)}, { "SESSION_USER", SYM(USER),0,0}, { "SUBDATE", SYM(DATE_SUB_INTERVAL),0,0}, { "SIGN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sign)}, diff -Nur mysql-4.0.24.orig/sql/mysqld.cc mysql-4.0.24/sql/mysqld.cc --- mysql-4.0.24.orig/sql/mysqld.cc 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/sql/mysqld.cc 2005-07-01 03:28:18.000000000 +0900 @@ -2427,6 +2427,9 @@ #ifdef USE_REGEX regex_init(); #endif +//#ifdef SENNA + sen_init(); +//#endif select_thread=pthread_self(); select_thread_in_use=1; if (use_temp_pool && bitmap_init(&temp_pool,1024,1)) diff -Nur mysql-4.0.24.orig/sql/sql_db.cc mysql-4.0.24/sql/sql_db.cc --- mysql-4.0.24.orig/sql/sql_db.cc 2005-03-05 09:38:15.000000000 +0900 +++ mysql-4.0.24/sql/sql_db.cc 2005-07-01 03:28:18.000000000 +0900 @@ -252,6 +252,36 @@ (file->name[1] == '.' && !file->name[2]))) continue; + /* senna files is skip */ + /* ".SEN",".SEN.i",".SEN.i.c",".SEN.l" */ + { + int len = strlen(file->name); + if (len > 4 && file->name[len-1] == 'N') { + if (file->name[len-4] == '.' && + file->name[len-3] == 'S' && + file->name[len-2] == 'E') + continue; + } + if (len > 6 && file->name[len-2] == '.' && + (file->name[len-1] == 'l' || file->name[len-1] == 'i')) { + if (file->name[len-6] == '.' && + file->name[len-5] == 'S' && + file->name[len-4] == 'E' && + file->name[len-3] == 'N') + continue; + } + if (len > 8 && file->name[len-1] == 'c') { + if (file->name[len-8] == '.' && + file->name[len-7] == 'S' && + file->name[len-6] == 'E' && + file->name[len-5] == 'N' && + file->name[len-4] == '.' && + file->name[len-3] == 'i' && + file->name[len-2] == '.') + continue; + } + } + /* Check if file is a raid directory */ if ((isdigit(file->name[0]) || (file->name[0] >= 'a' && file->name[0] <= 'f')) && diff -Nur mysql-4.0.24.orig/sql/sql_select.cc mysql-4.0.24/sql/sql_select.cc --- mysql-4.0.24.orig/sql/sql_select.cc 2005-03-05 09:38:14.000000000 +0900 +++ mysql-4.0.24/sql/sql_select.cc 2005-07-01 03:29:28.000000000 +0900 @@ -21,6 +21,15 @@ #pragma implementation // gcc: Class implementation #endif +#include +extern "C" { +//#include +//extern pthread_key(long, THR_SEN_select_limit); +//extern pthread_key(long, THR_SEN_offset_limit); +extern pthread_key_t THR_SEN_select_limit; +extern pthread_key_t THR_SEN_offset_limit; +} + #include "mysql_priv.h" #include "sql_select.h" @@ -247,6 +256,25 @@ thd->used_tables=0; // Updated by setup_fields /* select_limit is used to decide if we are likely to scan the whole table */ select_limit= thd->select_limit; + +#ifdef THREAD +{ + long *tmp = (long *) pthread_getspecific(THR_SEN_offset_limit); + if (!tmp) { + tmp = (long *) calloc(1, sizeof(long)); + pthread_setspecific(THR_SEN_offset_limit, tmp); + } + *tmp = thd->offset_limit; + + tmp = (long *) pthread_getspecific(THR_SEN_select_limit); + if (!tmp) { + tmp = (long *) calloc(1, sizeof(long)); + pthread_setspecific(THR_SEN_select_limit, tmp); + } + *tmp = thd->select_limit; +} +#endif + if (having || (select_options & OPTION_FOUND_ROWS)) select_limit= HA_POS_ERROR;