[Tritonn-commit 74] [svn] [84] Applied tritonn-1.0.8 patch from myisam directory.

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2008年 1月 22日 (火) 10:34:57 JST


Revision: 84
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=tritonn&view=rev&rev=84
Author:   mir
Date:     2008-01-22 10:34:57 +0900 (Tue, 22 Jan 2008)

Log Message:
-----------
Applied tritonn-1.0.8 patch from myisam directory.
This is very simple migration. May not work properly.

Modified Paths:
--------------
    trunk/src/ft_boolean_search.c
    trunk/src/ft_nlq_search.c
    trunk/src/ft_update.c
    trunk/src/fulltext.h
    trunk/src/mi_check.c
    trunk/src/mi_close.c
    trunk/src/mi_create.c
    trunk/src/mi_delete_all.c
    trunk/src/mi_delete_table.c
    trunk/src/mi_info.c
    trunk/src/mi_open.c
    trunk/src/mi_rename.c
    trunk/src/myisam_ftdump.c
    trunk/src/myisamchk.c
    trunk/src/myisamlog.c
    trunk/src/myisampack.c

Modified: trunk/src/ft_boolean_search.c
===================================================================
--- trunk/src/ft_boolean_search.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/ft_boolean_search.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -54,6 +54,11 @@
 #define FT_CORE
 #include "ftdefs.h"
 
+#ifdef ENABLE_SENNA
+#include <senna.h>
+#define SENNA_MAX_N_EXPR 32
+#endif /* ENABLE_SENNA */
+
 /* search with boolean queries */
 
 static double _wghts[11]=
@@ -142,6 +147,9 @@
   uint       keynr;
   uchar      with_scan;
   enum { UNINITIALIZED, READY, INDEX_SEARCH, INDEX_DONE } state;
+#ifdef ENABLE_SENNA
+  sen_records *sir;
+#endif /* ENABLE_SENNA */
 } FTB;
 
 static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b)
@@ -541,6 +549,40 @@
   DBUG_ASSERT(keynr==NO_SUCH_KEY || cs == info->s->keyinfo[keynr].seg->charset);
   ftb->with_scan=0;
   ftb->lastpos=HA_OFFSET_ERROR;
+#ifdef ENABLE_SENNA
+  if ((ftb->keynr != NO_SUCH_KEY) && ftb->info->s->keyinfo[ftb->keynr].senna)
+  {
+    sen_index *i;
+    sen_query *q;
+    const char *rest;
+    unsigned int rest_len;
+    if (keynr==NO_SUCH_KEY ||
+	!(i = info->s->keyinfo[keynr].senna)) {
+      SEN_LOG(sen_log_warning, "ft_init_boolean_serch: keynr==NO_SUCH_KEY");
+      my_free((gptr)ftb,MYF(0));
+      return 0;
+    }
+    SEN_LOG(sen_log_info, "ft_init_boolean_search => sen_query_open: str='%s', str_len=%d, max_exprs=%d",
+	    query, query_len, SENNA_MAX_N_EXPR);
+    if (!(q = sen_query_open(query, query_len, sen_sel_or, SENNA_MAX_N_EXPR, 
+			     info->s->keyinfo[keynr].senna_encoding))) {
+      SEN_LOG(sen_log_error, "ft_init_boolean_serch: sen_query_open returned error");
+      my_free((gptr)ftb,MYF(0));
+      return 0;
+    }
+    SEN_LOG(sen_log_debug, "ft_init_boolean_search => sen_query_rest: q=%p, rest=%p", q, &rest);
+    if ((rest_len = sen_query_rest(q, &rest))) {
+      SEN_LOG(sen_log_warning, "ft_init_boolean_search: too long query. rest(%.*s) are ignored", rest_len, rest);
+    }
+    SEN_LOG(sen_log_debug, "ft_init_boolean_search => sen_records_open");
+    ftb->sir = sen_records_open(sen_rec_document, sen_rec_none, 0);
+    SEN_LOG(sen_log_info, "ft_init_boolean_search => sen_query_exec: i=%p, q=%p, r=%p", i, q, ftb->sir);
+    sen_query_exec(i, q, ftb->sir, sen_sel_or);
+    SEN_LOG(sen_log_debug, "ft_init_boolean_search => sen_query_close: q=%p", q);
+    sen_query_close(q);
+    return ftb;
+  }
+#endif /* ENABLE_SENNA */ 
   bzero(& ftb->no_dupes, sizeof(TREE));
   ftb->last_word= 0;
 
@@ -777,6 +819,32 @@
 
 int ft_boolean_read_next(FT_INFO *ftb, char *record)
 {
+#ifdef ENABLE_SENNA
+  if ((ftb->keynr != NO_SUCH_KEY) && ftb->info->s->keyinfo[ftb->keynr].senna)
+  {
+    my_off_t pos;
+    MI_INFO   *info=ftb->info;
+    while (ftb->sir && sen_records_next(ftb->sir, &pos, sizeof(my_off_t), NULL)) {
+      info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
+      info->lastpos=pos;
+      if (!(my_thread_var->sen_flags & (SENNA_USE_2IND | SENNA_IF_READ_RECORD | 
+					SENNA_FILESORT))) {
+	SEN_LOG(sen_log_dump, "ft_boolean_read_next: 2ind return 0");
+	return 0;
+      }
+      if (!(*info->read_record)(info,info->lastpos,record)) {
+        info->update|= HA_STATE_AKTIV;          /* Record is read */
+        return 0;
+      }
+      SEN_LOG(sen_log_error, "ft_boolean_read_next: my_errno=%d pos=%lld", my_errno, pos);
+      if (my_errno == 127) { continue; }
+      return my_errno;
+    }
+    return HA_ERR_END_OF_FILE;
+  }
+  else
+#endif /* ENABLE_SENNA */
+ {
   FTB_EXPR  *ftbe;
   FTB_WORD  *ftbw;
   MI_INFO   *info=ftb->info;
@@ -847,9 +915,9 @@
 err:
   ftb->queue.first_cmp_arg=(void *)0;
   return my_errno;
+ }
 }
 
