[Tritonn-dev 103] JOIN高速化パッチの取り込みについて

Back to archive index

Tetsuro IKEDA te.ik****@jpta*****
2008年 2月 15日 (金) 17:42:17 JST


こんにちは。池田です。

奥さんが作成してくださったパッチの取り込みですが、
以下のツリーにて先ほどpatch+commitを行わせていただきました。

http://svn.sourceforge.jp/svnroot/tritonn/tags/tritonn-1.1.0-mysql-5.0.51a

revisionは109になります。tritonn-1.1.0のリリースに含まれる予定です。

尚、リリースまでの間に私のほうで、、、

1. 変数senna_embedded_pkeyの代わりにUSING句で指定できるようにする
2. ENABLE_SENNA_USE_PSEUDO_TFをENABLE_SENNAに統合する
3. libmysqldへマージ

といったような作業を追加で行いたいと考えております。

2についてはconfigureオプション化も考えたのですが、変数での制御が
できる現状の形をそのまま有効活用したほうがいいかなと思い、
統合を考えました。

ご意見、ご要望等ありましたら、お知らせ下さい。>奥さんに限らず皆様

-------- Original Message --------
Subject: [Tritonn-commit 97]  [svn] [109] A contributed patch by
Kazuho Oku,	Cybozu labs.
Date: Fri, 15 Feb 2008 17:16:35 +0900
From: svnno****@sourc*****
Reply-To: trito****@lists*****
To: trito****@lists*****

Revision: 109

http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=tritonn&view=rev&rev=109
Author:   mir
Date:     2008-02-15 17:16:35 +0900 (Fri, 15 Feb 2008)

Log Message:
-----------
A contributed patch by Kazuho Oku, Cybozu labs.

This patch enable two new featrue.

One enables tritonn to embed primary key value into "key" which is
passed to senna, so this can dramatically reduce disk I/O if select
statement use only fulltext index and primary key.

The other feature enables tritonn to return TF score instead of
simple "number of found keyword in a certain document" which is
current implement and only implement.

You can read full description about this patch at following URL:

http://labs.cybozu.co.jp/blog/kazuho/archives/2008/02/triton-embed-primary-key.php

Modified Paths:
--------------
    tags/tritonn-1.1.0-mysql-5.0.51a/include/my_base.h
    tags/tritonn-1.1.0-mysql-5.0.51a/include/myisam.h
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_boolean_search.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_nlq_search.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_update.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_create.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_all.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_table.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_extra.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_open.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_rename.c
    tags/tritonn-1.1.0-mysql-5.0.51a/myisam/myisamdef.h
    tags/tritonn-1.1.0-mysql-5.0.51a/sql/ha_myisam.cc
    tags/tritonn-1.1.0-mysql-5.0.51a/sql/item_func.cc
    tags/tritonn-1.1.0-mysql-5.0.51a/sql/mysqld.cc
    tags/tritonn-1.1.0-mysql-5.0.51a/sql/set_var.cc
    tags/tritonn-1.1.0-mysql-5.0.51a/sql/sql_select.cc

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/include/my_base.h
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/include/my_base.h	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/include/my_base.h	2008-02-15
08:16:35 UTC (rev 109)
@@ -347,6 +347,7 @@
 #define SENNA_IF_READ_RECORD    (1 << 4)
 #define SENNA_DISTINCT          (1 << 5)
 #define SENNA_FIRST_CALL        (1 << 6)
+#define SENNA_ONLY_READ_PRIMARY_KEY (1 << 7)
 #endif

 /*

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/include/myisam.h
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/include/myisam.h	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/include/myisam.h	2008-02-15
08:16:35 UTC (rev 109)
@@ -36,6 +36,10 @@
 #include <senna.h>
 #define SEN_DISABLE_SENNA	0x80000000 /* Don't use Senna fulltext search
engine */
 extern sen_logger_info senna_logger;
