Commit 9e29bb4e authored by unknown's avatar unknown

ft boolean search by table scan; queue_fix()


include/queues.h:
  queue_fix() introduced
myisam/ft_boolean_search.c:
  ft boolean search by table scan
myisam/ft_parser.c:
  ft boolean search by table scan
myisam/ft_update.c:
  ft boolean search by table scan
myisam/ftdefs.h:
  ft boolean search by table scan
mysql-test/r/fulltext_cache.result:
  ft boolean search by table scan
mysql-test/t/fulltext_cache.test:
  ft boolean search by table scan
mysys/queues.c:
  queue_fix() introduced
parent 36a4cc17
...@@ -53,6 +53,7 @@ void delete_queue(QUEUE *queue); ...@@ -53,6 +53,7 @@ void delete_queue(QUEUE *queue);
void queue_insert(QUEUE *queue,byte *element); void queue_insert(QUEUE *queue,byte *element);
byte *queue_remove(QUEUE *queue,uint idx); byte *queue_remove(QUEUE *queue,uint idx);
void _downheap(QUEUE *queue,uint idx); void _downheap(QUEUE *queue,uint idx);
void queue_fix(QUEUE *queue);
#define is_queue_inited(queue) ((queue)->root != 0) #define is_queue_inited(queue) ((queue)->root != 0)
#ifdef __cplusplus #ifdef __cplusplus
......
This diff is collapsed.
...@@ -33,17 +33,16 @@ typedef struct st_ft_docstat { ...@@ -33,17 +33,16 @@ typedef struct st_ft_docstat {
double max, nsum, nsum2; double max, nsum, nsum2;
#endif /* EVAL_RUN */ #endif /* EVAL_RUN */
MI_INFO *info; // MI_INFO *info;
uint keynr; // uint keynr;
byte *keybuf; // byte *keybuf;
} FT_DOCSTAT; } FT_DOCSTAT;
static int FT_WORD_cmp(void* cmp_arg __attribute__((unused)), static int FT_WORD_cmp(void* cmp_arg, FT_WORD *w1, FT_WORD *w2)
FT_WORD *w1, FT_WORD *w2)
{ {
return _mi_compare_text(default_charset_info, return _mi_compare_text(default_charset_info,
(uchar*) w1->pos,w1->len, (uchar*) w1->pos,w1->len,
(uchar*) w2->pos, w2->len,0); (uchar*) w2->pos, w2->len,(my_bool)cmp_arg);
} }
static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat) static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat)
...@@ -64,7 +63,9 @@ static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat) ...@@ -64,7 +63,9 @@ static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat)
/* transforms tree of words into the array, applying normalization */ /* transforms tree of words into the array, applying normalization */
FT_WORD * ft_linearize(MI_INFO *info, uint keynr, byte *keybuf, TREE *wtree) FT_WORD * ft_linearize(//MI_INFO *info, uint keynr,
//byte *keybuf,
TREE *wtree)
{ {
FT_WORD *wlist,*p; FT_WORD *wlist,*p;
FT_DOCSTAT docstat; FT_DOCSTAT docstat;
...@@ -73,9 +74,9 @@ FT_WORD * ft_linearize(MI_INFO *info, uint keynr, byte *keybuf, TREE *wtree) ...@@ -73,9 +74,9 @@ FT_WORD * ft_linearize(MI_INFO *info, uint keynr, byte *keybuf, TREE *wtree)
if ((wlist=(FT_WORD *) my_malloc(sizeof(FT_WORD)* if ((wlist=(FT_WORD *) my_malloc(sizeof(FT_WORD)*
(1+wtree->elements_in_tree),MYF(0)))) (1+wtree->elements_in_tree),MYF(0))))
{ {
docstat.info=info; // docstat.info=info;
docstat.keynr=keynr; // docstat.keynr=keynr;
docstat.keybuf=keybuf; // docstat.keybuf=keybuf;
docstat.list=wlist; docstat.list=wlist;
docstat.uniq=wtree->elements_in_tree; docstat.uniq=wtree->elements_in_tree;
#ifdef EVAL_RUN #ifdef EVAL_RUN
...@@ -207,19 +208,6 @@ byte ft_simple_get_word(byte **start, byte *end, FT_WORD *word) ...@@ -207,19 +208,6 @@ byte ft_simple_get_word(byte **start, byte *end, FT_WORD *word)
return 0; return 0;
} }
int is_boolean(byte *q, uint len)
{
if (!len) return 0;
if (*q == FTB_YES || *q == FTB_NO) return 1;
for (++q; --len; ++q)
{
if ((*q == FTB_YES || *q == FTB_NO) && q[-1] == ' ' && true_word_char(q[1]))
return 1;
}
return 0;
}
TREE * ft_parse(TREE *wtree, byte *doc, int doclen) TREE * ft_parse(TREE *wtree, byte *doc, int doclen)
{ {
byte *end=doc+doclen; byte *end=doc+doclen;
......
...@@ -29,17 +29,12 @@ ...@@ -29,17 +29,12 @@
/* parses a document i.e. calls _mi_ft_parse for every keyseg */ /* parses a document i.e. calls _mi_ft_parse for every keyseg */
FT_WORD * _mi_ft_parserecord(MI_INFO *info, uint keynr, byte *keybuf, uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, const byte *record)
const byte *record)
{ {
TREE *parsed, ptree;
MI_KEYSEG *keyseg;
byte *pos; byte *pos;
uint i; uint i;
MI_KEYSEG *keyseg=info->s->keyinfo[keynr].seg;
bzero(parsed=&ptree, sizeof(ptree));
keyseg=info->s->keyinfo[keynr].seg;
for (i=info->s->keyinfo[keynr].keysegs-FT_SEGS ; i-- ; ) for (i=info->s->keyinfo[keynr].keysegs-FT_SEGS ; i-- ; )
{ {
uint len; uint len;
...@@ -62,13 +57,26 @@ FT_WORD * _mi_ft_parserecord(MI_INFO *info, uint keynr, byte *keybuf, ...@@ -62,13 +57,26 @@ FT_WORD * _mi_ft_parserecord(MI_INFO *info, uint keynr, byte *keybuf,
} }
else else
len=keyseg->length; len=keyseg->length;
if (!(parsed=ft_parse(parsed, pos, len))) if (!(ft_parse(parsed, pos, len)))
return NULL; return 1;
} }
/* Handle the case where all columns are NULL */ /* Handle the case where all columns are NULL */
if (!is_tree_inited(parsed) && !(parsed=ft_parse(parsed, (byte*) "", 0))) if (!is_tree_inited(parsed) && !(ft_parse(parsed, (byte*) "", 0)))
return 1;
else
return 0;
}
FT_WORD * _mi_ft_parserecord(MI_INFO *info, uint keynr, byte *keybuf,
const byte *record)
{
TREE ptree;
bzero(&ptree, sizeof(ptree));
if (_mi_ft_parse(& ptree, info, keynr, record))
return NULL; return NULL;
return ft_linearize(info, keynr, keybuf, parsed);
return ft_linearize(/*info, keynr, keybuf, */ & ptree);
} }
static int _mi_ft_store(MI_INFO *info, uint keynr, byte *keybuf, static int _mi_ft_store(MI_INFO *info, uint keynr, byte *keybuf,
...@@ -158,7 +166,7 @@ int _mi_ft_cmp(MI_INFO *info, uint keynr, const byte *rec1, const byte *rec2) ...@@ -158,7 +166,7 @@ int _mi_ft_cmp(MI_INFO *info, uint keynr, const byte *rec1, const byte *rec2)
} }
/* update a document entry */ /* update a document entry */
int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf, int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf,
const byte *oldrec, const byte *newrec, my_off_t pos) const byte *oldrec, const byte *newrec, my_off_t pos)
{ {
int error= -1; int error= -1;
......
...@@ -120,8 +120,8 @@ byte ft_get_word(byte **, byte *, FT_WORD *, FTB_PARAM *); ...@@ -120,8 +120,8 @@ byte ft_get_word(byte **, byte *, FT_WORD *, FTB_PARAM *);
byte ft_simple_get_word(byte **, byte *, FT_WORD *); byte ft_simple_get_word(byte **, byte *, FT_WORD *);
TREE * ft_parse(TREE *, byte *, int); TREE * ft_parse(TREE *, byte *, int);
FT_WORD * ft_linearize(MI_INFO *, uint, byte *, TREE *); FT_WORD * ft_linearize(/*MI_INFO *, uint, byte *, */TREE *);
FT_WORD * _mi_ft_parserecord(MI_INFO *, uint , byte *, const byte *); FT_WORD * _mi_ft_parserecord(MI_INFO *, uint, byte *, const byte *);
const struct _ft_vft _ft_vft_nlq; const struct _ft_vft _ft_vft_nlq;
FT_INFO *ft_init_nlq_search(MI_INFO *, uint, byte *, uint, my_bool); FT_INFO *ft_init_nlq_search(MI_INFO *, uint, byte *, uint, my_bool);
......
...@@ -21,8 +21,8 @@ INSERT INTO t2 VALUES (5,2,'um copo de Vodka'); ...@@ -21,8 +21,8 @@ INSERT INTO t2 VALUES (5,2,'um copo de Vodka');
INSERT INTO t2 VALUES (6,2,'um chocolate Snickers'); INSERT INTO t2 VALUES (6,2,'um chocolate Snickers');
INSERT INTO t2 VALUES (7,1,'Bife'); INSERT INTO t2 VALUES (7,1,'Bife');
INSERT INTO t2 VALUES (8,1,'Pizza de Salmao'); INSERT INTO t2 VALUES (8,1,'Pizza de Salmao');
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi') as x FROM t1, t2 SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi')
WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id; as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x q item id x
aaaaaaaaa dsaass de sushi 1 1.92378664016724 aaaaaaaaa dsaass de sushi 1 1.92378664016724
aaaaaaaaa dsaass de Bolo de Chocolate 2 0 aaaaaaaaa dsaass de Bolo de Chocolate 2 0
...@@ -32,8 +32,19 @@ ssde df s fsda sad er um copo de Vodka 5 0 ...@@ -32,8 +32,19 @@ ssde df s fsda sad er um copo de Vodka 5 0
ssde df s fsda sad er um chocolate Snickers 6 0 ssde df s fsda sad er um chocolate Snickers 6 0
aaaaaaaaa dsaass de Bife 7 0 aaaaaaaaa dsaass de Bife 7 0
aaaaaaaaa dsaass de Pizza de Salmao 8 0 aaaaaaaaa dsaass de Pizza de Salmao 8 0
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi') as x FROM t2, t1 SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id; as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x
aaaaaaaaa dsaass de sushi 1 1
aaaaaaaaa dsaass de Bolo de Chocolate 2 0
aaaaaaaaa dsaass de Feijoada 3 0
aaaaaaaaa dsaass de Mousse de Chocolate 4 0
ssde df s fsda sad er um copo de Vodka 5 0
ssde df s fsda sad er um chocolate Snickers 6 0
aaaaaaaaa dsaass de Bife 7 0
aaaaaaaaa dsaass de Pizza de Salmao 8 0
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi')
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x q item id x
aaaaaaaaa dsaass de sushi 1 1.92378664016724 aaaaaaaaa dsaass de sushi 1 1.92378664016724
aaaaaaaaa dsaass de Bolo de Chocolate 2 0 aaaaaaaaa dsaass de Bolo de Chocolate 2 0
...@@ -43,4 +54,15 @@ ssde df s fsda sad er um copo de Vodka 5 0 ...@@ -43,4 +54,15 @@ ssde df s fsda sad er um copo de Vodka 5 0
ssde df s fsda sad er um chocolate Snickers 6 0 ssde df s fsda sad er um chocolate Snickers 6 0
aaaaaaaaa dsaass de Bife 7 0 aaaaaaaaa dsaass de Bife 7 0
aaaaaaaaa dsaass de Pizza de Salmao 8 0 aaaaaaaaa dsaass de Pizza de Salmao 8 0
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x
aaaaaaaaa dsaass de sushi 1 1
aaaaaaaaa dsaass de Bolo de Chocolate 2 0
aaaaaaaaa dsaass de Feijoada 3 0
aaaaaaaaa dsaass de Mousse de Chocolate 4 0
ssde df s fsda sad er um copo de Vodka 5 0
ssde df s fsda sad er um chocolate Snickers 6 0
aaaaaaaaa dsaass de Bife 7 0
aaaaaaaaa dsaass de Pizza de Salmao 8 0
drop table t1, t2; drop table t1, t2;
...@@ -26,10 +26,16 @@ INSERT INTO t2 VALUES (6,2,'um chocolate Snickers'); ...@@ -26,10 +26,16 @@ INSERT INTO t2 VALUES (6,2,'um chocolate Snickers');
INSERT INTO t2 VALUES (7,1,'Bife'); INSERT INTO t2 VALUES (7,1,'Bife');
INSERT INTO t2 VALUES (8,1,'Pizza de Salmao'); INSERT INTO t2 VALUES (8,1,'Pizza de Salmao');
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi') as x FROM t1, t2 SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi')
WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id; as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi') as x FROM t2, t1 SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id; as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi')
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
drop table t1, t2; drop table t1, t2;
...@@ -124,7 +124,6 @@ byte *queue_remove(register QUEUE *queue, uint idx) ...@@ -124,7 +124,6 @@ byte *queue_remove(register QUEUE *queue, uint idx)
} }
} }
/* Fix when element on top has been replaced */ /* Fix when element on top has been replaced */
#ifndef queue_replaced #ifndef queue_replaced
...@@ -166,3 +165,19 @@ void _downheap(register QUEUE *queue, uint idx) ...@@ -166,3 +165,19 @@ void _downheap(register QUEUE *queue, uint idx)
} }
queue->root[idx]=element; queue->root[idx]=element;
} }
static int queue_fix_cmp(QUEUE *queue, void *a, void *b)
{
return queue->compare(queue->first_cmp_arg,
a+queue->offset_to_key,
b+queue->offset_to_key);
}
/* Fix heap when every element was changed */
void queue_fix(QUEUE *queue)
{
qsort2(queue->root+1,queue->elements, sizeof(void *),
(qsort2_cmp)queue_fix_cmp, queue);
}
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