-
 typedef struct st_my_ftb_find_param
 {
   FT_INFO *ftb;
@@ -907,6 +975,20 @@
 
 float ft_boolean_find_relevance(FT_INFO *ftb, uchar *record, uint length)
 {
+#ifdef ENABLE_SENNA
+  if ((ftb->keynr != NO_SUCH_KEY) && ftb->info->s->keyinfo[ftb->keynr].senna)
+  {
+    my_off_t  docid=ftb->info->lastpos;
+    if (!ftb->sir) { return 0.0; }
+    if (docid == HA_OFFSET_ERROR)
+      return -2.0;
+    SEN_LOG(sen_log_dump, "ft_boolean_find_relevance => sen_records_find: records=%p, key=%p",
+	    ftb->sir, &docid);
+    return 1.0 * sen_records_find(ftb->sir, &docid);
+  }
+  else
+#endif /* ENABLE_SENNA */
+  {
   FTB_EXPR *ftbe;
   FT_SEG_ITERATOR ftsi, ftsi2;
   my_off_t  docid=ftb->info->lastpos;
@@ -971,11 +1053,21 @@
   { /* match failed ! */
     return 0.0;
   }
+ }
 }
 
 
 void ft_boolean_close_search(FT_INFO *ftb)
 {
+#ifdef ENABLE_SENNA
+  if ((ftb->keynr != NO_SUCH_KEY) && ftb->info->s->keyinfo[ftb->keynr].senna)
+  {
+    SEN_LOG(sen_log_debug, "ft_boolean_close_search => sen_records_close: records=%p", ftb->sir);
+    sen_records_close(ftb->sir);
+    my_free((gptr)ftb,MYF(0));
+    return;
+  }
+#endif /* ENABLE_SENNA */
   if (is_tree_inited(& ftb->no_dupes))
   {
     delete_tree(& ftb->no_dupes);
@@ -987,12 +1079,28 @@
 
 float ft_boolean_get_relevance(FT_INFO *ftb)
 {
+#ifdef ENABLE_SENNA
+  if ((ftb->keynr != NO_SUCH_KEY) && ftb->info->s->keyinfo[ftb->keynr].senna)
+  {
+    if (!ftb->sir) { return 0.0; }
+    SEN_LOG(sen_log_dump, "ft_boolean_get_relevance => sen_records_curr_score: r=%p", ftb->sir);
+    return 1.0 * sen_records_curr_score(ftb->sir);
+  }
+#endif /* ENABLE_SENNA */
   return ftb->root->cur_weight;
 }
 
 
 void ft_boolean_reinit_search(FT_INFO *ftb)
 {
+#ifdef ENABLE_SENNA
+  if ((ftb->keynr != NO_SUCH_KEY) && ftb->info->s->keyinfo[ftb->keynr].senna)
+  {
+    SEN_LOG(sen_log_debug, "ft_boolean_reinit_search => sen_records_rewind: records=%p", ftb->sir);
+    sen_records_rewind(ftb->sir);
+    return;
+  }
+#endif /* ENABLE_SENNA */
   _ftb_init_index_search(ftb);
 }
 

Modified: trunk/src/ft_nlq_search.c
===================================================================
--- trunk/src/ft_nlq_search.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/ft_nlq_search.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -32,6 +32,9 @@
   MI_INFO  *info;
   int       ndocs;
   int       curdoc;
+#ifdef ENABLE_SENNA
+  sen_records *sir;
+#endif /* ENABLE_SENNA */
   FT_DOC    doc[1];
 };
 
@@ -211,8 +214,23 @@
   my_off_t    saved_lastpos=info->lastpos;
   struct st_mysql_ftparser *parser;
   MYSQL_FTPARSER_PARAM *ftparser_param;
+#ifdef ENABLE_SENNA
+  sen_records *sir;
+#endif /* ENABLE_SENNA */
   DBUG_ENTER("ft_init_nlq_search");
 
+#ifdef ENABLE_SENNA
+  if (info->s->keyinfo[keynr].senna)
+    {
+      SEN_LOG(sen_log_info, "ft_init_nlq_search => sen_index_sel index=%p, string='%s', string_len=%d",
+	      info->s->keyinfo[keynr].senna, query, query_len);
+      sir = sen_index_sel(info->s->keyinfo[keynr].senna, query, query_len);
+    }
+  else
+    {
+      sir = NULL;
+    }
+#endif /* ENABLE_SENNA */
 /* black magic ON */
   if ((int) (keynr = _mi_check_index(info,keynr)) < 0)
     DBUG_RETURN(NULL);
@@ -290,6 +308,9 @@
   dlist->info=aio.info;
   dptr=dlist->doc;
 
+#ifdef ENABLE_SENNA
+  dlist->sir = sir;
+#endif /* ENABLE_SENNA */
   tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy,
 	    &dptr, left_root_right);
 
@@ -307,6 +328,32 @@
 int ft_nlq_read_next(FT_INFO *handler, char *record)
 {
   MI_INFO *info= (MI_INFO *) handler->info;
+#ifdef ENABLE_SENNA
+  if (handler->sir)
+  {
+    my_off_t pos;
+    info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
+    SEN_LOG(sen_log_dump, "ft_nlq_read_next => sen_records_next in while loop");
+    while (sen_records_next(handler->sir, &pos, sizeof(my_off_t), NULL))
+    {
+      info->lastpos=pos;
+      if (!(my_thread_var->sen_flags & (SENNA_USE_2IND | SENNA_IF_READ_RECORD |
+					SENNA_FILESORT))) {
+	SEN_LOG(sen_log_dump, "ft_nlq_read_next => 2ind return 0");
+	return 0;
+      }
+      if (!(*info->read_record)(info,info->lastpos,record))
+      {
+	info->update|= HA_STATE_AKTIV;		/* Record is read */
+	return 0;
+      }
+      SEN_LOG(sen_log_error, "ft_nlq_read_next => my_errno=%d pos=%lld", my_errno, pos);
+      if (my_errno == 127) { continue; }
+      return my_errno;
+    }
+    return HA_ERR_END_OF_FILE;
+  }
+#endif /* ENABLE_SENNA */
 
   if (++handler->curdoc >= handler->ndocs)
   {
@@ -337,6 +384,14 @@
   if (docid == HA_POS_ERROR)
     return -5.0;
 
+#ifdef ENABLE_SENNA
+  if (handler->sir) {
+    SEN_LOG(sen_log_dump, "ft_nlq_find_relevance => sen_records_find: records=%p, key=%p",
+	    handler->sir, &docid);
+    return 1.0 * sen_records_find(handler->sir, &docid);
+  }
+#endif /* ENABLE_SENNA */
+
   /* Assuming docs[] is sorted by dpos... */
 
   for (a=0, b=handler->ndocs, c=(a+b)/2; b-a>1; c=(a+b)/2)
@@ -356,18 +411,46 @@
 
 void ft_nlq_close_search(FT_INFO *handler)
 {
+#ifdef ENABLE_SENNA
+  if (handler->sir)
+  {
+    SEN_LOG(sen_log_debug, "ft_nlq_close_search => sen_records_close: records=%p",
+	    handler->sir);
+    sen_records_close(handler->sir);
+  }
+#endif /* ENABLE_SENNA */
   my_free((uchar*)handler,MYF(0));
 }
 
 
 float ft_nlq_get_relevance(FT_INFO *handler)
 {
+#ifdef ENABLE_SENNA
+  if (!handler->sir) {
+    if (handler->doc) {
+      return (float) handler->doc[handler->curdoc].weight;
+    }
+    return 0.0; 
+  }
+  SEN_LOG(sen_log_dump, "ft_nlq_get_relevance => sen_records_curr_score: r=%p",
+          handler->sir);
+  return 1.0 * sen_records_curr_score(handler->sir);
+#else /* ENABLE_SENNA */
   return (float) handler->doc[handler->curdoc].weight;
+#endif /* ENABLE_SENNA */
 }
 
 
 void ft_nlq_reinit_search(FT_INFO *handler)
 {
+#ifdef ENABLE_SENNA
+  if (handler->sir)
+  {
+    SEN_LOG(sen_log_debug, "ft_nlq_reinit_search => sen_records_rewind: r=%p",
+	    handler->sir);
+    sen_records_rewind(handler->sir);
+  }
+#endif /* ENABLE_SENNA */
   handler->curdoc=-1;
 }
 

Modified: trunk/src/ft_update.c
===================================================================
--- trunk/src/ft_update.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/ft_update.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -117,6 +117,19 @@
 FT_WORD *_mi_ft_parserecord(MI_INFO *info, uint keynr, const uchar *record,
                              MEM_ROOT *mem_root)
 {
+#ifdef ENABLE_SENNA
+  if (info->s->keyinfo[keynr].senna)
+  {
+    FT_WORD *wlist;
+    if (!(wlist = (FT_WORD *) my_malloc(sizeof(FT_WORD), MYF(0)))) {
+      return NULL;
+    }
+    wlist->pos = 0;
+    return wlist;
+  }
+  else
+#endif /* ENABLE_SENNA */
+ {
   TREE ptree;
   MYSQL_FTPARSER_PARAM *param;
   DBUG_ENTER("_mi_ft_parserecord");
@@ -128,6 +141,7 @@
     DBUG_RETURN(NULL);
 
   DBUG_RETURN(ft_linearize(&ptree, mem_root));
+ } 
 }
 
 static int _mi_ft_store(MI_INFO *info, uint keynr, uchar *keybuf,
@@ -187,7 +201,130 @@
   DBUG_RETURN(GEE_THEY_ARE_ABSOLUTELY_IDENTICAL);
 }
 
+#ifdef ENABLE_SENNA
+#define SECTIONALIZE 0x00080000
+int ft_sen_index_add(MI_INFO *info, uint keynr, const byte *record, my_off_t pos)
+{
+  DBUG_ENTER("ft_sen_index_add");
+  if (info->s->keyinfo[keynr].senna_flags & SECTIONALIZE) {
+    FT_SEG_ITERATOR ftsi;
+    unsigned int section;
+    sen_values *values;
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	if (ftsi.len > 1048576) { SEN_LOG(sen_log_debug, "ft_sen_index_add: ftsi.len=%d", ftsi.len); }
+      }
+    }
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	section = ftsi.num + 1;
+	SEN_LOG(sen_log_debug, "ft_sen_index_add => sen_values_open");
+	values = sen_values_open();
+	SEN_LOG(sen_log_debug, "ft_sen_index_add => sen_values_add: values=%p, str=%s, str_len=%d, weight=%d",
+		values, ftsi.pos, ftsi.len, 0);
+	sen_values_add(values, ftsi.pos, ftsi.len, 0);
+	SEN_LOG(sen_log_info, "ft_sen_index_add => sen_index_update: index=%p, key=%p (pos=%d), section=%d, oldvalue=%p, newvalue=%p",
+		info->s->keyinfo[keynr].senna, &pos, (uint) pos,  section, NULL, values);
+	sen_index_update(info->s->keyinfo[keynr].senna, &pos, ftsi.num+1, NULL, values);
+	SEN_LOG(sen_log_debug, "ft_sen_index_add => sen_values_close: values=%p", values);
+	sen_values_close(values);
+      }
+    }
+    DBUG_RETURN(0);
+  } else {
+    FT_SEG_ITERATOR ftsi;
+    char *buf, *p;
+    uint len = 0;
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	if (ftsi.len > 1048576) { SEN_LOG(sen_log_debug, "ft_sen_index_add: ftsi.len=%d", ftsi.len); }
+	len += ftsi.len + 1;
+      }
+    }
+    if (!len) { return -1; }
+    if (!(p = buf = malloc(len))) { return -1; }
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	if (p != buf) { *p++ = ' '; }
+	memcpy(p, ftsi.pos, ftsi.len);
+	p += ftsi.len;
+      }
+    }
+    *p = '\0';
+    SEN_LOG(sen_log_info, "ft_sen_index_add => sen_index_upd: index=%p, key=%p (pos=%d), oldvalue=%s,"
+	    "oldvalue_len=%d, newvalue=%s, newvalue_len=%d",
+	    info->s->keyinfo[keynr].senna, &pos, (uint) pos, NULL, 0, buf, (p - buf));
+    sen_index_upd(info->s->keyinfo[keynr].senna, &pos, NULL, 0, buf, (p - buf));
+    free(buf);
+    DBUG_RETURN(0);
+  }
+}
 