+extern my_bool senna_use_embedded_pkey;
+# ifdef ENABLE_SENNA_PSEUDO_TF
+extern my_bool senna_use_pseudo_tf;
+# endif
 #endif /* ENABLE_SENNA */

 /*
@@ -215,6 +219,10 @@
   ulonglong senna_inv_chunk_size;
   sen_index *senna;
   sen_encoding senna_encoding;
+  int senna_embedded_pkey;
+# ifdef ENABLE_SENNA_PSEUDO_TF
+  int senna_use_pseudo_tf;
+# endif
 #endif /* ENABLE_SENNA */
   int (*bin_search)(struct st_myisam_info *info,struct st_mi_keydef
*keyinfo,
 		    uchar *page,uchar *key,
@@ -291,6 +299,11 @@
 extern int mi_delete(struct st_myisam_info *file,const byte *buff);
 extern struct st_myisam_info *mi_open(const char *name,int mode,
 				      uint wait_if_locked);
+#ifdef ENABLE_SENNA
+extern struct st_myisam_info *mi_open_senna(const char *name,int mode,
+					    uint wait_if_locked,
+					    int senna_embedded_pkey);
+#endif
 extern int mi_panic(enum ha_panic_function function);
 extern int mi_rfirst(struct st_myisam_info *file,byte *buf,int inx);
 extern int mi_rkey(struct st_myisam_info *file,byte *buf,int inx,

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_boolean_search.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_boolean_search.c
2008-02-15 06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_boolean_search.c
2008-02-15 08:16:35 UTC (rev 109)
@@ -606,22 +606,31 @@
 #ifdef ENABLE_SENNA
   if ((ftb->keynr != NO_SUCH_KEY) &&
ftb->info->s->keyinfo[ftb->keynr].senna)
   {
-    my_off_t pos;
+    SENNA_EMBEDDED_KEY skey;
+    int skey_len;
     MI_INFO   *info=ftb->info;
-    while (ftb->sir && sen_records_next(ftb->sir, &pos,
sizeof(my_off_t), NULL)) {
+    while (ftb->sir && (skey_len = sen_records_next(ftb->sir, &skey,
sizeof(skey), NULL))) {
       info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
-      info->lastpos=pos;
+      info->lastpos=skey.pos;
       if (my_thread_var->sen_flags & SENNA_USE_2IND) {
 	if (!(my_thread_var->sen_flags & (SENNA_IF_READ_RECORD |
SENNA_FILESORT))) {
 	  SEN_LOG(sen_log_debug, "ft_boolean_read_next: 2ind return 0");
 	  return 0;
 	}
       }
+      if (skey_len == sizeof(SENNA_EMBEDDED_KEY) &&
+	  info->s->keyinfo[ftb->keynr].senna_embedded_pkey != MAX_INDEXES &&
+	  (my_thread_var->sen_flags & SENNA_ONLY_READ_PRIMARY_KEY)) {
+	HA_KEYSEG *keyseg =
info->s->keyinfo[info->s->keyinfo[ftb->keynr].senna_embedded_pkey].seg;
+	memcpy(record + keyseg->start, &skey.pkey, keyseg->length);
+	info->update|= HA_STATE_AKTIV;          /* Record is read */
+	return 0;
+      } else
       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);
+      SEN_LOG(sen_log_error, "ft_boolean_read_next: my_errno=%d
pos=%lld", my_errno, skey.pos);
       if (my_errno == 127) { continue; }
       return my_errno;
     }
@@ -704,13 +713,21 @@
 #ifdef ENABLE_SENNA
   if ((ftb->keynr != NO_SUCH_KEY) &&
ftb->info->s->keyinfo[ftb->keynr].senna)
   {
-    my_off_t  docid=ftb->info->lastpos;
+    MYISAM_SHARE *share = ftb->info->s;
+    SENNA_EMBEDDED_KEY skey;
+    skey.pos=ftb->info->lastpos;
     if (!ftb->sir) { return 0.0; }
-    if (docid == HA_OFFSET_ERROR)
+    if (skey.pos == HA_OFFSET_ERROR)
       return -2.0;
+    skey.pkey=0;
+    if (share->keyinfo[ftb->keynr].senna_embedded_pkey != MAX_INDEXES) {
+      HA_KEYSEG *keyseg =
+	share->keyinfo[share->keyinfo[ftb->keynr].senna_embedded_pkey].seg;
+      memcpy(&skey.pkey, record + keyseg->start, keyseg->length);
+    }
     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);
+	    ftb->sir, &skey.pos);
+    return 1.0 * sen_records_find(ftb->sir, &skey);
   }
   else
 #endif /* ENABLE_SENNA */

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_nlq_search.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_nlq_search.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_nlq_search.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -34,6 +34,7 @@
   int       curdoc;
 #ifdef ENABLE_SENNA
   sen_records *sir;
+  int       senna_embedded_pkey;
 #endif /* ENABLE_SENNA */
   FT_DOC    doc[1];
 };
@@ -296,6 +297,7 @@

 #ifdef ENABLE_SENNA
   dlist->sir = sir;
+  dlist->senna_embedded_pkey = info->s->keyinfo[keynr].senna_embedded_pkey;
 #endif /* ENABLE_SENNA */
   tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy,
 	    &dptr, left_root_right);
