summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorserg@serg.mysql.com <>2000-11-02 17:36:21 +0100
committerserg@serg.mysql.com <>2000-11-02 17:36:21 +0100
commitff8df2c42bc453ca8d89e9461347f75b571d2fb5 (patch)
treec2c98089c936e8e55bca2409f12161c8224087c8 /sql
parenta896b8722b73f45e9d581a603c84bbcfe0d1b1cb (diff)
downloadmariadb-git-ff8df2c42bc453ca8d89e9461347f75b571d2fb5.tar.gz
Ill-minded FULLTEXT impilict initialization hack removed.
From now on FULLTEXT search is initialized expilictly in mysql_select()
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_myisam.cc30
-rw-r--r--sql/ha_myisam.h5
-rw-r--r--sql/handler.h6
-rw-r--r--sql/item_func.cc27
-rw-r--r--sql/item_func.h2
-rw-r--r--sql/opt_ft.h11
-rw-r--r--sql/opt_range.h2
-rw-r--r--sql/sql_select.cc31
8 files changed, 44 insertions, 70 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 7b1d274922d..76433a8eae5 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -353,7 +353,7 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
int error = 0;
const char* errmsg = "";
-
+
if (my_copy(src_path, fn_format(dst_path, table->path, "",
MI_NAME_DEXT, 4), MYF(MY_WME)))
{
@@ -361,11 +361,11 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
errmsg = "failed in my_copy( Error %d)";
goto err;
}
-
+
tmp_check_opt.init();
tmp_check_opt.quick = 1;
return repair(thd, &tmp_check_opt);
-
+
err:
{
MI_CHECK param;
@@ -375,7 +375,7 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
param.table_name = table->table_name;
param.testflag = 0;
mi_check_print_error(&param,errmsg, errno );
- return error;
+ return error;
}
}
@@ -450,7 +450,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
llstr(file->state->records, llbuff),
llstr(start_records, llbuff2),
table->path);
- }
+ }
return error;
}
@@ -496,7 +496,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
DBUG_RETURN(HA_ADMIN_FAILED);
}
- if (!optimize ||
+ if (!optimize ||
((file->state->del || share->state.split != file->state->records) &&
(!param.opt_rep_quick ||
!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))))
@@ -621,9 +621,9 @@ bool ha_myisam::check_and_repair(THD *thd)
{
sql_print_error("Warning: Recovering table: '%s'",table->path);
check_opt.quick= !check_opt.retry_without_quick && !marked_crashed;
- check_opt.flags=(((myisam_recover_options & HA_RECOVER_BACKUP) ?
+ check_opt.flags=(((myisam_recover_options & HA_RECOVER_BACKUP) ?
T_BACKUP_DATA : 0) |
- (!(myisam_recover_options & HA_RECOVER_FORCE) ?
+ (!(myisam_recover_options & HA_RECOVER_FORCE) ?
T_SAFE_REPAIR : 0)) | T_AUTO_REPAIR;
if (repair(thd, &check_opt))
error=1;
@@ -1079,20 +1079,6 @@ ha_rows ha_myisam::records_in_range(int inx,
end_search_flag);
}
-int ha_myisam::ft_init(uint inx, const byte *key, uint keylen, bool presort)
-{
- if (ft_handler)
- return -1;
-
- // Do the search!
- ft_handler=ft_init_search(file,inx,(byte*) key,keylen,presort);
-
- if (!ft_handler)
- return (my_errno ? my_errno : -1);
-
- return 0;
-}
-
int ha_myisam::ft_read(byte * buf)
{
int error;
diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h
index e0165d46920..d9f322fe9ca 100644
--- a/sql/ha_myisam.h
+++ b/sql/ha_myisam.h
@@ -71,8 +71,9 @@ class ha_myisam: public handler
int index_first(byte * buf);
int index_last(byte * buf);
int index_next_same(byte *buf, const byte *key, uint keylen);
- 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)
+ int ft_init()
+ { if(!ft_handler) return 1; ft_reinit_search(ft_handler); return 0; }
+ void *ft_init_ext(uint inx,const byte *key, uint keylen, bool presort)
{ return ft_init_search(file,inx,(byte*) key,keylen,presort); }
int ft_read(byte *buf);
int rnd_init(bool scan=1);
diff --git a/sql/handler.h b/sql/handler.h
index b7872ead98a..84c14538f4b 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -222,9 +222,9 @@ public:
virtual int index_first(byte * buf)=0;
virtual int index_last(byte * buf)=0;
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=1)
+ virtual int ft_init()
{ return -1; }
- virtual void *ft_init_ext(uint inx,const byte *key, uint keylen, bool presort=0)
+ virtual void *ft_init_ext(uint inx,const byte *key, uint keylen, bool presort)
{ return (void *)NULL; }
virtual int ft_read(byte *buf) { return -1; }
virtual int rnd_init(bool scan=1)=0;
@@ -257,7 +257,7 @@ public:
virtual int restore(THD* thd, HA_CHECK_OPT* check_opt);
// assumes .frm file must exist, and you must have already called
// generate_table() - it will just copy the data file and run repair
-
+
virtual int dump(THD* thd, int fd = -1) { return ER_DUMP_NOT_IMPLEMENTED; }
virtual void deactivate_non_unique_index(ha_rows rows) {}
virtual bool activate_all_index(THD *thd) {return 0;}
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 3ea7eadd238..39a4bee1366 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1840,9 +1840,6 @@ err:
double Item_func_match::val()
{
- if (first_call)
- init_search();
-
// Don't know how to return an error from val(), so NULL will be returned
if ((null_value=(ft_handler==NULL)))
return 0.0;
@@ -1853,8 +1850,7 @@ double Item_func_match::val()
}
else
{
- /* implicit initialization was done, so we'll have to find
- ft_relevance manually in ft_handler array */
+ /* we'll have to find ft_relevance manually in ft_handler array */
int a,b,c;
FT_DOC *docs=ft_handler->doc;
@@ -1881,9 +1877,8 @@ double Item_func_match::val()
void Item_func_match::init_search()
{
- if (!first_call)
+ if (ft_handler)
return;
- first_call=false;
if (master)
{
@@ -1893,20 +1888,19 @@ void Item_func_match::init_search()
return;
}
- if (join_key)
- {
- ft_handler=((FT_DOCLIST *)table->file->ft_handler);
- return;
- }
-
- /* join won't use this ft-key, but we must to init it anyway */
String *ft_tmp=0;
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());
+ table->file->ft_init_ext(key, (byte*) ft_tmp->ptr(), ft_tmp->length(), join_key);
+
+ if (join_key)
+ {
+ table->file->ft_handler=ft_handler;
+ return;
+ }
}
bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
@@ -1917,6 +1911,8 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
/* Why testing for const_item ? Monty */
/* I'll remove it later, but this should include modifications to
find_best and auto_close as complement to auto_init code above. SerG */
+ /* I'd rather say now that const_item is assumed in quite a bit of
+ places, so it would be difficult to remove. SerG */
if (Item_func::fix_fields(thd,tlist) || !const_item())
return 1;
@@ -1996,7 +1992,6 @@ bool Item_func_match::fix_index()
}
this->key=max_key;
- first_call=1;
maybe_null=1;
join_key=0;
diff --git a/sql/item_func.h b/sql/item_func.h
index 7b6d9acdcdc..9b696f75aa1 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -838,7 +838,7 @@ public:
List<Item> fields;
TABLE *table;
uint key;
- bool first_call, join_key;
+ bool join_key;
Item_func_match *master;
FT_DOCLIST *ft_handler;
diff --git a/sql/opt_ft.h b/sql/opt_ft.h
index 1c95a7cfea7..dcbbb8abcec 100644
--- a/sql/opt_ft.h
+++ b/sql/opt_ft.h
@@ -31,16 +31,7 @@ public:
FT_SELECT(TABLE *table, TABLE_REF *tref) :
QUICK_SELECT (table,tref->key,1), ref(tref) {}
- int init()
- {
-#if 0
- if (cp_buffer_from_ref(ref)) // as ft-key doesn't use store_key's
- return -1;
-#endif
- return error=file->ft_init(ref->key,
- ref->key_buff,
- ref->key_length);
- }
+ int init() { return error=file->ft_init(); }
int get_next() { return error=file->ft_read(record); }
};
diff --git a/sql/opt_range.h b/sql/opt_range.h
index 250c172a988..586c35f397f 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -71,7 +71,7 @@ public:
double read_time;
QUICK_SELECT(TABLE *table,uint index_arg,bool no_alloc=0);
- virtual ~QUICK_SELECT(); // fixed by Sasha needs to be virtual
+ virtual ~QUICK_SELECT();
void reset(void) { next=0; it.rewind(); }
virtual int init() { return 0; }
virtual int get_next();
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index d97a59cb898..7e7fed76877 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -486,7 +486,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
as in other cases the join is done before the sort.
*/
if ((order || group) && join.join_tab[join.const_tables].type != JT_ALL &&
- join.join_tab[join.const_tables].type != JT_FT && /* Beware! SerG */
+ join.join_tab[join.const_tables].type != JT_FT &&
(order && simple_order || group && simple_group))
{
if (add_ref_to_table_cond(thd,&join.join_tab[join.const_tables]))
@@ -522,6 +522,19 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
goto err;
}
+ /* Perform FULLTEXT search before all regular searches */
+ if (ftfuncs.elements)
+ {
+ List_iterator<Item_func_match> li(ftfuncs);
+ Item_func_match *ifm;
+ DBUG_PRINT("info",("Performing FULLTEXT search"));
+ thd->proc_info="FULLTEXT searching";
+
+ while ((ifm=li++))
+ {
+ ifm->init_search();
+ }
+ }
/* Create a tmp table if distinct or if the sort is too complicated */
if (need_tmp)
{
@@ -4438,26 +4451,14 @@ join_ft_read_first(JOIN_TAB *tab)
if (cp_buffer_from_ref(&tab->ref)) // as ft-key doesn't use store_key's
return -1; // see also FT_SELECT::init()
#endif
- if ((error=table->file->ft_init(tab->ref.key,
- tab->ref.key_buff,
- tab->ref.key_length)))
- {
- if (error != HA_ERR_KEY_NOT_FOUND)
- {
- sql_print_error("ft_read_first/init: Got error %d when reading table %s",error,
- table->path);
- table->file->print_error(error,MYF(0));
- return 1;
- }
- return -1;
- }
+ table->file->ft_init();
error=table->file->ft_read(table->record[0]);
if (error)
{
if (error != HA_ERR_END_OF_FILE)
{
- sql_print_error("ft_read_first/read: Got error %d when reading table %s",
+ sql_print_error("ft_read_first: Got error %d when reading table %s",
error, table->path);
table->file->print_error(error,MYF(0));
return 1;