+int ft_sen_index_del(MI_INFO *info, uint keynr, const byte *record, my_off_t pos)
+{
+  if (info->s->keyinfo[keynr].senna_flags & SECTIONALIZE) {
+    FT_SEG_ITERATOR ftsi;
+    unsigned int section;
+    sen_values *values;
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	if (ftsi.len > 1048576) { SEN_LOG(sen_log_debug, "ft_sen_index_del: ftsi.len=%d", ftsi.len); }
+      }
+    }
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	section = ftsi.num + 1;
+        SEN_LOG(sen_log_debug, "ft_sen_index_del => sen_values_open");
+        values = sen_values_open();
+        SEN_LOG(sen_log_debug, "ft_sen_index_del => sen_values_add: values=%p, str=%s, str_len=%d, weight=%d",
+                values, ftsi.pos, ftsi.len, 0);
+        sen_values_add(values, ftsi.pos, ftsi.len, 0);
+        SEN_LOG(sen_log_info, "ft_sen_index_del => sen_index_update: index=%p, key=%p (pos=%d), section=%d, oldvalue=%p, newvalue=%p",
+                info->s->keyinfo[keynr].senna, &pos, (uint) pos, section, values, NULL);
+        sen_index_update(info->s->keyinfo[keynr].senna, &pos, section, values, NULL);
+        SEN_LOG(sen_log_debug, "ft_sen_index_del => sen_values_close: values=%p", values);
+        sen_values_close(values);
+      }
+    }
+    return 0;
+  } else {
+    FT_SEG_ITERATOR ftsi;
+    char *buf, *p;
+    uint len = 0;
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	if (ftsi.len > 1048576) { SEN_LOG(sen_log_debug, "ft_sen_index_del: ftsi.len=%d", ftsi.len); }
+	len += ftsi.len + 1;
+      }
+    }
+    if (!len) { return -1; }
+    if (!(p = buf = malloc(len))) { return -1; }
+    _mi_ft_segiterator_init(info, keynr, record, &ftsi);
+    while (_mi_ft_segiterator(&ftsi)) {
+      if (ftsi.pos) {
+	if (p != buf) { *p++ = ' '; }
+	memcpy(p, ftsi.pos, ftsi.len);
+	p += ftsi.len;
+      }
+    }
+    *p = '\0';
+    SEN_LOG(sen_log_info, "ft_sen_index_add => sen_index_upd: index=%p, key=%p (pos=%d), oldvalue=%p,"
+            "oldvalue_len=%d, newvalue=%p, newvalue_len=%d",
+            info->s->keyinfo[keynr].senna, &pos, (uint) pos, buf, (p - buf), NULL, 0);
+    sen_index_upd(info->s->keyinfo[keynr].senna, &pos, buf, (p - buf), NULL, 0);
+    free(buf);
+    return 0;
+  }
+}
+#endif /* ENABLE_SENNA */
+
 /* update a document entry */
 
 int _mi_ft_update(MI_INFO *info, uint keynr, uchar *keybuf,
@@ -200,6 +337,14 @@
   int cmp, cmp2;
   DBUG_ENTER("_mi_ft_update");
 
+#ifdef ENABLE_SENNA
+  if (info->s->keyinfo[keynr].senna)
+  {
+    ft_sen_index_del(info, keynr, oldrec, pos);
+    ft_sen_index_add(info, keynr, newrec, pos);
+  }
+#endif /* ENABLE_SENNA */
+
   if (!(old_word=oldlist=_mi_ft_parserecord(info, keynr, oldrec,
                                             &info->ft_memroot)) ||
       !(new_word=newlist=_mi_ft_parserecord(info, keynr, newrec,
@@ -249,6 +394,11 @@
   DBUG_ENTER("_mi_ft_add");
   DBUG_PRINT("enter",("keynr: %d",keynr));
 
+#ifdef ENABLE_SENNA
+  if (info->s->keyinfo[keynr].senna)
+    ft_sen_index_add(info, keynr, record, pos);
+#endif /* ENABLE_SENNA */
+
   if ((wlist=_mi_ft_parserecord(info, keynr, record, &info->ft_memroot)))
     error=_mi_ft_store(info,keynr,keybuf,wlist,pos);
 
@@ -268,6 +418,11 @@
   DBUG_ENTER("_mi_ft_del");
   DBUG_PRINT("enter",("keynr: %d",keynr));
 
+#ifdef ENABLE_SENNA
+  if (info->s->keyinfo[keynr].senna)
+    ft_sen_index_del(info, keynr, record, pos);
+#endif /* ENABLE_SENNA */
+
   if ((wlist=_mi_ft_parserecord(info, keynr, record, &info->ft_memroot)))
     error=_mi_ft_erase(info,keynr,keybuf,wlist,pos);
 
@@ -350,3 +505,43 @@
                                      SEARCH_SAME));
 }
 
+#ifdef ENABLE_SENNA
+/*
+  this function is called by myisamchk only.
+*/
+void ft_sen_index_truncate(MI_INFO *info)
+{
+  char buf[FN_REFLEN];
+  MYISAM_SHARE *share= info->s;
+  uint i, keys= (uint) share->state.header.keys;
+  DBUG_ENTER("ft_sen_index_truncate");
+  for (i=0 ; i < keys ; i++)
+  {
+    if (share->keyinfo[i].flag & HA_FULLTEXT)
+    {
+      if (share->keyinfo[i].senna)
+      {
+        sen_index_close(share->keyinfo[i].senna);
+      }
+      strcpy(buf, share->unique_file_name);
+      sprintf(buf + strlen(buf) - 3, "%03d", i);
+      if (share->keyinfo[i].senna_flags & SEN_DISABLE_SENNA)
+      {
+        share->keyinfo[i].senna = NULL;
+      } else {
+        if (!(share->keyinfo[i].senna_encoding >= 0 && share->keyinfo[i].senna_encoding <= 6))
+        {
+          share->keyinfo[i].senna = NULL;
+          DBUG_VOID_RETURN;
+        } else {
+          share->keyinfo[i].senna = sen_index_create(buf, sizeof(my_off_t),
+                                                     share->keyinfo[i].senna_flags,
+                                                     share->keyinfo[i].senna_initial_n_segments,
+                                                     share->keyinfo[i].senna_encoding);
+        }
+      }
+    }
+  }
+  DBUG_VOID_RETURN;
+}
+#endif /* ENABLE_SENNA */

Modified: trunk/src/fulltext.h
===================================================================
--- trunk/src/fulltext.h	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/fulltext.h	2008-01-22 01:34:57 UTC (rev 84)
@@ -35,3 +35,7 @@
 
 uint _mi_ft_convert_to_ft2(MI_INFO *, uint, uchar *);
 
+#ifdef ENABLE_SENNA 
+int ft_sen_index_add(MI_INFO *info, uint keynr, const byte *record, my_off_t pos);
+void ft_sen_index_truncate(MI_INFO *info);
+#endif

Modified: trunk/src/mi_check.c
===================================================================
--- trunk/src/mi_check.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_check.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -2108,7 +2108,6 @@
   SORT_INFO sort_info;
   ulonglong key_map=share->state.key_map;
   DBUG_ENTER("mi_repair_by_sort");
-
   start_records=info->state->records;
   got_error=1;
   new_file= -1;
@@ -3048,6 +3047,11 @@
       free_root(&sort_param->wordroot, MYF(MY_MARK_BLOCKS_FREE));
       if ((error=sort_get_next_record(sort_param)))
         DBUG_RETURN(error);
+#ifdef ENABLE_SENNA
+      if (info->s->keyinfo[sort_param->key].senna) {
+        ft_sen_index_add(info, sort_param->key, sort_param->record, sort_param->filepos);
+      }
+#endif /* ENABLE_SENNA */
       if (!(wptr=_mi_ft_parserecord(info,sort_param->key,sort_param->record,
                                     &sort_param->wordroot)))
         DBUG_RETURN(1);

Modified: trunk/src/mi_close.c
===================================================================
--- trunk/src/mi_close.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_close.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -30,7 +30,6 @@
   DBUG_PRINT("enter",("base: 0x%lx  reopen: %u  locks: %u",
 		      (long) info, (uint) share->reopen,
                       (uint) share->tot_locks));
-
   pthread_mutex_lock(&THR_LOCK_myisam);
   if (info->lock_type == F_EXTRA_LCK)
     info->lock_type=F_UNLCK;			/* HA_EXTRA_NO_USER_CHANGE */
@@ -99,6 +98,26 @@
       VOID(rwlock_destroy(&share->mmap_lock));
       for(i=0; i<keys; i++) {
 	VOID(rwlock_destroy(&share->key_root_lock[i]));
+
+#ifdef ENABLE_SENNA
+	if (share->keyinfo[i].flag & HA_FULLTEXT)
+	{
+	  {
+	    char buf[FN_REFLEN];
+	    strncpy(buf, share->unique_file_name, FN_REFLEN - 1);
+	    buf[FN_REFLEN - 1] = '\0';
+	    sprintf(buf + strlen(buf) - 3, "%03d", i);
+	    if (share->keyinfo[i].senna) {
+	      SEN_LOG(sen_log_notice, "mi_close => sen_index_close: "
+		      "delay_key_write=%d, unique_file_name=%s, data_file_name=%s, index_file_name=%s",
+		      share->delay_key_write, share->unique_file_name, share->data_file_name, share->index_file_name);
+	      sen_index_close(share->keyinfo[i].senna);
+	    }
+	  }
+	}
+#endif /* ENABLE_SENNA */
+
+
       }
     }
 #endif

Modified: trunk/src/mi_create.c
===================================================================
--- trunk/src/mi_create.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_create.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -287,6 +287,59 @@
     }
     else if (keydef->flag & HA_FULLTEXT)
     {
+#ifdef ENABLE_SENNA
+      sen_index *senna;
+      char buf[FN_REFLEN];
+      strncpy(buf, name, FN_REFLEN - 1);
+      buf[FN_REFLEN - 1] = '\0';
+      sprintf(buf + strlen(buf), ".%03d", i);
+      if (!(keydef->senna_flags & SEN_DISABLE_SENNA))
+      {
+	/* make index files */
+	SEN_LOG(sen_log_notice,
+		"mi_create => sen_index_create: path=%s, key_size=%d, flags=%x, ins=%d", buf,
+		sizeof(my_off_t), keydef->senna_flags, keydef->senna_initial_n_segments);
+        if (!(keydef->senna_encoding >= 0 && keydef->senna_encoding <= 6))
+        {
+          my_errno= HA_WRONG_CREATE_OPTION;
+          goto err;
+        }
+	senna = sen_index_create(buf, sizeof(my_off_t),
+				 keydef->senna_flags,
+				 keydef->senna_initial_n_segments,
+				 keydef->senna_encoding);
+	SEN_LOG(sen_log_notice, "mi_create => sen_index_close: index=%p", senna);
+	sen_index_close(senna);
+      } else {
+	SEN_LOG(sen_log_notice, "mi_create => sen_index_open: path=%s", buf);
+	senna = sen_index_open(buf);
+	if (senna) {
+	  int senna_flags, senna_initial_n_segments;
+	  sen_encoding senna_encoding;
+	  SEN_LOG(sen_log_info, "mi_create => sen_index_info: index=%p", senna);
+	  sen_index_info(senna, NULL, &senna_flags, &senna_initial_n_segments,
+			 &senna_encoding, NULL, NULL, NULL, NULL, NULL, NULL);
+	  SEN_LOG(sen_log_notice, "mi_create => sen_index_close: index=%p", senna);
+	  sen_index_close(senna);
+	  SEN_LOG(sen_log_notice, "mi_create => sen_index_remove: path=%s", buf);
+	  sen_index_remove(buf);
+	  SEN_LOG(sen_log_notice,
+		  "mi_create => sen_index_create: path=%s, key_size=%d, flags=%x ins=%d)", buf,
+		  sizeof(my_off_t), senna_flags, senna_initial_n_segments);
+        if (!(senna_encoding >= 0 && senna_encoding <= 6))
+        {
+          my_errno= HA_WRONG_CREATE_OPTION;
+          goto err;
+        }
+	  senna = sen_index_create(buf, sizeof(my_off_t),
+				   senna_flags,
+				   senna_initial_n_segments,
+				   senna_encoding);
+	  SEN_LOG(sen_log_notice, "mi_create => sen_index_close: index=%p", senna);
+	  sen_index_close(senna);
+	}
+      }
+#endif /* ENABLE_SENNA */
       keydef->flag=HA_FULLTEXT | HA_PACK_KEY | HA_VAR_LENGTH_KEY;
       options|=HA_OPTION_PACK_KEYS;             /* Using packed keys */
 

Modified: trunk/src/mi_delete_all.c
===================================================================
--- trunk/src/mi_delete_all.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_delete_all.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -34,6 +34,34 @@
   if (_mi_mark_file_changed(info))
     goto err;
 
+#ifdef ENABLE_SENNA
+  for (i = 0; i < share->base.keys; i++) {
+    sen_index *senna = share->keyinfo[i].senna;
+    if (senna)
+    {
+      char buf[FN_REFLEN];
+      if (!(share->keyinfo[i].senna_encoding >= 0 && share->keyinfo[i].senna_encoding <= 6))
+      {
+        my_errno= HA_WRONG_CREATE_OPTION;
+        goto err;
+      }
+      SEN_LOG(sen_log_debug, "mi_delete_all_rows => sen_index_path: index=%p, buf=%s", senna, buf);
+      sen_index_path(senna, buf, FN_REFLEN);
+      SEN_LOG(sen_log_notice, "mi_delete_all_rows => sen_index_close: index=%p", senna);
+      sen_index_close(senna);
+      SEN_LOG(sen_log_notice, "mi_delete_all_rows => sen_index_remove: buf=%s", buf);
+      sen_index_remove(buf);
+      SEN_LOG(sen_log_notice, "mi_delete_all_rows => sen_index_create: path=%s, flags=%x, ins=%d",
+	      buf, share->keyinfo[i].senna_flags, share->keyinfo[i].senna_initial_n_segments);
+      senna = sen_index_create(buf, sizeof(my_off_t),
+			       share->keyinfo[i].senna_flags,
+			       share->keyinfo[i].senna_initial_n_segments,
+			       share->keyinfo[i].senna_encoding);
+      share->keyinfo[i].senna = senna;
+    }
+  }
+#endif /* ENABLE_SENNA */
+
   info->state->records=info->state->del=state->split=0;
   state->dellink = HA_OFFSET_ERROR;
   state->sortkey=  (ushort) ~0;

Modified: trunk/src/mi_delete_table.c
===================================================================
--- trunk/src/mi_delete_table.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_delete_table.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -56,7 +56,32 @@
   check_table_is_closed(name,"delete");
 #endif
 #endif /* USE_RAID */
+#ifdef ENABLE_SENNA
+  {
+    int i,j,keys;
+    int should_be_deleted[1024];
+    MI_INFO *mi_info;
+    MI_INFO cp_of_mi_info;
 
+    if (!(mi_info = mi_open(name, O_RDONLY, 0)))
+    {
+      SEN_LOG(sen_log_warning, "mi_delete_table => cannot get MI_INFO");
+      DBUG_RETURN(my_errno);
+    }
+    keys = mi_info->s->base.keys;
+    for (i=0,j=0; i<keys; i++)
+    {
+      if (mi_info->s->keyinfo[i].senna) should_be_deleted[j++]=i;
+    }
+    mi_close(mi_info);
+    for (i=0; i<j; i++)
+    {
+      my_snprintf(from, FN_REFLEN, "%s.%03d", name, should_be_deleted[i]);
+      SEN_LOG(sen_log_notice, "mi_delete_table => sen_index_remove: path=%s", from);
+      sen_index_remove(from);
+    }
+  }
+#endif /* ENABLE_SENNA */
   fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
   if (my_delete_with_symlink(from, MYF(MY_WME)))
     DBUG_RETURN(my_errno);

Modified: trunk/src/mi_info.c
===================================================================
--- trunk/src/mi_info.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_info.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -60,6 +60,26 @@
     x->mean_reclength= x->records ?
       (ulong) ((x->data_file_length - x->delete_length) / x->records) :
       (ulong) share->min_pack_length;
+#ifdef ENABLE_SENNA
+    if ((flag & HA_STATUS_SENNA) && share->keyinfo) 
+    {
+      int i;
+      for (i = 0; i < share->base.keys; i++)
+      {
+	MI_KEYDEF *keydef = &share->keyinfo[i];
+	sen_index *senna = keydef->senna;
+	if (senna)
+	{
+	  SEN_LOG(sen_log_info, "mi_info => sen_index_info: index=%p", senna);
+	  sen_index_info(senna, NULL, &keydef->senna_flags,
+			 &keydef->senna_initial_n_segments, &keydef->senna_encoding,
+			 &keydef->senna_keys_size, &keydef->senna_keys_file_size,
+			 &keydef->senna_lexicon_size, &keydef->senna_lexicon_file_size,
+			 &keydef->senna_inv_seg_size, &keydef->senna_inv_chunk_size);
+	}
+      }
+    }
+#endif /* ENABLE_SENNA */
   }
   if (flag & HA_STATUS_ERRKEY)
   {

Modified: trunk/src/mi_open.c
===================================================================
--- trunk/src/mi_open.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_open.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -356,6 +356,11 @@
 	  else if (pos->type == HA_KEYTYPE_BINARY)
 	    pos->charset= &my_charset_bin;
 	}