@@ -317,24 +319,34 @@
 #ifdef ENABLE_SENNA
   if (handler->sir)
   {
-    my_off_t pos;
+    SENNA_EMBEDDED_KEY skey;
+    int skey_len;
     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))
+    while ((skey_len = sen_records_next(handler->sir, &skey,
sizeof(skey), NULL)) != 0)
     {
-      info->lastpos=pos;
+      info->lastpos=skey.pos;
       if (my_thread_var->sen_flags & SENNA_USE_2IND) {
 	if (!(my_thread_var->sen_flags & (SENNA_IF_READ_RECORD |
SENNA_FILESORT))) {
 	  SEN_LOG(sen_log_debug, "ft_nlq_read_next => 2ind return 0");
 	  return 0;
 	}
       }
+      if (skey_len == sizeof(SENNA_EMBEDDED_KEY) &&
+	  handler->senna_embedded_pkey != MAX_INDEXES &&
+	  (my_thread_var->sen_flags & SENNA_ONLY_READ_PRIMARY_KEY)) {
+	HA_KEYSEG *keyseg = info->s->keyinfo[handler->senna_embedded_pkey].seg;
+	memcpy(record + keyseg->start, &skey.pkey, keyseg->length);
+	info->update|= HA_STATE_AKTIV;          /* Record is read */
+	return 0;
+      }
+      else
       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);
+      SEN_LOG(sen_log_error, "ft_nlq_read_next => my_errno=%d
pos=%lld", my_errno, skey.pos);
       if (my_errno == 127) { continue; }
       return my_errno;
     }
@@ -373,9 +385,17 @@

 #ifdef ENABLE_SENNA
   if (handler->sir) {
+    MYISAM_SHARE *share = handler->info->s;
+    SENNA_EMBEDDED_KEY skey;
+    skey.pos = docid;
+    skey.pkey = 0;
+    if (handler->senna_embedded_pkey != MAX_INDEXES) {
+      HA_KEYSEG *keyseg = share->keyinfo[handler->senna_embedded_pkey].seg;
+      memcpy(&skey.pkey, record + keyseg->start, keyseg->length);
+    }
     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);
+    return 1.0 * sen_records_find(handler->sir, &skey);
   }
 #endif /* ENABLE_SENNA */


Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_update.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_update.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/ft_update.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -202,9 +202,20 @@

 #ifdef ENABLE_SENNA
 #define SECTIONALIZE 0x00080000
+# ifdef ENABLE_SENNA_PSEUDO_TF
+#define TF_WEIGHT(len) ((len) != 0 ? 0x40000000 / (len) : (len))
+# endif
 int ft_sen_index_add(MI_INFO *info, uint keynr, const byte *record,
my_off_t pos)
 {
+  SENNA_EMBEDDED_KEY skey;
   DBUG_ENTER("ft_sen_index_add");
+  skey.pos = pos;
+  skey.pkey = 0;
+  if (info->s->keyinfo[keynr].senna_embedded_pkey != MAX_INDEXES) {
+    HA_KEYSEG *keyseg =
+      info->s->keyinfo[info->s->keyinfo[keynr].senna_embedded_pkey].seg;
+    memcpy(&skey.pkey, record + keyseg->start, keyseg->length);
+  }
   if (info->s->keyinfo[keynr].senna_flags & SECTIONALIZE) {
     FT_SEG_ITERATOR ftsi;
     unsigned int section;
@@ -223,10 +234,16 @@
 	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_values_add(values, ftsi.pos, ftsi.len,
+# ifdef ENABLE_SENNA_PSEUDO_TF
+		       info->s->keyinfo[keynr].senna_use_pseudo_tf ?
TF_WEIGHT(ftsi.len) : 0
+# else
+		       0
+# endif
+		       );
 	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_index_update(info->s->keyinfo[keynr].senna, &skey, ftsi.num+1,
NULL, values);
 	SEN_LOG(sen_log_debug, "ft_sen_index_add => sen_values_close:
values=%p", values);
 	sen_values_close(values);
       }
@@ -257,7 +274,15 @@
     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));
