sql_select.cc ft-optimization: AND, GT/LT/GE/LE

sql_select.cc	EXPLAIN fulltext
Makefile.am	CLEANFILES corrected
sql_show.cc	SHOW CREATE now displays FULLTEXT keys properly
parent 23385734
......@@ -46,7 +46,7 @@ libmyisam_a_SOURCES = mi_open.c mi_extra.c mi_info.c mi_rkey.c \
mi_delete_table.c mi_rename.c mi_check.c mi_debug.c \
ft_parser.c ft_search.c ft_stopwords.c ft_static.c \
ft_update.c sort.c
CLEANFILES = test?.IS? isam.log mi_test_all
CLEANFILES = test?.MY? FT?.MY? isam.log mi_test_all
DEFS = -DMAP_TO_USE_RAID
# Omit dependency for ../mit-pthreads/include/sys that only exits if
# mit-pthreads are used
......
......@@ -29,7 +29,7 @@
#include <assert.h>
const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
"MAYBE_REF","ALL","range","index" };
"MAYBE_REF","ALL","range","index","fulltext" };
static bool make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds,
DYNAMIC_ARRAY *keyuse,List<Item_func_match> &ftfuncs);
......@@ -1280,15 +1280,54 @@ static void
add_ft_keys(DYNAMIC_ARRAY *keyuse_array,
JOIN_TAB *stat,COND *cond,table_map usable_tables)
{
/* for now, handling only the simples WHERE MATCH (...) case */
/* a bit more complex WHERE MATCH (...) > const,
AND's and (perhaps) OR's are on the way SerG */
Item_func_match *cond_func=NULL;
if (cond->type() == Item::FUNC_ITEM)
{
Item_func *func=(Item_func *)cond,
*arg0=(Item_func *)(func->arguments()[0]),
*arg1=(Item_func *)(func->arguments()[1]);
if (func->functype() == Item_func::FT_FUNC)
cond_func=(Item_func_match *)cond;
else if (arg0->type() == Item::FUNC_ITEM &&
arg0->functype() == Item_func::FT_FUNC &&
(func->functype() == Item_func::GE_FUNC ||
func->functype() == Item_func::GT_FUNC) &&
arg1->const_item() && arg1->val()>=0)
cond_func=(Item_func_match *)arg0;
else if (arg1->type() == Item::FUNC_ITEM &&
arg1->functype() == Item_func::FT_FUNC &&
(func->functype() == Item_func::LE_FUNC ||
func->functype() == Item_func::LT_FUNC) &&
arg0->const_item() && arg0->val()>=0)
cond_func=(Item_func_match *)arg1;
}
else if (cond->type() == Item::COND_ITEM)
{
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
if (cond->type() != Item::FUNC_ITEM ||
((Item_func*) cond)->functype() != Item_func::FT_FUNC)
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
{
Item *item;
/* I'm too lazy to implement proper recursive descent here,
and anyway, nobody will use such a stupid queries
that will require it :-)
May be later...
*/
while ((item=li++))
if (item->type() == Item::FUNC_ITEM &&
((Item_func *)item)->functype() == Item_func::FT_FUNC)
{
cond_func=(Item_func_match *)item;
break;
}
}
}
if(!cond_func)
return;
Item_func_match *cond_func= (Item_func_match *) cond;
KEYUSE keyuse;
keyuse.table= cond_func->table;
......@@ -1936,8 +1975,7 @@ get_best_combination(JOIN *join)
if (ftkey)
{
j->ref.items[0]=((Item_func*)(keyuse->val))->key_item();
if (!keyuse->used_tables &&
!(join->select_options & SELECT_DESCRIBE))
if (!keyuse->used_tables)
{
// AFAIK key_buff is zeroed...
// We don't need to free ft_tmp as the buffer will be freed atom.
......
......@@ -744,6 +744,8 @@ store_create_info(THD *thd, TABLE *table, String* packet)
packet->append("primary", 7);
else if(key_info->flags & HA_NOSAME)
packet->append("unique", 6);
else if(key_info->flags & HA_FULLTEXT)
packet->append("fulltext", 8);
packet->append(" key ", 5);
if(i != primary_key)
......@@ -761,8 +763,9 @@ store_create_info(THD *thd, TABLE *table, String* packet)
KEY *key=table->key_info+i;
if (!key_part->field ||
key_part->length !=
table->field[key_part->fieldnr-1]->key_length())
(key_part->length !=
table->field[key_part->fieldnr-1]->key_length() &&
!(key_info->flags & HA_FULLTEXT)))
{
char buff[64];
buff[0] = '(';
......
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