+#ifdef ENABLE_SENNA
+	share->keyinfo[i].senna = NULL;
+	share->keyinfo[i].senna_flags = 0;
+	share->keyinfo[i].senna_initial_n_segments = 0;
+#endif /* ENABLE_SENNA */
 	if (share->keyinfo[i].flag & HA_SPATIAL)
 	{
 #ifdef HAVE_SPATIAL
@@ -369,6 +374,29 @@
 	}
         else if (share->keyinfo[i].flag & HA_FULLTEXT)
 	{
+#ifdef ENABLE_SENNA
+	  if (!(share->keyinfo[i].senna_flags & SEN_DISABLE_SENNA))
+	  {
+	    {
+	      char buf[FN_REFLEN];
+	      strncpy(buf, share->unique_file_name, FN_REFLEN - 1);
+	      buf[FN_REFLEN - 1] = '\0';
+	      sprintf(buf + strlen(buf) - 3, "%03d", i);
+	      SEN_LOG(sen_log_notice, "mi_open => "
+		      "sen_index_open: path=%s, delay_key_write=%d, unique_file_name=%s, data_file_name=%s, " 
+		      "index_file_name=%s, keyinfo[%d].seg=%d", 
+		      buf, share->delay_key_write, share->unique_file_name, share->data_file_name,
+		      share->index_file_name, i, pos-FT_SEGS);
+	      share->keyinfo[i].senna = sen_index_open(buf);
+	      SEN_LOG(sen_log_info, "mi_open => sen_index_info: index=%p", share->keyinfo[i].senna);
+	      sen_index_info(share->keyinfo[i].senna, NULL,
+			     &share->keyinfo[i].senna_flags,
+			     &share->keyinfo[i].senna_initial_n_segments,
+			     &share->keyinfo[i].senna_encoding,
+                             NULL, NULL, NULL, NULL, NULL, NULL);
+	    }
+	  }
+#endif /* ENABLE_SENNA */
           if (!fulltext_keys)
           { /* 4.0 compatibility code, to be removed in 5.0 */
             share->keyinfo[i].seg=pos-FT_SEGS;

Modified: trunk/src/mi_rename.c
===================================================================
--- trunk/src/mi_rename.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/mi_rename.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -45,6 +45,34 @@
 #endif
 #endif /* USE_RAID */
 
+#ifdef ENABLE_SENNA /* nkjm modified 2007/06/04 SFID:10291 */
+  {
+    int i, keys;
+    MI_INFO *mi_info;
+    MI_INFO cp_of_mi_info;
+
+    if (!(mi_info = mi_open(old_name, O_RDONLY, 0)))
+      {
+	SEN_LOG(sen_log_warning, "mi_rename => cannot get MI_INFO");
+	DBUG_RETURN(my_errno);
+      }
+
+    cp_of_mi_info = *mi_info;
+    mi_close(mi_info);
+    keys = cp_of_mi_info.s->base.keys;
+    for (i = 0; i < keys; i++)
+      {
+	if (cp_of_mi_info.s->keyinfo[i].senna)
+	  {
+	    my_snprintf(from, FN_REFLEN, "%s.%03d", old_name, i);
+	    my_snprintf(to, FN_REFLEN, "%s.%03d", new_name, i);
+	    SEN_LOG(sen_log_notice, "mi_rename => sen_index_rename: from=%s, to=%s", from, to);
+	    sen_index_rename(from, to);
+	  }
+      }
+  }
+#endif /* ENABLE_SENNA */
+
   fn_format(from,old_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
   fn_format(to,new_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
   if (my_rename_with_symlink(from, to, MYF(MY_WME)))

Modified: trunk/src/myisam_ftdump.c
===================================================================
--- trunk/src/myisam_ftdump.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/myisam_ftdump.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -63,6 +63,9 @@
   struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */
 
   MY_INIT(argv[0]);
+#ifdef ENABLE_SENNA
+  sen_init();
+#endif /* ENABLE_SENNA */
   if ((error= handle_options(&argc, &argv, my_long_options, get_one_option)))
     exit(error);
   if (count || dump)

Modified: trunk/src/myisamchk.c
===================================================================
--- trunk/src/myisamchk.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/myisamchk.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -93,6 +93,9 @@
   get_options(&argc,(char***) &argv);
   myisam_quick_table_bits=decode_bits;
   error=0;
+#ifdef ENABLE_SENNA
+  sen_init();
+#endif /* ENABLE_SENNA */
   while (--argc >= 0)
   {
     int new_error=myisamchk(&check_param, *(argv++));
@@ -1003,6 +1006,9 @@
       }
       if (!error)
       {
+#ifdef ENABLE_SENNA
+	ft_sen_index_truncate(info);
+#endif /* ENABLE_SENNA */
 	if ((param->testflag & (T_REP_BY_SORT | T_REP_PARALLEL)) &&
 	    (mi_is_any_key_active(share->state.key_map) ||
 	     (rep_quick && !param->keys_in_use && !recreate)) &&
@@ -1059,6 +1065,9 @@
 	  {
 	    if (param->verbose)
 	      puts("Table had a compressed index;  We must now recreate the index");
+#ifdef ENABLE_SENNA
+	    ft_sen_index_truncate(info);
+#endif /* ENABLE_SENNA */
 	    error=mi_repair_by_sort(param,info,filename,1);
 	  }
 	}

Modified: trunk/src/myisamlog.c
===================================================================
--- trunk/src/myisamlog.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/myisamlog.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -86,6 +86,9 @@
   int error,i,first;
   ulong total_count,total_error,total_recover;
   MY_INIT(argv[0]);
+#ifdef ENABLE_SENNA
+  sen_init();
+#endif /* ENABLE_SENNA */
 
   log_filename=myisam_log_filename;
   get_options(&argc,&argv);

Modified: trunk/src/myisampack.c
===================================================================
--- trunk/src/myisampack.c	2008-01-21 07:26:12 UTC (rev 83)
+++ trunk/src/myisampack.c	2008-01-22 01:34:57 UTC (rev 84)
@@ -207,6 +207,9 @@
   PACK_MRG_INFO merge;
   char **default_argv;
   MY_INIT(argv[0]);
+#ifdef ENABLE_SENNA
+  sen_init();
+#endif /* ENABLE_SENNA */
 
   load_defaults("my",load_default_groups,&argc,&argv);
   default_argv= argv;




Tritonn-commit メーリングリストの案内
Zurück zum Archiv-Index