+# ifdef ENABLE_SENNA_PSEUDO_TF
+    if (info->s->keyinfo[keynr].senna_use_pseudo_tf) {
+      sen_values *values = sen_values_open();
+      sen_values_add(values, buf, p - buf, TF_WEIGHT(p - buf));
+      sen_index_update(info->s->keyinfo[keynr].senna, &skey, 2, NULL,
values);
+      sen_values_close(values);
+    } else
+# endif
+      sen_index_upd(info->s->keyinfo[keynr].senna, &skey, NULL, 0, buf,
(p - buf));
     free(buf);
     DBUG_RETURN(0);
   }
@@ -265,6 +290,14 @@

 int ft_sen_index_del(MI_INFO *info, uint keynr, const byte *record,
my_off_t pos)
 {
+  SENNA_EMBEDDED_KEY skey;
+  skey.pos = pos;
+  skey.pkey = 0;
+  if (info->s->keyinfo[keynr].senna_embedded_pkey != MAX_INDEXES) {
+    HA_KEYSEG *keyseg =
+      info->s->keyinfo[info->s->keyinfo[keynr].senna_embedded_pkey].seg;
+    memcpy(&skey.pkey, record + keyseg->start, keyseg->length);
+  }
   if (info->s->keyinfo[keynr].senna_flags & SECTIONALIZE) {
     FT_SEG_ITERATOR ftsi;
     unsigned int section;
@@ -286,7 +319,7 @@
         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_index_update(info->s->keyinfo[keynr].senna, &skey, section,
values, NULL);
         SEN_LOG(sen_log_debug, "ft_sen_index_del => sen_values_close:
values=%p", values);
         sen_values_close(values);
       }
@@ -317,7 +350,7 @@
     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);
+    sen_index_upd(info->s->keyinfo[keynr].senna, &skey, buf, (p - buf),
NULL, 0);
     free(buf);
     return 0;
   }
@@ -532,7 +565,8 @@
           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 = sen_index_create(buf,
+						     share->keyinfo[i].senna_embedded_pkey != MAX_INDEXES ?
sizeof(SENNA_EMBEDDED_KEY) : sizeof(my_off_t),

share->keyinfo[i].senna_flags,

share->keyinfo[i].senna_initial_n_segments,

share->keyinfo[i].senna_encoding);

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_create.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_create.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_create.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -295,18 +295,31 @@
 	/* 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);
+		senna_use_embedded_pkey ? sizeof(SENNA_EMBEDDED_KEY) : 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),
+	senna = sen_index_create(buf,
+				 senna_use_embedded_pkey ? sizeof(SENNA_EMBEDDED_KEY) :
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);
+# ifdef ENABLE_SENNA_PSEUDO_TF
+	if (senna_use_pseudo_tf) {
+	  strcat(buf, ".tf");
+	  int fd = open(buf, O_WRONLY | O_CREAT, 0666);
+	  if (fd == -1) {
+	    my_errno = HA_ERR_CRASHED;
+	    goto err;
+	  }
+	  close(fd);
+	}
+# endif
       } else {
 	SEN_LOG(sen_log_notice, "mi_create => sen_index_open: path=%s", buf);
 	senna = sen_index_open(buf);
@@ -322,13 +335,15 @@
 	  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);
+		  senna_use_embedded_pkey ? sizeof(SENNA_EMBEDDED_KEY) :
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 = sen_index_create(buf,
+				   senna_use_embedded_pkey ? sizeof(SENNA_EMBEDDED_KEY) :
sizeof(my_off_t),
 				   senna_flags,
 				   senna_initial_n_segments,
 				   senna_encoding);

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_all.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_all.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_all.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -53,7 +53,8 @@
       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),
+      senna = sen_index_create(buf,
+			       share->keyinfo[i].senna_embedded_pkey != MAX_INDEXES ?
sizeof(SENNA_EMBEDDED_KEY) : sizeof(my_off_t),
 			       share->keyinfo[i].senna_flags,
 			       share->keyinfo[i].senna_initial_n_segments,
 			       share->keyinfo[i].senna_encoding);

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_table.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_table.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_delete_table.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -21,7 +21,11 @@

 int mi_delete_table(const char *name)
 {
+#ifdef ENABLE_SENNA_PSEUDO_TF
+  char from[FN_REFLEN + 3];
+#else
   char from[FN_REFLEN];
+#endif
 #ifdef USE_RAID
   uint raid_type=0,raid_chunks=0;
 #endif
@@ -80,6 +84,10 @@
       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);
+# ifdef ENABLE_SENNA_PSEUDO_TF
+      strcat(from, ".tf");
+      unlink(from);
+# endif
     }
   }
 #endif /* ENABLE_SENNA */

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_extra.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_extra.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_extra.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -199,6 +199,11 @@
     break;
   case HA_EXTRA_KEYREAD:			/* Read only keys to record */
   case HA_EXTRA_REMEMBER_POS:
