Many MATCH'es per query now allowed (i.e. AND's and OR's now work, but

slow - full table scan); ORDER BY now works with MATCH (slow, full table
scan)
parent 8b865368
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -43,8 +43,9 @@ typedef struct st_ft_doclist { ...@@ -43,8 +43,9 @@ typedef struct st_ft_doclist {
int ft_init_stopwords(const char **); int ft_init_stopwords(const char **);
FT_DOCLIST * ft_init_search(void *, uint, byte *, uint, my_bool); FT_DOCLIST * ft_init_search(void *, uint, byte *, uint, my_bool);
double ft_read_next(FT_DOCLIST *, char *); int ft_read_next(FT_DOCLIST *, char *);
#define ft_close_search(handler) my_free(((gptr)(handler)),MYF(0)) #define ft_close_search(handler) my_free(((gptr)(handler)),MYF(0))
#define ft_get_relevance(handler) ((handler)->doc[(handler)->curdoc].weight)
#ifdef __cplusplus #ifdef __cplusplus
} }
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -82,7 +82,7 @@ int main(int argc,char *argv[]) ...@@ -82,7 +82,7 @@ int main(int argc,char *argv[])
if (!silent) if (!silent)
printf("- Reading rows with key\n"); 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; FT_DOCLIST *result; double w; int t,err;
result=ft_init_search(file,0,blob_record,(uint) strlen(blob_record),1); result=ft_init_search(file,0,blob_record,(uint) strlen(blob_record),1);
if(!result) { if(!result) {
...@@ -91,11 +91,12 @@ int main(int argc,char *argv[]) ...@@ -91,11 +91,12 @@ int main(int argc,char *argv[])
} }
if (!silent) if (!silent)
printf("Query %d. Found: %d.\n",i,result->ndocs); printf("Query %d. Found: %d.\n",i,result->ndocs);
for(j=0;(w=ft_read_next(result, read_record))>0;j++) { for(j=0;(err=ft_read_next(result, read_record))==0;j++) {
t=uint2korr(read_record); t=uint2korr(read_record);
w=ft_get_relevance(result);
printf("%d %.*s %f\n",i,t,read_record+2,w); printf("%d %.*s %f\n",i,t,read_record+2,w);
} }
if(w<0) { if(err != HA_ERR_KEY_NOT_FOUND) {
printf("ft_read_next %d failed with errno %3d\n",j,my_errno); printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
goto err; goto err;
} }
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -187,7 +187,7 @@ FT_DOCLIST * ft_init_search(void *info, uint keynr, byte *key, ...@@ -187,7 +187,7 @@ FT_DOCLIST * ft_init_search(void *info, uint keynr, byte *key,
goto err; goto err;
dlist->ndocs=aio.dtree.elements_in_tree; dlist->ndocs=aio.dtree.elements_in_tree;
dlist->curdoc=0; dlist->curdoc=-1;
dlist->info=aio.info; dlist->info=aio.info;
dptr=dlist->doc; dptr=dlist->doc;
...@@ -205,19 +205,19 @@ err: ...@@ -205,19 +205,19 @@ err:
return dlist; return dlist;
} }
double ft_read_next(FT_DOCLIST *handler, char *record) int ft_read_next(FT_DOCLIST *handler, char *record)
{ {
MI_INFO *info=handler->info; MI_INFO *info=handler->info;
if (handler->curdoc >= handler->ndocs) if (++handler->curdoc >= handler->ndocs)
return 0; return HA_ERR_END_OF_FILE;
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
if (!(*info->read_record)(info,handler->doc[handler->curdoc].dpos,record)) if (!(*info->read_record)(info,handler->doc[handler->curdoc].dpos,record))
{ {
info->update|= HA_STATE_AKTIV; /* Record is read */ info->update|= HA_STATE_AKTIV; /* Record is read */
return handler->doc[handler->curdoc++].weight; return 0;
} }
return -my_errno; return my_errno;
} }
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -145,15 +145,16 @@ static int run_test(const char *filename) ...@@ -145,15 +145,16 @@ static int run_test(const char *filename)
} }
printf("Query %d: `%s'. Found: %d. Top five documents:\n", printf("Query %d: `%s'. Found: %d. Top five documents:\n",
i,query[i],result->ndocs); i,query[i],result->ndocs);
for(j=0;j<5;j++) { double w; for(j=0;j<5;j++) { double w; int err;
w=ft_read_next(result, read_record); err=ft_read_next(result, read_record);
if(w<0) { if(err==HA_ERR_KEY_NOT_FOUND) {
printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
break;
} else if (w==0) {
printf("No more matches!\n"); printf("No more matches!\n");
break; break;
} else if (err) {
printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
break;
} }
w=ft_get_relevance(result);
if(key_field == FIELD_VARCHAR) { if(key_field == FIELD_VARCHAR) {
uint l; uint l;
char *p; char *p;
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -72,7 +72,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, ...@@ -72,7 +72,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
fprintf(stderr, fprintf(stderr,
"Failed on my_net_write, writing to stderr instead: %s\n", "Failed on my_net_write, writing to stderr instead: %s\n",
msgbuf); msgbuf);
return; return;
} }
extern "C" { extern "C" {
...@@ -134,7 +134,7 @@ int ha_myisam::net_read_dump(NET* net) ...@@ -134,7 +134,7 @@ int ha_myisam::net_read_dump(NET* net)
goto err; goto err;
} }
} }
err: err:
return error; return error;
} }
...@@ -186,7 +186,7 @@ int ha_myisam::dump(THD* thd, int fd) ...@@ -186,7 +186,7 @@ int ha_myisam::dump(THD* thd, int fd)
my_net_write(net, "", 0); my_net_write(net, "", 0);
net_flush(net); net_flush(net);
} }
err: err:
my_free((gptr) buf, MYF(0)); my_free((gptr) buf, MYF(0));
return error; return error;
...@@ -233,7 +233,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -233,7 +233,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
int error ; int error ;
MI_CHECK param; MI_CHECK param;
MYISAM_SHARE* share = file->s; MYISAM_SHARE* share = file->s;
myisamchk_init(&param); myisamchk_init(&param);
param.thd = thd; param.thd = thd;
param.op_name = (char*)"check"; param.op_name = (char*)"check";
...@@ -241,7 +241,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -241,7 +241,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
param.testflag = check_opt->flags | T_CHECK | T_SILENT; param.testflag = check_opt->flags | T_CHECK | T_SILENT;
if (check_opt->quick) if (check_opt->quick)
param.testflag |= T_FAST; param.testflag |= T_FAST;
if (!(table->db_stat & HA_READ_ONLY)) if (!(table->db_stat & HA_READ_ONLY))
param.testflag|= T_STATISTICS; param.testflag|= T_STATISTICS;
param.using_global_keycache = 1; param.using_global_keycache = 1;
...@@ -268,7 +268,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -268,7 +268,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
} }
} }
if (!error) if (!error)
{ {
if (share->state.changed) if (share->state.changed)
{ {
file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
...@@ -290,7 +290,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -290,7 +290,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
mi_mark_crashed(file); mi_mark_crashed(file);
file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
} }
return error ? HA_CHECK_CORRUPT : HA_CHECK_OK; return error ? HA_CHECK_CORRUPT : HA_CHECK_OK;
} }
...@@ -306,7 +306,7 @@ int ha_myisam::analyze(THD *thd) ...@@ -306,7 +306,7 @@ int ha_myisam::analyze(THD *thd)
int error; int error;
MI_CHECK param; MI_CHECK param;
MYISAM_SHARE* share = file->s; MYISAM_SHARE* share = file->s;
myisamchk_init(&param); myisamchk_init(&param);
param.thd = thd; param.thd = thd;
param.op_name = (char*)" analyze"; param.op_name = (char*)" analyze";
...@@ -317,7 +317,7 @@ int ha_myisam::analyze(THD *thd) ...@@ -317,7 +317,7 @@ int ha_myisam::analyze(THD *thd)
error = chk_key(&param, file); error = chk_key(&param, file);
if (!error) if (!error)
{ {
pthread_mutex_lock(&share->intern_lock); pthread_mutex_lock(&share->intern_lock);
#ifndef HAVE_PREAD #ifndef HAVE_PREAD
pthread_mutex_lock(&THR_LOCK_keycache); // QQ; Has to be removed! pthread_mutex_lock(&THR_LOCK_keycache); // QQ; Has to be removed!
...@@ -345,7 +345,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) ...@@ -345,7 +345,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
param.op_name = (char*) "repair"; param.op_name = (char*) "repair";
param.testflag = (check_opt->flags | T_SILENT|T_FORCE_CREATE|T_REP_BY_SORT| param.testflag = (check_opt->flags | T_SILENT|T_FORCE_CREATE|T_REP_BY_SORT|
T_STATISTICS); T_STATISTICS);
if (check_opt->quick) if (check_opt->quick)
param.opt_rep_quick++; param.opt_rep_quick++;
param.sort_buffer_length= check_opt->sort_buffer_size; param.sort_buffer_length= check_opt->sort_buffer_size;
return repair(thd,param); return repair(thd,param);
...@@ -365,11 +365,11 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param) ...@@ -365,11 +365,11 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param)
VOID(fn_format(fixed_name,file->filename,"",MI_NAME_IEXT, VOID(fn_format(fixed_name,file->filename,"",MI_NAME_IEXT,
4+ (param.opt_follow_links ? 16 : 0))); 4+ (param.opt_follow_links ? 16 : 0)));
if (mi_test_if_sort_rep(file,file->state->records)) if (mi_test_if_sort_rep(file,file->state->records))
error = mi_repair_by_sort(&param, file, fixed_name, param.opt_rep_quick); error = mi_repair_by_sort(&param, file, fixed_name, param.opt_rep_quick);
else else
error= mi_repair(&param, file, fixed_name, param.opt_rep_quick); error= mi_repair(&param, file, fixed_name, param.opt_rep_quick);
if (!error) if (!error)
{ {
if (share->state.changed) if (share->state.changed)
{ {
share->state.changed = 0; share->state.changed = 0;
...@@ -400,7 +400,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param) ...@@ -400,7 +400,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param)
if (param.out_flag & O_NEW_DATA) if (param.out_flag & O_NEW_DATA)
error|=change_to_newfile(fixed_name,MI_NAME_DEXT, error|=change_to_newfile(fixed_name,MI_NAME_DEXT,
DATA_TMP_EXT, 0); DATA_TMP_EXT, 0);
if (param.out_flag & O_NEW_INDEX) if (param.out_flag & O_NEW_INDEX)
error|=change_to_newfile(fixed_name,MI_NAME_IEXT, error|=change_to_newfile(fixed_name,MI_NAME_IEXT,
INDEX_TMP_EXT,0); INDEX_TMP_EXT,0);
...@@ -433,7 +433,7 @@ bool ha_myisam::activate_all_index(THD *thd) ...@@ -433,7 +433,7 @@ bool ha_myisam::activate_all_index(THD *thd)
thd->proc_info="creating index"; thd->proc_info="creating index";
myisamchk_init(&param); myisamchk_init(&param);
param.op_name = (char*) "recreating_index"; param.op_name = (char*) "recreating_index";
param.testflag = (T_SILENT | T_REP_BY_SORT | param.testflag = (T_SILENT | T_REP_BY_SORT |
T_STATISTICS | T_CREATE_MISSING_KEYS | T_TRUST_HEADER); T_STATISTICS | T_CREATE_MISSING_KEYS | T_TRUST_HEADER);
param.myf_rw&= ~MY_WAIT_IF_FULL; param.myf_rw&= ~MY_WAIT_IF_FULL;
param.sort_buffer_length= myisam_sort_buffer_size; param.sort_buffer_length= myisam_sort_buffer_size;
...@@ -491,7 +491,7 @@ int ha_myisam::index_prev(byte * buf) ...@@ -491,7 +491,7 @@ int ha_myisam::index_prev(byte * buf)
table->status=error ? STATUS_NOT_FOUND: 0; table->status=error ? STATUS_NOT_FOUND: 0;
return error; return error;
} }
int ha_myisam::index_first(byte * buf) int ha_myisam::index_first(byte * buf)
{ {
statistic_increment(ha_read_first_count,&LOCK_status); statistic_increment(ha_read_first_count,&LOCK_status);
...@@ -626,7 +626,7 @@ int ha_myisam::delete_table(const char *name) ...@@ -626,7 +626,7 @@ int ha_myisam::delete_table(const char *name)
int ha_myisam::external_lock(THD *thd, int lock_type) int ha_myisam::external_lock(THD *thd, int lock_type)
{ {
return mi_lock_database(file,lock_type); return mi_lock_database(file,lock_type);
} }
THR_LOCK_DATA **ha_myisam::store_lock(THD *thd, THR_LOCK_DATA **ha_myisam::store_lock(THD *thd,
...@@ -833,8 +833,8 @@ int ha_myisam::create(const char *name, register TABLE *form, ...@@ -833,8 +833,8 @@ int ha_myisam::create(const char *name, register TABLE *form,
((options & HA_OPTION_CHECKSUM) ? HA_CREATE_CHECKSUM : 0) | ((options & HA_OPTION_CHECKSUM) ? HA_CREATE_CHECKSUM : 0) |
((options & HA_OPTION_DELAY_KEY_WRITE) ? ((options & HA_OPTION_DELAY_KEY_WRITE) ?
HA_CREATE_DELAY_KEY_WRITE : 0))); HA_CREATE_DELAY_KEY_WRITE : 0)));
my_free((gptr) recinfo,MYF(0)); my_free((gptr) recinfo,MYF(0));
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -904,15 +904,13 @@ int ha_myisam::ft_read(byte * buf) ...@@ -904,15 +904,13 @@ int ha_myisam::ft_read(byte * buf)
{ {
int error; int error;
if (!ft_handler)
return -1;
thread_safe_increment(ha_read_next_count,&LOCK_status); // why ? thread_safe_increment(ha_read_next_count,&LOCK_status); // why ?
if (ft_handler)
ft_relevance=ft_read_next((FT_DOCLIST *) ft_handler,(char*) buf);
else
ft_relevance=0;
error=((ft_relevance == 0) ? HA_ERR_END_OF_FILE : error=ft_read_next((FT_DOCLIST *) ft_handler,(char*) buf);
(ft_relevance > 0) ? 0 :
(int) -ft_relevance);
table->status=error ? STATUS_NOT_FOUND: 0; table->status=error ? STATUS_NOT_FOUND: 0;
return error; return error;
} }
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -37,10 +37,10 @@ class ha_myisam: public handler ...@@ -37,10 +37,10 @@ class ha_myisam: public handler
int_option_flag(HA_READ_NEXT+HA_READ_PREV+HA_READ_RND_SAME+ int_option_flag(HA_READ_NEXT+HA_READ_PREV+HA_READ_RND_SAME+
HA_KEYPOS_TO_RNDPOS+ HA_READ_ORDER+ HA_LASTKEY_ORDER+ HA_KEYPOS_TO_RNDPOS+ HA_READ_ORDER+ HA_LASTKEY_ORDER+
HA_HAVE_KEY_READ_ONLY+ HA_READ_NOT_EXACT_KEY+ HA_HAVE_KEY_READ_ONLY+ HA_READ_NOT_EXACT_KEY+
HA_LONGLONG_KEYS+ HA_NULL_KEY + HA_LONGLONG_KEYS+ HA_NULL_KEY +
HA_DUPP_POS + HA_BLOB_KEY + HA_AUTO_PART_KEY) HA_DUPP_POS + HA_BLOB_KEY + HA_AUTO_PART_KEY)
{} {}
~ha_myisam() { ft_close(); } ~ha_myisam() {}
const char *table_type() const { return "MyISAM"; } const char *table_type() const { return "MyISAM"; }
const char **bas_ext() const; const char **bas_ext() const;
ulong option_flag() const { return int_option_flag; } ulong option_flag() const { return int_option_flag; }
...@@ -63,9 +63,10 @@ class ha_myisam: public handler ...@@ -63,9 +63,10 @@ class ha_myisam: public handler
int index_first(byte * buf); int index_first(byte * buf);
int index_last(byte * buf); int index_last(byte * buf);
int index_next_same(byte *buf, const byte *key, uint keylen); int index_next_same(byte *buf, const byte *key, uint keylen);
int ft_init(uint inx,const byte *key, uint keylen, bool presort); int ft_init(uint inx,const byte *key, uint keylen, bool presort=1);
void *ft_init_ext(uint inx,const byte *key, uint keylen, bool presort=0)
{ return ft_init_search(file,inx,(byte*) key,keylen,presort); }
int ft_read(byte *buf); int ft_read(byte *buf);
int ft_close() { if(ft_handler) ft_close_search(ft_handler); ft_handler=0; return 0;}
int rnd_init(bool scan=1); int rnd_init(bool scan=1);
int rnd_next(byte *buf); int rnd_next(byte *buf);
int rnd_pos(byte * buf, byte *pos); int rnd_pos(byte * buf, byte *pos);
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -189,7 +189,6 @@ public: ...@@ -189,7 +189,6 @@ public:
time_t check_time; time_t check_time;
time_t update_time; time_t update_time;
ulong mean_rec_length; /* physical reclength */ ulong mean_rec_length; /* physical reclength */
double ft_relevance;
void *ft_handler; void *ft_handler;
handler(TABLE *table_arg) : table(table_arg),active_index(MAX_REF_PARTS), handler(TABLE *table_arg) : table(table_arg),active_index(MAX_REF_PARTS),
...@@ -198,7 +197,7 @@ public: ...@@ -198,7 +197,7 @@ public:
delete_length(0), auto_increment_value(0), raid_type(0), delete_length(0), auto_increment_value(0), raid_type(0),
key_used_on_scan(MAX_KEY), key_used_on_scan(MAX_KEY),
create_time(0), check_time(0), update_time(0), mean_rec_length(0), create_time(0), check_time(0), update_time(0), mean_rec_length(0),
ft_relevance(0.0), ft_handler(0) ft_handler(0)
{} {}
virtual ~handler(void) { my_free((char*) ref,MYF(MY_ALLOW_ZERO_PTR)); } virtual ~handler(void) { my_free((char*) ref,MYF(MY_ALLOW_ZERO_PTR)); }
int ha_open(const char *name, int mode, int test_if_locked); int ha_open(const char *name, int mode, int test_if_locked);
...@@ -231,10 +230,11 @@ public: ...@@ -231,10 +230,11 @@ public:
virtual int index_first(byte * buf)=0; virtual int index_first(byte * buf)=0;
virtual int index_last(byte * buf)=0; virtual int index_last(byte * buf)=0;
virtual int index_next_same(byte *buf, const byte *key, uint keylen); virtual int index_next_same(byte *buf, const byte *key, uint keylen);
virtual int ft_init(uint inx,const byte *key, uint keylen, bool presort) virtual int ft_init(uint inx,const byte *key, uint keylen, bool presort=1)
{ return -1; } { return -1; }
virtual void *ft_init_ext(uint inx,const byte *key, uint keylen, bool presort=0)
{ return (void *)NULL; }
virtual int ft_read(byte *buf) { return -1; } virtual int ft_read(byte *buf) { return -1; }
virtual int ft_close() { return -1; }
virtual int rnd_init(bool scan=1)=0; virtual int rnd_init(bool scan=1)=0;
virtual int rnd_end() { return 0; } virtual int rnd_end() { return 0; }
virtual int rnd_next(byte *buf)=0; virtual int rnd_next(byte *buf)=0;
...@@ -266,7 +266,7 @@ public: ...@@ -266,7 +266,7 @@ public:
// not implemented by default // not implemented by default
virtual int net_read_dump(NET* net) virtual int net_read_dump(NET* net)
{ return ER_DUMP_NOT_IMPLEMENTED; } { return ER_DUMP_NOT_IMPLEMENTED; }
/* The following can be called without an open handler */ /* The following can be called without an open handler */
virtual const char *table_type() const =0; virtual const char *table_type() const =0;
virtual const char **bas_ext() const =0; virtual const char **bas_ext() const =0;
......
...@@ -1837,43 +1837,49 @@ err: ...@@ -1837,43 +1837,49 @@ err:
double Item_func_match::val() double Item_func_match::val()
{ {
int a,b,c; my_off_t docid=table->file->row_position(); // HAVE to do it here...
FT_DOC *docs;
my_off_t docid;
docid = table->file->row_position(); // HAVE to do it here... if (first_call)
if (table->file->ft_handler==NULL && !auto_init_was_done)
{ {
/* join won't use this ft-key, but we must to init it anyway */ if (join_key=(table->file->get_index() == key &&
String *ft_tmp=0; (ft_handler=(FT_DOCLIST *)table->file->ft_handler)))
char tmp1[FT_QUERY_MAXLEN]; ;
String tmp2(tmp1,sizeof(tmp1)); else
{
ft_tmp=key_item()->val_str(&tmp2); /* join won't use this ft-key, but we must to init it anyway */
table->file->ft_init(key, (byte*) ft_tmp->ptr(), ft_tmp->length(), FALSE); String *ft_tmp=0;
auto_init_was_done=1; char tmp1[FT_QUERY_MAXLEN];
String tmp2(tmp1,sizeof(tmp1));
ft_tmp=key_item()->val_str(&tmp2);
ft_handler=(FT_DOCLIST *)
table->file->ft_init_ext(key, (byte*) ft_tmp->ptr(), ft_tmp->length());
}
first_call=0;
} }
// Don't know how to return an error from val(), so NULL will be returned // Don't know how to return an error from val(), so NULL will be returned
if ((null_value=(table->file->ft_handler==NULL))) if ((null_value=(ft_handler==NULL)))
return 0.0; return 0.0;
if (auto_init_was_done) if (join_key)
{ {
/* implicit initialization was done, so nobody will set proper return ft_get_relevance(ft_handler);
ft_relevance for us. We'll look for it in ft_handler array */ }
else
{
/* implicit initialization was done, so we'll have to find
ft_relevance manually in ft_handler array */
docs = ((FT_DOCLIST *)table->file->ft_handler)->doc; int a,b,c;
// docid = table->file->row_position(); FT_DOC *docs=ft_handler->doc;
if ((null_value=(docid==HA_OFFSET_ERROR))) if ((null_value=(docid==HA_OFFSET_ERROR)))
return 0.0; return 0.0;
// Assuming docs[] is sorted by dpos... // Assuming docs[] is sorted by dpos...
a=0, b=((FT_DOCLIST *)table->file->ft_handler)->ndocs; for (a=0, b=ft_handler->ndocs, c=(a+b)/2; b-a>1; c=(a+b)/2)
for (c=(a+b)/2; b-a>1; c=(a+b)/2)
{ {
if (docs[c].dpos > docid) if (docs[c].dpos > docid)
b=c; b=c;
...@@ -1881,12 +1887,10 @@ double Item_func_match::val() ...@@ -1881,12 +1887,10 @@ double Item_func_match::val()
a=c; a=c;
} }
if (docs[a].dpos == docid) if (docs[a].dpos == docid)
table->file->ft_relevance=docs[a].weight; return docs[a].weight;
else else
table->file->ft_relevance=0; return 0.0;
} }
return table->file->ft_relevance;
} }
bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist) bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
...@@ -1912,8 +1916,6 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist) ...@@ -1912,8 +1916,6 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
return 1; return 1;
const_item_cache=0; const_item_cache=0;
table=((Item_field *)fields.head())->field->table; table=((Item_field *)fields.head())->field->table;
auto_init_was_done=0;
table->file->ft_close(); // It's a bad solution to do it here, I know :-(
return 0; return 0;
} }
...@@ -1978,7 +1980,7 @@ bool Item_func_match::fix_index() ...@@ -1978,7 +1980,7 @@ bool Item_func_match::fix_index()
} }
this->key=max_key; this->key=max_key;
first_call=1;
maybe_null=1; maybe_null=1;
return 0; return 0;
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
...@@ -817,7 +817,7 @@ public: ...@@ -817,7 +817,7 @@ public:
void fix_length_and_dec(); void fix_length_and_dec();
enum Item_result result_type() const; enum Item_result result_type() const;
const char *func_name() const { return "get_user_var"; } const char *func_name() const { return "get_user_var"; }
}; };
class Item_func_inet_aton : public Item_int_func class Item_func_inet_aton : public Item_int_func
{ {
...@@ -830,22 +830,23 @@ public: ...@@ -830,22 +830,23 @@ public:
/* SerG: for fulltext search */ /* SerG: for fulltext search */
#include <ft_global.h>
class Item_func_match :public Item_real_func class Item_func_match :public Item_real_func
{ {
public: public:
// handler *File;
List<Item> fields; List<Item> fields;
TABLE *table; TABLE *table;
uint key; uint key;
bool auto_init_was_done; bool first_call, join_key;
FT_DOCLIST *ft_handler;
Item_func_match(List<Item> &a, Item *b): Item_real_func(b), Item_func_match(List<Item> &a, Item *b): Item_real_func(b),
fields(a), table(0) fields(a), table(0), ft_handler(0)
{} {}
~Item_func_match() {} ~Item_func_match() { ft_close_search(ft_handler);
if(join_key) table->file->ft_handler=0; }
const char *func_name() const { return "match"; } const char *func_name() const { return "match"; }
//optimize_type select_optimize() const { return OPTIMIZE_FT; }
enum Functype functype() const { return FT_FUNC; } enum Functype functype() const { return FT_FUNC; }
void update_used_tables() {} void update_used_tables() {}
bool fix_fields(THD *thd,struct st_table_list *tlist); bool fix_fields(THD *thd,struct st_table_list *tlist);
......
...@@ -476,6 +476,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds, ...@@ -476,6 +476,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
as in other cases the join is done before the sort. as in other cases the join is done before the sort.
*/ */
if ((order || group) && join.join_tab[join.const_tables].type != JT_ALL && if ((order || group) && join.join_tab[join.const_tables].type != JT_ALL &&
join.join_tab[join.const_tables].type != JT_FT && /* Beware! SerG */
(order && simple_order || group && simple_group)) (order && simple_order || group && simple_group))
{ {
if (add_ref_to_table_cond(thd,&join.join_tab[join.const_tables])) if (add_ref_to_table_cond(thd,&join.join_tab[join.const_tables]))
...@@ -4281,7 +4282,7 @@ join_ft_read_first(JOIN_TAB *tab) ...@@ -4281,7 +4282,7 @@ join_ft_read_first(JOIN_TAB *tab)
#endif #endif
if ((error=table->file->ft_init(tab->ref.key, if ((error=table->file->ft_init(tab->ref.key,
tab->ref.key_buff, tab->ref.key_buff,
tab->ref.key_length,TRUE))) tab->ref.key_length)))
{ {
if (error != HA_ERR_KEY_NOT_FOUND) if (error != HA_ERR_KEY_NOT_FOUND)
{ {
...@@ -4303,7 +4304,6 @@ join_ft_read_first(JOIN_TAB *tab) ...@@ -4303,7 +4304,6 @@ join_ft_read_first(JOIN_TAB *tab)
table->file->print_error(error,MYF(0)); table->file->print_error(error,MYF(0));
return 1; return 1;
} }
table->file->ft_close();
return -1; return -1;
} }
return 0; return 0;
...@@ -4322,7 +4322,6 @@ join_ft_read_next(READ_RECORD *info) ...@@ -4322,7 +4322,6 @@ join_ft_read_next(READ_RECORD *info)
info->file->print_error(error,MYF(0)); info->file->print_error(error,MYF(0));
return 1; return 1;
} }
info->file->ft_close();
return -1; return -1;
} }
return 0; return 0;
...@@ -4974,6 +4973,7 @@ create_sort_index(JOIN_TAB *tab,ORDER *order,ha_rows select_limit) ...@@ -4974,6 +4973,7 @@ create_sort_index(JOIN_TAB *tab,ORDER *order,ha_rows select_limit)
} }
} }
else else
if (tab->type != JT_FT) /* Beware! SerG */
{ {
/* /*
We have a ref on a const; Change this to a range that filesort We have a ref on a const; Change this to a range that filesort
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment