summaryrefslogtreecommitdiff
path: root/myisam
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2002-06-11 11:20:31 +0300
committerunknown <monty@mashka.mysql.fi>2002-06-11 11:20:31 +0300
commit70aa7424c41c45a8fb171bbdd9e24d74b70a7765 (patch)
tree8fcaabe013fff43cf466235067f2c47f0cd66531 /myisam
parent30d5eb22877d0546fb4bd93ead7e8602285d449b (diff)
downloadmariadb-git-70aa7424c41c45a8fb171bbdd9e24d74b70a7765.tar.gz
Big code cleanup/review before 4.0.2 release.
(All commit emails since 4.0.1 checked) This had to be done now, before the 4.1 tree changes to much, to make it easy to propagate bug fixes to the 4.1 tree. BUILD/SETUP.sh: Added -DPEDANTIC_SAFEMALLOC as standard debug option Docs/manual.texi: Changes for new version. client/mysql.cc: Fixed default value for rehash cleanup client/mysqladmin.c: Cleanup client/mysqlbinlog.cc: cleanup client/mysqldump.c: Cleanup client/mysqlmanager-pwgen.c: Cleanup client/mysqlmanagerc.c: Cleanup client/mysqltest.c: Cleanup dbug/dbug.c: Cleanup extra/resolve_stack_dump.c: Cleanup & Simple optimizations include/ft_global.h: Cleanup include/my_alloc.h: Cleanup include/my_global.h: Cleanup include/my_sys.h: Cleanup include/myisam.h: Cleanup libmysql/libmysql.c: Cleanup libmysql/manager.c: Cleanup myisam/ft_boolean_search.c: Cleanup myisam/ft_dump.c: Change strcpy -> strmov myisam/ft_eval.c: Cleanup myisam/ft_nlq_search.c: Cleanup myisam/ft_test1.c: strncpy -> strnmov myisam/ft_update.c: Cleanup myisam/mi_static.c: Cleanup myisam/mi_test2.c: Cleanup myisam/mi_write.c: Cleanup mysys/mf_fn_ext.c: Cleanup mysys/mf_iocache.c: Cleanup mysys/mf_iocache2.c: Cleanup mysys/my_getopt.c: Cleanup mysys/my_read.c: Cleanup mysys/my_thr_init.c: Cleanup mysys/queues.c: Cleanup mysys/safemalloc.c: Cleanup sql/field.cc: Indentation cleanups sql/ha_berkeley.cc: Indentation cleanups sql/ha_myisam.cc: Cleanup sql/item.h: Indentation cleanups sql/item_cmpfunc.cc: Indentation cleanups sql/item_create.cc: cleanup sql/item_func.cc: Cleanup sql/item_func.h: Indentation cleanups sql/item_strfunc.cc: Indentation cleanups sql/item_sum.cc: Indentation cleanups sql/item_timefunc.cc: Indentation cleanups sql/lock.cc: Indentation cleanups sql/log.cc: Cleanup strnmov -> strmake sql/log_event.cc: Cleanup + optimizations Fixed memory leak Added missing pthread_mutex_unlock() (On error condition) sql/log_event.h: Indentation and comment cleanup Merged #ifdef's into common blocks for better readability sql/mini_client.cc: Indentation cleanup sql/mysql_priv.h: Cleanup Changed int function to bool sql/mysqld.cc: Indentation and comment cleanup sql/net_pkg.cc: Indentation cleanup sql/net_serv.cc: Changed int function -> bool sql/nt_servc.cc: Cleanup sql/opt_range.cc: Indentation cleanup sql/repl_failsafe.cc: Cleanup + simple optimization strnmov -> strmake sql/slave.cc: strnmov -> strmake Cleanups sql/slave.h: Cleanup sql/sql_acl.cc: Indentation and DBUG_PRINT cleanup Changed WITH MAX... to not use = sql/sql_base.cc: Indentation cleanup sql/sql_cache.cc: Indentation cleanup sql/sql_class.cc: Indentation cleanup sql/sql_class.h: Renamed some struct slots sql/sql_delete.cc: Indentation cleanup sql/sql_handler.cc: Indentation cleanup sql/sql_insert.cc: Use new slot names. sql/sql_lex.cc: Indentation cleanup sql/sql_lex.h: Indentation cleanup sql/sql_load.cc: Indentation cleanup sql/sql_parse.cc: Indentation cleanup Removed not used check from LOCK TABLES sql/sql_repl.cc: strnmov -> strmake sql/sql_repl.h: Removed test if file is included (We want to know if it's included twice to avoid this) sql/sql_select.cc: Indentation cleanup sql/sql_show.cc: Indentation cleanup sql/sql_string.cc: Indentation cleanup sql/sql_table.cc: Indentation cleanup sql/sql_union.cc: Use renamed struct slot sql/sql_update.cc: Indentation cleanup sql/sql_yacc.yy: Removed = after GRANT ... MAX_ to make the syntax uniform sql/table.cc: Indentation cleanup sql/table.h: Indentation cleanup sql/time.cc: Indentation cleanup sql/udf_example.cc: Indentation cleanup sql/unireg.cc: strnmov -> strmake tests/grant.pl: Added test for LOCK TABLES tools/mysqlmanager.c: Cleanup fopen() -> my_fopen() vio/viosocket.c: DBUG_PRINT cleanups vio/viosslfactories.c: Indentation cleanup Checking of results from malloc() Fixed possible memory leak BitKeeper/etc/ignore: Added scripts/mysql_secure_installation to the ignore list BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'myisam')
-rw-r--r--myisam/ft_boolean_search.c88
-rw-r--r--myisam/ft_dump.c6
-rw-r--r--myisam/ft_eval.c62
-rw-r--r--myisam/ft_nlq_search.c63
-rw-r--r--myisam/ft_test1.c12
-rw-r--r--myisam/ft_update.c43
-rw-r--r--myisam/mi_static.c6
-rw-r--r--myisam/mi_test2.c17
-rw-r--r--myisam/mi_write.c12
9 files changed, 192 insertions, 117 deletions
diff --git a/myisam/ft_boolean_search.c b/myisam/ft_boolean_search.c
index 1b44f9d1ab9..8ebc5c33555 100644
--- a/myisam/ft_boolean_search.c
+++ b/myisam/ft_boolean_search.c
@@ -24,7 +24,8 @@
/* search with boolean queries */
-static double _wghts[11]={
+static double _wghts[11]=
+{
0.131687242798354,
0.197530864197531,
0.296296296296296,
@@ -38,7 +39,8 @@ static double _wghts[11]={
7.593750000000000};
static double *wghts=_wghts+5; /* wghts[i] = 1.5**i */
-static double _nwghts[11]={
+static double _nwghts[11]=
+{
-0.065843621399177,
-0.098765432098766,
-0.148148148148148,
@@ -57,7 +59,8 @@ static double *nwghts=_nwghts+5; /* nwghts[i] = -0.5*1.5**i */
#define FTB_FLAG_NO 4 /* should NEVER be set both */
typedef struct st_ftb_expr FTB_EXPR;
-struct st_ftb_expr {
+struct st_ftb_expr
+{
FTB_EXPR *up;
byte *quot, *qend;
float weight;
@@ -70,7 +73,8 @@ struct st_ftb_expr {
int yweaks; /* number of "yes" words for scan only */
};
-typedef struct st_ftb_word {
+typedef struct st_ftb_word
+{
FTB_EXPR *up;
float weight;
uint flags;
@@ -81,7 +85,8 @@ typedef struct st_ftb_word {
byte word[1];
} FTB_WORD;
-typedef struct st_ft_info {
+typedef struct st_ft_info
+{
struct _ft_vft *please;
MI_INFO *info;
uint keynr;
@@ -200,21 +205,23 @@ void _ftb_init_index_search(FT_INFO *ftb)
{
ftbw=(FTB_WORD *)(ftb->queue.root[i]);
- if (ftbw->flags&FTB_FLAG_TRUNC)
- /* special treatment for truncation operator :((
- 1. +trunc* and there're other (not +trunc*) words
+ if (ftbw->flags & FTB_FLAG_TRUNC)
+ {
+ /*
+ special treatment for truncation operator :((
+ 1. +trunc* and there're other (not +trunc*) words
| no need to search in the index, it can never ADD new rows
| to the result, and to remove half-matched rows we do scan anyway
- 2. -trunc*
+ 2. -trunc*
| same as 1.
- 3. trunc*
+ 3. trunc*
| We have to index-search for this prefix.
| It may cause duplicates, as in the index (sorted by <word,docid>)
| <aaaa,row1>
| <aabb,row2>
| <aacc,row1>
| Searching for "aa*" will find row1 twice...
- */
+ */
if ( test(ftbw->flags&FTB_FLAG_NO) || /* 2 */
(test(ftbw->flags&FTB_FLAG_YES) && /* 1 */
ftbw->up->ythresh - ftbw->up->yweaks >1)) /* 1 */
@@ -231,7 +238,7 @@ void _ftb_init_index_search(FT_INFO *ftb)
_ftb_no_dupes_cmp,0,0,0);
}
}
-
+ }
r=_mi_search(info, keyinfo, (uchar*) ftbw->word, ftbw->len,
SEARCH_FIND | SEARCH_BIGGER, keyroot);
if (!r)
@@ -246,8 +253,11 @@ void _ftb_init_index_search(FT_INFO *ftb)
if (r) /* not found */
{
if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0)
- { /* this word MUST BE present in every document returned,
- so we can abort the search right now */
+ {
+ /*
+ This word MUST BE present in every document returned,
+ so we can abort the search right now
+ */
ftb->state=INDEX_DONE;
return;
}
@@ -261,8 +271,10 @@ void _ftb_init_index_search(FT_INFO *ftb)
queue_fix(& ftb->queue);
}
+
FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
- uint query_len, my_bool presort __attribute__((unused)))
+ uint query_len,
+ my_bool presort __attribute__((unused)))
{
FTB *ftb;
FTB_EXPR *ftbe;
@@ -282,9 +294,10 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
init_alloc_root(&ftb->mem_root, 1024, 1024);
- /* hack: instead of init_queue, we'll use reinit queue to be able
- * to alloc queue with alloc_root()
- */
+ /*
+ Hack: instead of init_queue, we'll use reinit queue to be able
+ to alloc queue with alloc_root()
+ */
res=ftb->queue.max_elements=1+query_len/(ft_min_word_len+1);
ftb->queue.root=(byte **)alloc_root(&ftb->mem_root, (res+1)*sizeof(void*));
reinit_queue(& ftb->queue, res, 0, 0,
@@ -309,6 +322,7 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
return ftb;
}
+
/* returns 1 if str0 contain str1 */
int _ftb_strstr(const byte *s0, const byte *e0,
const byte *s1, const byte *e1,
@@ -333,6 +347,7 @@ int _ftb_strstr(const byte *s0, const byte *e0,
return 0;
}
+
void _ftb_climb_the_tree(FTB *ftb, FTB_WORD *ftbw, FT_SEG_ITERATOR *ftsi_orig)
{
FT_SEG_ITERATOR ftsi;
@@ -381,28 +396,31 @@ void _ftb_climb_the_tree(FTB *ftb, FTB_WORD *ftbw, FT_SEG_ITERATOR *ftsi_orig)
else
if (yn & FTB_FLAG_NO)
{
- /* NOTE: special sort function of queue assures that all
- * (yn & FTB_FLAG_NO) != 0
- * events for every particular subexpression will
- * "auto-magically" happen BEFORE all the
- * (yn & FTB_FLAG_YES) != 0 events. So no
- * already matched expression can become not-matched again.
+ /*
+ NOTE: special sort function of queue assures that all
+ (yn & FTB_FLAG_NO) != 0
+ events for every particular subexpression will
+ "auto-magically" happen BEFORE all the
+ (yn & FTB_FLAG_YES) != 0 events. So no
+ already matched expression can become not-matched again.
*/
++ftbe->nos;
break;
}
else
{
- if (ftbe->ythresh) weight/=3;
+ if (ftbe->ythresh)
+ weight/=3;
ftbe->cur_weight += weight;
if (ftbe->yesses < ythresh)
break;
yn= (ftbe->yesses++ == ythresh) ? ftbe->flags : 0 ;
- weight*=ftbe->weight;
+ weight*= ftbe->weight;
}
}
}
+
int ft_boolean_read_next(FT_INFO *ftb, char *record)
{
FTB_EXPR *ftbe;
@@ -426,8 +444,9 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
if (!ftb->queue.elements)
return my_errno=HA_ERR_END_OF_FILE;
- while(ftb->state == INDEX_SEARCH &&
- (curdoc=((FTB_WORD *)queue_top(& ftb->queue))->docid[0]) != HA_POS_ERROR)
+ while (ftb->state == INDEX_SEARCH &&
+ (curdoc=((FTB_WORD *)queue_top(& ftb->queue))->docid[0]) !=
+ HA_POS_ERROR)
{
while (curdoc==(ftbw=(FTB_WORD *)queue_top(& ftb->queue))->docid[0])
{
@@ -449,8 +468,11 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
{
ftbw->docid[0]=HA_POS_ERROR;
if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0)
- { /* this word MUST BE present in every document returned,
- so we can stop the search right now */
+ {
+ /*
+ This word MUST BE present in every document returned,
+ so we can stop the search right now
+ */
ftb->state=INDEX_DONE;
}
}
@@ -473,7 +495,7 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
continue;
info->lastpos=curdoc;
- info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); /* why is this ? */
+ info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
if (!(*info->read_record)(info,curdoc,record))
{
@@ -489,6 +511,7 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
return my_errno=HA_ERR_END_OF_FILE;
}
+
float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
{
FT_WORD word;
@@ -555,6 +578,7 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
}
}
+
void ft_boolean_close_search(FT_INFO *ftb)
{
if (is_tree_inited(& ftb->no_dupes))
@@ -565,11 +589,13 @@ void ft_boolean_close_search(FT_INFO *ftb)
my_free((gptr)ftb,MYF(0));
}
+
float ft_boolean_get_relevance(FT_INFO *ftb)
{
return ftb->root->cur_weight;
}
+
void ft_boolean_reinit_search(FT_INFO *ftb)
{
_ftb_init_index_search(ftb);
diff --git a/myisam/ft_dump.c b/myisam/ft_dump.c
index 822603212a0..c9350ee77b9 100644
--- a/myisam/ft_dump.c
+++ b/myisam/ft_dump.c
@@ -148,16 +148,16 @@ int main(int argc,char *argv[])
if (maxlen<keylen2)
{
maxlen=keylen2;
- strcpy(buf_maxlen, buf2);
+ strmov(buf_maxlen, buf2);
}
if (max_doc_cnt < doc_cnt)
{
max_doc_cnt=doc_cnt;
- strcpy(buf_min_gws, buf2);
+ strmov(buf_min_gws, buf2);
min_gws=gws;
}
}
- strcpy(buf2, buf);
+ strmov(buf2, buf);
keylen2=keylen;
doc_cnt=0;
}
diff --git a/myisam/ft_eval.c b/myisam/ft_eval.c
index e196121d7af..34248c69f20 100644
--- a/myisam/ft_eval.c
+++ b/myisam/ft_eval.c
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
my_errno=0;
i=0;
- while(create_record(record,df))
+ while (create_record(record,df))
{
error=mi_write(file,record);
if (error)
@@ -94,24 +94,28 @@ int main(int argc, char *argv[])
if (!(file=mi_open(filename,2,0))) goto err;
if (!silent)
printf("- Reading rows with key\n");
- for(i=1;create_record(record,qf);i++) {
+ for (i=1;create_record(record,qf);i++)
+ {
FT_DOCLIST *result;
double w;
int t, err;
result=ft_nlq_init_search(file,0,blob_record,(uint) strlen(blob_record),1);
- if(!result) {
+ if (!result)
+ {
printf("Query %d failed with errno %3d\n",i,my_errno);
goto err;
}
if (!silent)
printf("Query %d. Found: %d.\n",i,result->ndocs);
- for(j=0;(err=ft_nlq_read_next(result, read_record))==0;j++) {
+ for (j=0;(err=ft_nlq_read_next(result, read_record))==0;j++)
+ {
t=uint2korr(read_record);
w=ft_nlq_get_relevance(result);
printf("%d %.*s %f\n",i,t,read_record+2,w);
- }
- if(err != HA_ERR_END_OF_FILE) {
+ }
+ if (err != HA_ERR_END_OF_FILE)
+ {
printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
goto err;
}
@@ -134,24 +138,28 @@ static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
- switch(optid) {
+ switch (optid) {
case 's':
- if(stopwordlist && stopwordlist!=ft_precompiled_stopwords) break;
+ if (stopwordlist && stopwordlist != ft_precompiled_stopwords)
+ break;
{
FILE *f; char s[HA_FT_MAXLEN]; int i=0,n=SWL_INIT;
- if(!(stopwordlist=(const char**) malloc(n*sizeof(char *))))
+ if (!(stopwordlist=(const char**) malloc(n*sizeof(char *))))
print_error(1,"malloc(%d)",n*sizeof(char *));
- if(!(f=fopen(argument,"r")))
+ if (!(f=fopen(argument,"r")))
print_error(1,"fopen(%s)",argument);
- while(!feof(f)) {
- if(!(fgets(s,HA_FT_MAXLEN,f)))
+ while (!feof(f))
+ {
+ if (!(fgets(s,HA_FT_MAXLEN,f)))
print_error(1,"fgets(s,%d,%s)",HA_FT_MAXLEN,argument);
- if(!(stopwordlist[i++]=strdup(s)))
+ if (!(stopwordlist[i++]=strdup(s)))
print_error(1,"strdup(%s)",s);
- if(i>=n) {
+ if (i >= n)
+ {
n+=SWL_PLUS;
- if(!(stopwordlist=(const char**) realloc((char*) stopwordlist,n*sizeof(char *))))
+ if (!(stopwordlist=(const char**) realloc((char*) stopwordlist,
+ n*sizeof(char *))))
print_error(1,"realloc(%d)",n*sizeof(char *));
}
}
@@ -160,7 +168,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break;
}
case 'q': silent=1; break;
- case 'S': if(stopwordlist==ft_precompiled_stopwords) stopwordlist=NULL; break;
+ case 'S': if (stopwordlist==ft_precompiled_stopwords) stopwordlist=NULL; break;
case '#':
DEBUGGER_ON;
DBUG_PUSH (argument);
@@ -174,6 +182,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
return 0;
}
+
static void get_options(int argc, char *argv[])
{
int ho_error;
@@ -181,24 +190,29 @@ static void get_options(int argc, char *argv[])
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
- if(!(d_file=argv[optind])) print_error(1,"No d_file");
- if(!(df=fopen(d_file,"r")))
+ if (!(d_file=argv[optind])) print_error(1,"No d_file");
+ if (!(df=fopen(d_file,"r")))
print_error(1,"fopen(%s)",d_file);
- if(!(q_file=argv[optind+1])) print_error(1,"No q_file");
- if(!(qf=fopen(q_file,"r")))
+ if (!(q_file=argv[optind+1])) print_error(1,"No q_file");
+ if (!(qf=fopen(q_file,"r")))
print_error(1,"fopen(%s)",q_file);
return;
} /* get options */
+
static int create_record(char *pos, FILE *file)
-{ uint tmp; char *ptr;
+{
+ uint tmp; char *ptr;
bzero((char *)pos,MAX_REC_LENGTH);
/* column 1 - VARCHAR */
- if(!(fgets(pos+2,MAX_REC_LENGTH-32,file)))
+ if (!(fgets(pos+2,MAX_REC_LENGTH-32,file)))
{
- if(feof(file)) return 0; else print_error(1,"fgets(docid) - 1");
+ if (feof(file))
+ return 0;
+ else
+ print_error(1,"fgets(docid) - 1");
}
tmp=(uint) strlen(pos+2)-1;
int2store(pos,tmp);
@@ -206,7 +220,7 @@ static int create_record(char *pos, FILE *file)
/* column 2 - BLOB */
- if(!(fgets(blob_record,MAX_BLOB_LENGTH,file)))
+ if (!(fgets(blob_record,MAX_BLOB_LENGTH,file)))
print_error(1,"fgets(docid) - 2");
tmp=(uint) strlen(blob_record);
int4store(pos,tmp);
diff --git a/myisam/ft_nlq_search.c b/myisam/ft_nlq_search.c
index 42f7d7fc8cf..5670edde7c0 100644
--- a/myisam/ft_nlq_search.c
+++ b/myisam/ft_nlq_search.c
@@ -21,12 +21,14 @@
/* search with natural language queries */
-typedef struct ft_doc_rec {
+typedef struct ft_doc_rec
+{
my_off_t dpos;
double weight;
} FT_DOC;
-struct st_ft_info {
+struct st_ft_info
+{
struct _ft_vft *please;
MI_INFO *info;
int ndocs;
@@ -34,7 +36,8 @@ struct st_ft_info {
FT_DOC doc[1];
};
-typedef struct st_all_in_one {
+typedef struct st_all_in_one
+{
MI_INFO *info;
uint keynr;
CHARSET_INFO *charset;
@@ -44,7 +47,8 @@ typedef struct st_all_in_one {
TREE dtree;
} ALL_IN_ONE;
-typedef struct st_ft_superdoc {
+typedef struct st_ft_superdoc
+{
FT_DOC doc;
FT_WORD *word_ptr;
double tmp_weight;
@@ -92,7 +96,7 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
r=_mi_search(aio->info, aio->keyinfo, aio->keybuff, keylen,
SEARCH_FIND | SEARCH_PREFIX, aio->key_root);
- while(!r)
+ while (!r)
{
if (_mi_compare_text(aio->charset,
aio->info->lastkey,keylen,
@@ -116,11 +120,12 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
sdoc.doc.dpos=aio->info->lastpos;
/* saving document matched into dtree */
- if(!(selem=tree_insert(&aio->dtree, &sdoc, 0))) return 1;
+ if (!(selem=tree_insert(&aio->dtree, &sdoc, 0)))
+ return 1;
sptr=(FT_SUPERDOC *)ELEMENT_KEY((&aio->dtree), selem);
- if(selem->count==1) /* document's first match */
+ if (selem->count==1) /* document's first match */
sptr->doc.weight=0;
else
sptr->doc.weight+=sptr->tmp_weight*sptr->word_ptr->weight;
@@ -144,31 +149,35 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
aio->info->lastkey_length, SEARCH_BIGGER,
aio->key_root);
}
- if(doc_cnt) {
+ if (doc_cnt)
+ {
word->weight*=GWS_IN_USE;
- if(word->weight < 0) word->weight=0;
+ if (word->weight < 0)
+ word->weight=0;
}
-
return 0;
}
+
static int walk_and_copy(FT_SUPERDOC *from,
uint32 count __attribute__((unused)), FT_DOC **to)
{
- from->doc.weight+=from->tmp_weight*from->word_ptr->weight;
- (*to)->dpos=from->doc.dpos;
- (*to)->weight=from->doc.weight;
- (*to)++;
- return 0;
+ from->doc.weight+=from->tmp_weight*from->word_ptr->weight;
+ (*to)->dpos=from->doc.dpos;
+ (*to)->weight=from->doc.weight;
+ (*to)++;
+ return 0;
}
+
static int FT_DOC_cmp(FT_DOC *a, FT_DOC *b)
{
- return sgn(b->weight - a->weight);
+ return sgn(b->weight - a->weight);
}
+
FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
- uint query_len, my_bool presort)
+ uint query_len, my_bool presort)
{
TREE allocated_wtree, *wtree=&allocated_wtree;
ALL_IN_ONE aio;
@@ -196,15 +205,16 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
NULL, NULL);
ft_parse_init(&allocated_wtree, aio.charset);
- if(ft_parse(&allocated_wtree,query,query_len))
+ if (ft_parse(&allocated_wtree,query,query_len))
goto err;
- if(tree_walk(wtree, (tree_walk_action)&walk_and_match, &aio,
- left_root_right))
+ if (tree_walk(wtree, (tree_walk_action)&walk_and_match, &aio,
+ left_root_right))
goto err2;
dlist=(FT_INFO *)my_malloc(sizeof(FT_INFO)+
- sizeof(FT_DOC)*(aio.dtree.elements_in_tree-1),MYF(0));
+ sizeof(FT_DOC)*(aio.dtree.elements_in_tree-1),
+ MYF(0));
if(!dlist)
goto err2;
@@ -214,10 +224,10 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
dlist->info=aio.info;
dptr=dlist->doc;
- tree_walk(&aio.dtree, (tree_walk_action)&walk_and_copy,
- &dptr, left_root_right);
+ tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy,
+ &dptr, left_root_right);
- if(presort)
+ if (presort)
qsort(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort_cmp)&FT_DOC_cmp);
err2:
@@ -229,6 +239,7 @@ err:
return dlist;
}
+
int ft_nlq_read_next(FT_INFO *handler, char *record)
{
MI_INFO *info= (MI_INFO *) handler->info;
@@ -250,6 +261,7 @@ int ft_nlq_read_next(FT_INFO *handler, char *record)
return my_errno;
}
+
float ft_nlq_find_relevance(FT_INFO *handler,
byte *record __attribute__((unused)),
uint length __attribute__((unused)))
@@ -276,16 +288,19 @@ float ft_nlq_find_relevance(FT_INFO *handler,
return 0.0;
}
+
void ft_nlq_close_search(FT_INFO *handler)
{
my_free((gptr)handler,MYF(0));
}
+
float ft_nlq_get_relevance(FT_INFO *handler)
{
return (float) handler->doc[handler->curdoc].weight;
}
+
void ft_nlq_reinit_search(FT_INFO *handler)
{
handler->curdoc=-1;
diff --git a/myisam/ft_test1.c b/myisam/ft_test1.c
index 6fa347f594a..cb0b6054f0a 100644
--- a/myisam/ft_test1.c
+++ b/myisam/ft_test1.c
@@ -205,7 +205,7 @@ void create_record(char *pos, int n)
{
uint tmp;
char *ptr;
- strncpy(blob_key,data[n].f0,keyinfo[0].seg[0].length);
+ strnmov(blob_key,data[n].f0,keyinfo[0].seg[0].length);
tmp=strlen(blob_key);
int4store(pos,tmp);
ptr=blob_key;
@@ -215,21 +215,21 @@ void create_record(char *pos, int n)
else if (recinfo[0].type == FIELD_VARCHAR)
{
uint tmp;
- strncpy(pos+2,data[n].f0,keyinfo[0].seg[0].length);
+ strnmov(pos+2,data[n].f0,keyinfo[0].seg[0].length);
tmp=strlen(pos+2);
int2store(pos,tmp);
pos+=recinfo[0].length;
}
else
{
- strncpy(pos,data[n].f0,keyinfo[0].seg[0].length);
+ strnmov(pos,data[n].f0,keyinfo[0].seg[0].length);
pos+=recinfo[0].length;
}
if (recinfo[1].type == FIELD_BLOB)
{
uint tmp;
char *ptr;
- strncpy(blob_key,data[n].f2,keyinfo[0].seg[0].length);
+ strnmov(blob_key,data[n].f2,keyinfo[0].seg[0].length);
tmp=strlen(blob_key);
int4store(pos,tmp);
ptr=blob_key;
@@ -239,14 +239,14 @@ void create_record(char *pos, int n)
else if (recinfo[1].type == FIELD_VARCHAR)
{
uint tmp;
- strncpy(pos+2,data[n].f2,keyinfo[0].seg[0].length);
+ strnmov(pos+2,data[n].f2,keyinfo[0].seg[0].length);
tmp=strlen(pos+2);
int2store(pos,tmp);
pos+=recinfo[1].length;
}
else
{
- strncpy(pos,data[n].f2,keyinfo[0].seg[0].length);
+ strnmov(pos,data[n].f2,keyinfo[0].seg[0].length);
pos+=recinfo[1].length;
}
}
diff --git a/myisam/ft_update.c b/myisam/ft_update.c
index b693950dc18..a68cc2a4cf4 100644
--- a/myisam/ft_update.c
+++ b/myisam/ft_update.c
@@ -29,7 +29,7 @@
/**************************************************************/
void _mi_ft_segiterator_init(MI_INFO *info, uint keynr, const byte *record,
- FT_SEG_ITERATOR *ftsi)
+ FT_SEG_ITERATOR *ftsi)
{
ftsi->num=info->s->keyinfo[keynr].keysegs-FT_SEGS;
ftsi->seg=info->s->keyinfo[keynr].seg;
@@ -37,7 +37,7 @@ void _mi_ft_segiterator_init(MI_INFO *info, uint keynr, const byte *record,
}
void _mi_ft_segiterator_dummy_init(const byte *record, uint len,
- FT_SEG_ITERATOR *ftsi)
+ FT_SEG_ITERATOR *ftsi)
{
ftsi->num=1;
ftsi->seg=0;
@@ -45,12 +45,13 @@ void _mi_ft_segiterator_dummy_init(const byte *record, uint len,
ftsi->len=len;
}
-/* This function breaks convention "return 0 in success"
- but it's easier to use like this
+/*
+ This function breaks convention "return 0 in success"
+ but it's easier to use like this
- while(_mi_ft_segiterator())
+ while(_mi_ft_segiterator())
- so "1" means "OK", "0" means "EOF"
+ so "1" means "OK", "0" means "EOF"
*/
uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi)
@@ -68,7 +69,7 @@ uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi)
if (ftsi->seg->flag & HA_VAR_LENGTH)
{
ftsi->len=uint2korr(ftsi->pos);
- ftsi->pos+=2; /* Skip VARCHAR length */
+ ftsi->pos+=2; /* Skip VARCHAR length */
set_if_smaller(ftsi->len,ftsi->seg->length);
return 1;
}
@@ -84,7 +85,9 @@ uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi)
return 1;
}
+
/* parses a document i.e. calls ft_parse for every keyseg */
+
uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, const byte *record)
{
FT_SEG_ITERATOR ftsi;
@@ -92,10 +95,11 @@ uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, const byte *record)
ft_parse_init(parsed, info->s->keyinfo[keynr].seg->charset);
while (_mi_ft_segiterator(&ftsi))
+ {
if (ftsi.pos)
if (ft_parse(parsed, (byte *)ftsi.pos, ftsi.len))
return 1;
-
+ }
return 0;
}
@@ -117,32 +121,33 @@ static int _mi_ft_store(MI_INFO *info, uint keynr, byte *keybuf,
{
uint key_length;
- while(wlist->pos)
+ for (; wlist->pos; wlist++)
{
key_length=_ft_make_key(info,keynr,keybuf,wlist,filepos);
if (_mi_ck_write(info,keynr,(uchar*) keybuf,key_length))
return 1;
- wlist++;
}
return 0;
}
-static int _mi_ft_erase(MI_INFO *info, uint keynr, byte *keybuf, FT_WORD *wlist, my_off_t filepos)
+static int _mi_ft_erase(MI_INFO *info, uint keynr, byte *keybuf,
+ FT_WORD *wlist, my_off_t filepos)
{
uint key_length, err=0;
- while(wlist->pos)
+ for (; wlist->pos; wlist++)
{
key_length=_ft_make_key(info,keynr,keybuf,wlist,filepos);
if (_mi_ck_delete(info,keynr,(uchar*) keybuf,key_length))
err=1;
- wlist++;
}
return err;
}
-/* compares an appropriate parts of two WORD_KEY keys directly out of records */
-/* returns 1 if they are different */
+/*
+ Compares an appropriate parts of two WORD_KEY keys directly out of records
+ returns 1 if they are different
+*/
#define THOSE_TWO_DAMN_KEYS_ARE_REALLY_DIFFERENT 1
#define GEE_THEY_ARE_ABSOLUTELY_IDENTICAL 0
@@ -154,7 +159,7 @@ int _mi_ft_cmp(MI_INFO *info, uint keynr, const byte *rec1, const byte *rec2)
_mi_ft_segiterator_init(info, keynr, rec1, &ftsi1);
_mi_ft_segiterator_init(info, keynr, rec2, &ftsi2);
- while(_mi_ft_segiterator(&ftsi1) && _mi_ft_segiterator(&ftsi2))
+ while (_mi_ft_segiterator(&ftsi1) && _mi_ft_segiterator(&ftsi2))
{
if ((ftsi1.pos != ftsi2.pos) &&
(!ftsi1.pos || !ftsi2.pos ||
@@ -165,7 +170,9 @@ int _mi_ft_cmp(MI_INFO *info, uint keynr, const byte *rec1, const byte *rec2)
return GEE_THEY_ARE_ABSOLUTELY_IDENTICAL;
}
+
/* update a document entry */
+
int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf,
const byte *oldrec, const byte *newrec, my_off_t pos)
{
@@ -215,7 +222,9 @@ err0:
return error;
}
+
/* adds a document to the collection */
+
int _mi_ft_add(MI_INFO *info, uint keynr, byte *keybuf, const byte *record,
my_off_t pos)
{
@@ -230,7 +239,9 @@ int _mi_ft_add(MI_INFO *info, uint keynr, byte *keybuf, const byte *record,
return error;
}
+
/* removes a document from the collection */
+
int _mi_ft_del(MI_INFO *info, uint keynr, byte *keybuf, const byte *record,
my_off_t pos)
{
diff --git a/myisam/mi_static.c b/myisam/mi_static.c
index 86d7fc38f25..37b9ac04b7a 100644
--- a/myisam/mi_static.c
+++ b/myisam/mi_static.c
@@ -42,8 +42,10 @@ my_off_t myisam_max_extra_temp_length= MI_MAX_TEMP_LENGTH;
my_off_t myisam_max_temp_length= MAX_FILE_SIZE;
ulong myisam_bulk_insert_tree_size=8192*1024;
-/* read_vec[] is used for converting between P_READ_KEY.. and SEARCH_ */
-/* Position is , == , >= , <= , > , < */
+/*
+ read_vec[] is used for converting between P_READ_KEY.. and SEARCH_
+ Position is , == , >= , <= , > , <
+*/
uint NEAR myisam_read_vec[]=
{
diff --git a/myisam/mi_test2.c b/myisam/mi_test2.c
index 81d00893d27..75129ac7667 100644
--- a/myisam/mi_test2.c
+++ b/myisam/mi_test2.c
@@ -341,13 +341,19 @@ int main(int argc, char *argv[])
}
}
}
- if (testflag==3) goto end;
+ if (testflag == 3)
+ goto end;
for (i=999, dupp_keys=j=0 ; i>0 ; i--)
{
- if (key1[i] > dupp_keys) { dupp_keys=key1[i]; j=i; }
+ if (key1[i] > dupp_keys)
+ {
+ dupp_keys=key1[i]; j=i;
+ }
}
sprintf(key,"%6d",j);
+ start=keyinfo[0].seg[0].start;
+ length=keyinfo[0].seg[0].length;
if (dupp_keys)
{
if (!silent)
@@ -355,8 +361,10 @@ int main(int argc, char *argv[])
DBUG_PRINT("progpos",("first - next -> last - prev -> first"));
if (verbose) printf(" Using key: \"%s\" Keys: %d\n",key,dupp_keys);
- if (mi_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT)) goto err;
- if (mi_rsame(file,read_record2,-1)) goto err;
+ if (mi_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT))
+ goto err;
+ if (mi_rsame(file,read_record2,-1))
+ goto err;
if (memcmp(read_record,read_record2,reclength) != 0)
{
printf("mi_rsame didn't find same record\n");
@@ -381,7 +389,6 @@ int main(int argc, char *argv[])
}
}
ant=1;
- start=keyinfo[0].seg[0].start; length=keyinfo[0].seg[0].length;
while (mi_rnext(file,read_record2,0) == 0 &&
memcmp(read_record2+start,key,length) == 0) ant++;
if (ant != dupp_keys)
diff --git a/myisam/mi_write.c b/myisam/mi_write.c
index 94b9c78707e..7398ec07ae2 100644
--- a/myisam/mi_write.c
+++ b/myisam/mi_write.c
@@ -103,7 +103,7 @@ int mi_write(MI_INFO *info, byte *record)
{
bool local_lock_tree= (lock_tree &&
!(info->bulk_insert &&
- is_tree_inited(& info->bulk_insert[i])));
+ is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree)
{
rw_wrlock(&share->key_root_lock[i]);
@@ -168,9 +168,9 @@ err:
uint j;
for (j=0 ; j < share->base.keys ; j++)
{
- if (is_tree_inited(& info->bulk_insert[j]))
+ if (is_tree_inited(&info->bulk_insert[j]))
{
- reset_tree(& info->bulk_insert[j]);
+ reset_tree(&info->bulk_insert[j]);
}
}
}
@@ -181,7 +181,7 @@ err:
{
bool local_lock_tree= (lock_tree &&
!(info->bulk_insert &&
- is_tree_inited(& info->bulk_insert[i])));
+ is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree)
rw_wrlock(&share->key_root_lock[i]);
if (share->keyinfo[i].flag & HA_FULLTEXT)
@@ -227,7 +227,7 @@ int _mi_ck_write(MI_INFO *info, uint keynr, uchar *key, uint key_length)
{
DBUG_ENTER("_mi_ck_write");
- if (info->bulk_insert && is_tree_inited(& info->bulk_insert[keynr]))
+ if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))
{
DBUG_RETURN(_mi_ck_write_tree(info, keynr, key, key_length));
}
@@ -750,7 +750,7 @@ int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
int error;
DBUG_ENTER("_mi_ck_write_tree");
- error= tree_insert(& info->bulk_insert[keynr], key,
+ error= tree_insert(&info->bulk_insert[keynr], key,
key_length + info->s->rec_reflength) ? 0 : HA_ERR_OUT_OF_MEM ;
DBUG_RETURN(error);