+#ifdef ENABLE_SENNA
+    if (info->s->senna_has_embedded_pkey &&
+	(my_thread_var->sen_flags & SENNA_MATCH))
+      break;
+#endif
     info->opt_flag |= REMEMBER_OLD_POS;
     bmove((byte*) info->lastkey+share->base.max_key_length*2,
 	  (byte*) info->lastkey,info->lastkey_length);
@@ -210,6 +215,11 @@
       break;
     /* fall through */
   case HA_EXTRA_KEYREAD_CHANGE_POS:
+#ifdef ENABLE_SENNA
+    if (info->s->senna_has_embedded_pkey &&
+	(my_thread_var->sen_flags & SENNA_MATCH))
+      break;
+#endif
     info->opt_flag |= KEY_READ_USED;
     info->read_record=_mi_read_key_record;
     break;

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_open.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_open.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_open.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -31,6 +31,13 @@
 #include "static.c"
 #endif

+#ifdef ENABLE_SENNA
+my_bool senna_use_embedded_pkey;
+# ifdef ENABLE_SENNA_PSEUDO_TF
+my_bool senna_use_pseudo_tf;
+# endif
+#endif
+
 static void setup_key_functions(MI_KEYDEF *keyinfo);
 #define get_next_element(to,pos,size) { memcpy((char*) to,pos,(size_t)
size); \
 					pos+=size;}
@@ -73,7 +80,14 @@
 ******************************************************************************/

 MI_INFO *mi_open(const char *name, int mode, uint open_flags)
+#ifdef ENABLE_SENNA
 {
+  return mi_open_senna(name, mode, open_flags, MAX_INDEXES);
+}
+
+MI_INFO *mi_open_senna(const char *name, int mode, uint open_flags, int
senna_embedded_pkey)
+#endif
+{
   int lock_error,kfile,open_mode,save_errno,have_rtree=0;
   uint i,j,len,errpos,head_length,base_pos,offset,info_length,keys,
     key_parts,unique_key_parts,fulltext_keys,uniques;
@@ -348,6 +362,7 @@
 	share->keyinfo[i].senna = NULL;
 	share->keyinfo[i].senna_flags = 0;
 	share->keyinfo[i].senna_initial_n_segments = 0;
+	share->keyinfo[i].senna_embedded_pkey = MAX_INDEXES;
 #endif /* ENABLE_SENNA */
 	if (share->keyinfo[i].flag & HA_SPATIAL)
 	{
@@ -366,7 +381,13 @@
 	  if (!(share->keyinfo[i].senna_flags & SEN_DISABLE_SENNA))
 	  {
 	    {
+# ifdef ENABLE_SENNA_PSEUDO_TF
+	      char buf[FN_REFLEN + 3];
+	      struct stat st;
+# else
 	      char buf[FN_REFLEN];
+# endif
+	      int key_size;
 	      strncpy(buf, share->unique_file_name, FN_REFLEN - 1);
 	      buf[FN_REFLEN - 1] = '\0';
 	      sprintf(buf + strlen(buf) - 3, "%03d", i);
@@ -377,11 +398,18 @@
 		      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,
+	      sen_index_info(share->keyinfo[i].senna, &key_size,
 			     &share->keyinfo[i].senna_flags,
 			     &share->keyinfo[i].senna_initial_n_segments,
 			     &share->keyinfo[i].senna_encoding,
                              NULL, NULL, NULL, NULL, NULL, NULL);
+	      /* adjusted later on */
+	      if (key_size == sizeof(SENNA_EMBEDDED_KEY))
+		share->keyinfo[i].senna_embedded_pkey = senna_embedded_pkey;
+# ifdef ENABLE_SENNA_PSEUDO_TF
+	      strcat(buf, ".tf");
+	      share->keyinfo[i].senna_use_pseudo_tf = stat(buf, &st) == 0;
+# endif
 	    }
 	  }
 #endif /* ENABLE_SENNA */
@@ -427,6 +455,29 @@
 	pos->flag=0;					/* For purify */
 	pos++;
       }
+#ifdef ENABLE_SENNA
+      /* reset embedded pkey to MAX_KEY unless it fits in
SENNA_EMBEDDED_KEY */
+      share->senna_has_embedded_pkey = 0;
+      if (senna_embedded_pkey != MAX_INDEXES) {
+	switch (share->keyinfo[senna_embedded_pkey].seg[0].type) {
+	case HA_KEYTYPE_SHORT_INT:
+	case HA_KEYTYPE_LONG_INT:
+	case HA_KEYTYPE_FLOAT:
+	case HA_KEYTYPE_DOUBLE:
+	case HA_KEYTYPE_USHORT_INT:
+	case HA_KEYTYPE_ULONG_INT:
+	  /* supported types, ok */
+	  for (i = 0; i < keys; i++)
+	    if (share->keyinfo[i].senna_embedded_pkey != MAX_INDEXES)
+	      share->senna_has_embedded_pkey = 1;
+	  break;
+	default:
+	  for (i = 0; i < keys; i++)
+	    share->keyinfo[i].senna_embedded_pkey = MAX_INDEXES;
+	  break;
+	}
+      }
+#endif
       for (i=0 ; i < uniques ; i++)
       {
 	disk_pos=mi_uniquedef_read(disk_pos, &share->uniqueinfo[i]);

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_rename.c
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_rename.c	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/mi_rename.c	2008-02-15
08:16:35 UTC (rev 109)
@@ -21,7 +21,11 @@

 int mi_rename(const char *old_name, const char *new_name)
 {
+#ifdef ENABLE_SENNA_PSEUDO_TF
+  char from[FN_REFLEN + 3],to[FN_REFLEN + 3];
+#else
   char from[FN_REFLEN],to[FN_REFLEN];
+#endif
 #ifdef USE_RAID
   uint raid_type=0,raid_chunks=0;
 #endif
@@ -66,6 +70,11 @@
       my_snprintf(to, FN_REFLEN, "%s.%03d", new_name, senna_indexes[i]);
       SEN_LOG(sen_log_notice, "mi_rename => sen_index_rename: from=%s,
to=%s", from, to);
       sen_index_rename(from, to);
+# ifdef ENABLE_SENNA_PSEUDO_TF
+      strcat(from, ".tf");
+      strcat(to, ".tf");
+      rename(from, to);
+# endif
     }
   }
 #endif /* ENABLE_SENNA */

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/myisam/myisamdef.h
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/myisam/myisamdef.h	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/myisam/myisamdef.h	2008-02-15
08:16:35 UTC (rev 109)
@@ -208,6 +208,9 @@
   pthread_mutex_t intern_lock;		/* Locking for use with _locking */
   rw_lock_t *key_root_lock;
 #endif
+#ifdef ENABLE_SENNA
+  int senna_has_embedded_pkey;
+#endif
 } MYISAM_SHARE;


@@ -365,6 +368,15 @@
 #define READING_NEXT	1
 #define READING_HEADER	2

+#ifdef ENABLE_SENNA
+
+typedef struct st_senna_embedded_key {
+  my_off_t pos;
+  my_off_t pkey; /* used to store primary key if length<8 bytes */
+} SENNA_EMBEDDED_KEY;
+
+#endif
+
 #define mi_getint(x)	((uint) mi_uint2korr(x) & 32767)
 #define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) +
(uint16) (y);\
 			  mi_int2store(x,boh); }

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/sql/ha_myisam.cc
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/sql/ha_myisam.cc	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/sql/ha_myisam.cc	2008-02-15
08:16:35 UTC (rev 109)
@@ -683,8 +683,18 @@

 int ha_myisam::open(const char *name, int mode, uint test_if_locked)
 {
+#ifdef ENABLE_SENNA
+  int embedded_pkey = MAX_KEY;
+  if (table->key_info && /* seems to be NULL w. pkey set to 0 on temp
tbl */
+      table->key_info[table->s->primary_key].key_parts == 1) {
+    embedded_pkey = table->s->primary_key;
+  }
+  if (!(file=mi_open_senna(name, mode, test_if_locked, embedded_pkey)))
+    return (my_errno ? my_errno : -1);
+#else
   if (!(file=mi_open(name, mode, test_if_locked)))
     return (my_errno ? my_errno : -1);
+#endif

   if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE))
     VOID(mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0));

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/sql/item_func.cc
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/sql/item_func.cc	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/sql/item_func.cc	2008-02-15
08:16:35 UTC (rev 109)
@@ -4909,12 +4909,22 @@
     modifications to find_best and auto_close as complement to
auto_init code
     above.
    */
+#ifdef ENABLE_SENNA
+  bool save_set_query_id = thd->set_query_id;
+  thd->set_query_id = 0;
+#endif
   if (Item_func::fix_fields(thd, ref) ||
       !args[0]->const_during_execution())
   {
     my_error(ER_WRONG_ARGUMENTS,MYF(0),"AGAINST");
+#ifdef ENABLE_SENNA
+    thd->set_query_id = save_set_query_id;
+#endif
     return TRUE;
   }
+#ifdef ENABLE_SENNA
+  thd->set_query_id = save_set_query_id;
+#endif

   const_item_cache=0;
   for (uint i=1 ; i < arg_count ; i++)

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/sql/mysqld.cc
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/sql/mysqld.cc	2008-02-15 06:43:05
UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/sql/mysqld.cc	2008-02-15 08:16:35
UTC (rev 109)
@@ -4894,6 +4894,10 @@
   OPT_SENNA_LOG_LEVEL,
   OPT_SENNA_2IND,
   OPT_SENNA_INDEX_TYPE,
+  OPT_SENNA_EMBEDDED_PKEY,
+# ifdef ENABLE_SENNA_PSEUDO_TF
+  OPT_SENNA_PSEUDO_TF,
+# endif
 #endif
   OPT_PROFILING,
   OPT_INNODB_ROLLBACK_ON_TIMEOUT,
@@ -5573,6 +5577,16 @@
   {"senna-log-level", OPT_SENNA_LOG_LEVEL, "Senna log level.",
    (gptr*) &opt_senna_log_level, (gptr*) &opt_senna_log_level, 0,
GET_STR, REQUIRED_ARG,
    0, 0, 0, 0, 0, 0},
+  {"senna-embedded-pkey", OPT_SENNA_EMBEDDED_PKEY, "Embed primary key
value to senna index.",
+   (gptr*) &senna_use_embedded_pkey,
+   (gptr*) &senna_use_embedded_pkey,
+   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+# ifdef ENABLE_SENNA_PSEUDO_TF
+  {"senna-pseudo-tf", OPT_SENNA_EMBEDDED_PKEY, "Use TF-like algorithm
for calculationg relevance.",
+   (gptr*) &senna_use_pseudo_tf,
+   (gptr*) &senna_use_pseudo_tf,
+   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+# endif
 #endif
   {"secure-file-priv", OPT_SECURE_FILE_PRIV,
    "Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files
within specified directory",
@@ -6847,6 +6861,10 @@
   opt_senna_log = 0;
   senna_log_level_options = senna_logger.max_level;
   global_system_variables.senna_2ind = 0;
+  senna_use_embedded_pkey = 0;
+# ifdef ENABLE_SENNA_PSEUDO_TF
+  senna_use_pseudo_tf = 0;
+# endif
 #endif

 #if defined(__WIN__) || defined(__NETWARE__)
@@ -7485,6 +7503,14 @@
   case OPT_SENNA_2IND:
     global_system_variables.senna_2ind = 1;
     break;
+  case OPT_SENNA_EMBEDDED_PKEY:
+    senna_use_embedded_pkey = 1;
+    break;
+# ifdef ENABLE_SENNA_PSEUDO_TF
+  case OPT_SENNA_PSEUDO_TF:
+    senna_use_pseudo_tf = 1;
+    break;
+# endif
 #endif
   }
   return 0;

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/sql/set_var.cc
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/sql/set_var.cc	2008-02-15 06:43:05
UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/sql/set_var.cc	2008-02-15 08:16:35
UTC (rev 109)
@@ -483,6 +483,10 @@
 sys_var_enum
sys_senna_log_level("senna_log_level",&senna_log_level_options,
 					    &senna_log_level_typelib, fix_senna_log_level);
 sys_var_thd_bool        sys_senna_2ind("senna_2ind", &SV::senna_2ind,
fix_senna_2ind);
+sys_var_bool_ptr        sys_senna_embedded_pkey("senna_embedded_pkey",
&senna_use_embedded_pkey);
+# ifdef ENABLE_SENNA_PSEUDO_TF
+sys_var_bool_ptr        sys_senna_pseudo_tf("senna_pseudo_tf",
&senna_use_pseudo_tf);
+# endif
 #endif

 /* Condition pushdown to storage engine */
@@ -774,6 +778,10 @@
   &sys_senna_2ind,
   &sys_senna_index_type,
   &sys_senna_log_level,
+  &sys_senna_embedded_pkey,
+# ifdef ENABLE_SENNA_PSEUDO_TF
+  &sys_senna_pseudo_tf,
+# endif
 #endif
   &sys_server_id,
 #ifdef HAVE_REPLICATION
@@ -1095,9 +1103,13 @@
   {"secure_file_priv",        (char*) &sys_secure_file_priv,
SHOW_SYS},
 #ifdef ENABLE_SENNA
   {"senna_2ind",              (char*) &sys_senna_2ind,
SHOW_SYS},
+  {"senna_embedded_pkey",     (char*) &sys_senna_embedded_pkey,
SHOW_SYS},
   {"senna_index_type",        (char*) &sys_senna_index_type,
SHOW_SYS},
   {"senna_log",               (char*) &opt_senna_log,
SHOW_MY_BOOL},
   {"senna_log_level",         (char*) &sys_senna_log_level,
SHOW_SYS},
+# ifdef ENABLE_SENNA_PSEUDO_TF
+  {"senna_pseudo_tf",         (char*) &sys_senna_pseudo_tf,
SHOW_SYS},
+# endif
 #endif
 #ifdef HAVE_SMEM
   {"shared_memory",           (char*) &opt_enable_shared_memory,
SHOW_MY_BOOL},

Modified: tags/tritonn-1.1.0-mysql-5.0.51a/sql/sql_select.cc
===================================================================
--- tags/tritonn-1.1.0-mysql-5.0.51a/sql/sql_select.cc	2008-02-15
06:43:05 UTC (rev 108)
+++ tags/tritonn-1.1.0-mysql-5.0.51a/sql/sql_select.cc	2008-02-15
08:16:35 UTC (rev 109)
@@ -2290,8 +2290,8 @@
     }
   }
 #ifdef ENABLE_SENNA
+  if (select_lex->ftfunc_list->elements) {my_thread_var->sen_flags |=
SENNA_MATCH; } /* the flag is used to prevent the use of keyread in
mi_extra.c */
   if (my_thread_var->sen_flags & SENNA_USE_2IND) {
-    if (select_lex->ftfunc_list->elements) {my_thread_var->sen_flags |=
SENNA_MATCH; }
     if (join->select_distinct) { my_thread_var->sen_flags |=
SENNA_DISTINCT; }
   }
 #endif /* ENABLE_SENNA */
@@ -6187,6 +6187,18 @@
 #ifdef ENABLE_SENNA
       if (my_thread_var->sen_flags & SENNA_USE_2IND)
 	my_thread_var->sen_flags |= SENNA_DO_READ_RECORD;
+      if (!table->no_keyread && table->s->primary_key != MAX_KEY) {
+	KEY *pkey = table->key_info + table->s->primary_key;
+	if (pkey->key_parts == 1) {
+	  for (Field **field = table->field; *field != NULL; field++)
+	    if ((*field)->query_id == join->thd->query_id &&
+		*field != pkey->key_part[0].field)
+	      goto SENNA_END_PRIMARY_KEY_OPTIMIZATION;
+	  my_thread_var->sen_flags |= SENNA_ONLY_READ_PRIMARY_KEY;
+	SENNA_END_PRIMARY_KEY_OPTIMIZATION:
+	  ;
+	}
+      }
 #endif /* ENABLE_SENNA */
       break;
     case JT_ALL:

_______________________________________________
Tritonn-commit mailing list
Trito****@lists*****
http://lists.sourceforge.jp/mailman/listinfo/tritonn-commit




Tritonn-dev メーリングリストの案内
Back to archive index