[Groonga-commit] groonga/groonga at cd984b1 [master] Fix a bug that wrong section is used

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Mar 2 23:28:20 JST 2015


Kouhei Sutou	2015-03-02 23:28:20 +0900 (Mon, 02 Mar 2015)

  New Revision: cd984b157a9f346b916272023f5b0e2ea2148d76
  https://github.com/groonga/groonga/commit/cd984b157a9f346b916272023f5b0e2ea2148d76

  Message:
    Fix a bug that wrong section is used
    
    It may be occurred when all of the following conditions are true:
    
      1. Multiple indexes are available.
      2. The first defined index and/or the last defined index
         are multi-column indexes.
      3. When both of the first defined index and the last defined index are
         multi-column indexes:
         * Source columns orders are different in them.

  Added files:
    test/command/suite/select/index/multi_column/multiple_indexes.expected
    test/command/suite/select/index/multi_column/multiple_indexes.test
  Modified files:
    lib/expr.c
    lib/mrb/mrb_object.c

  Modified: lib/expr.c (+63 -19)
===================================================================
--- lib/expr.c    2015-03-02 23:26:29 +0900 (e6a8234)
+++ lib/expr.c    2015-03-02 23:28:20 +0900 (76a32c3)
@@ -4258,19 +4258,31 @@ scan_info_build_match_expr_codes_find_index(grn_ctx *ctx, scan_info *si,
 {
   grn_expr_code *ec;
   uint32_t offset = 1;
+  grn_index_datum index_datum;
+  unsigned int n_index_data = 0;
 
   ec = &(expr->codes[i]);
   switch (ec->value->header.type) {
   case GRN_ACCESSOR :
-    if (grn_column_index(ctx, ec->value, si->op, index, 1, sid)) {
+    n_index_data = grn_column_find_index_data(ctx, ec->value, si->op,
+                                              &index_datum, 1);
+    if (n_index_data > 0) {
+      *sid = index_datum.section;
       if (((grn_accessor *)ec->value)->next) {
         *index = ec->value;
+      } else {
+        *index = index_datum.index;
       }
     }
     break;
   case GRN_COLUMN_FIX_SIZE :
   case GRN_COLUMN_VAR_SIZE :
-    grn_column_index(ctx, ec->value, si->op, index, 1, sid);
+    n_index_data = grn_column_find_index_data(ctx, ec->value, si->op,
+                                              &index_datum, 1);
+    if (n_index_data > 0) {
+        *index = index_datum.index;
+      *sid = index_datum.section;
+    }
     break;
   case GRN_COLUMN_INDEX :
     {
@@ -4393,23 +4405,36 @@ scan_info_build_match_expr(grn_ctx *ctx, scan_info *si, grn_expr *expr)
 static void
 scan_info_build_match(grn_ctx *ctx, scan_info *si)
 {
-  int sid;
-  grn_obj *index, **p = si->args, **pe = si->args + si->nargs;
+  grn_obj **p = si->args, **pe = si->args + si->nargs;
   for (; p < pe; p++) {
     if ((*p)->header.type == GRN_EXPR) {
       scan_info_build_match_expr(ctx, si, (grn_expr *)(*p));
     } else if (GRN_DB_OBJP(*p)) {
-      if (grn_column_index(ctx, *p, si->op, &index, 1, &sid)) {
-        scan_info_put_index(ctx, si, index, sid, 1, NULL, NULL, 0);
+      grn_index_datum index_datum;
+      unsigned int n_index_data;
+      n_index_data = grn_column_find_index_data(ctx, *p, si->op,
+                                                &index_datum, 1);
+      if (n_index_data > 0) {
+        scan_info_put_index(ctx, si,
+                            index_datum.index, index_datum.section, 1,
+                            NULL, NULL, 0);
       }
     } else if (GRN_ACCESSORP(*p)) {
+      grn_index_datum index_datum;
+      unsigned int n_index_data;
       si->flags |= SCAN_ACCESSOR;
-      if (grn_column_index(ctx, *p, si->op, &index, 1, &sid)) {
+      n_index_data = grn_column_find_index_data(ctx, *p, si->op,
+                                                &index_datum, 1);
+      if (n_index_data > 0) {
+        grn_obj *index;
         if (((grn_accessor *)(*p))->next) {
-          scan_info_put_index(ctx, si, *p, sid, 1, NULL, NULL, 0);
+          index = *p;
         } else {
-          scan_info_put_index(ctx, si, index, sid, 1, NULL, NULL, 0);
+          index = index_datum.index;
         }
+        scan_info_put_index(ctx, si,
+                            index, index_datum.section, 1,
+                            NULL, NULL, 0);
       }
     } else {
       switch (si->op) {
@@ -4634,17 +4659,28 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
         sis[i++] = si;
         /* better index resolving framework for functions should be implemented */
         {
-          int sid;
-          grn_obj *index, **p = si->args, **pe = si->args + si->nargs;
+          grn_obj **p = si->args, **pe = si->args + si->nargs;
           for (; p < pe; p++) {
             if (GRN_DB_OBJP(*p)) {
-              if (grn_column_index(ctx, *p, c->op, &index, 1, &sid)) {
-                scan_info_put_index(ctx, si, index, sid, 1, NULL, NULL, 0);
+              grn_index_datum index_datum;
+              unsigned int n_index_data;
+              n_index_data = grn_column_find_index_data(ctx, *p, c->op,
+                                                        &index_datum, 1);
+              if (n_index_data > 0) {
+                scan_info_put_index(ctx, si,
+                                    index_datum.index, index_datum.section, 1,
+                                    NULL, NULL, 0);
               }
             } else if (GRN_ACCESSORP(*p)) {
+              grn_index_datum index_datum;
+              unsigned int n_index_data;
               si->flags |= SCAN_ACCESSOR;
-              if (grn_column_index(ctx, *p, c->op, &index, 1, &sid)) {
-                scan_info_put_index(ctx, si, index, sid, 1, NULL, NULL, 0);
+              n_index_data = grn_column_find_index_data(ctx, *p, c->op,
+                                                        &index_datum, 1);
+              if (n_index_data > 0) {
+                scan_info_put_index(ctx, si,
+                                    index_datum.index, index_datum.section, 1,
+                                    NULL, NULL, 0);
               }
             } else {
               si->query = *p;
@@ -4986,10 +5022,18 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table,
 
       accessor = (grn_accessor *)GRN_PTR_VALUE_AT(accessor_stack, i - 1);
       target = accessor->obj;
-      if (grn_column_index(ctx, target, GRN_OP_EQUAL, &index, 1, &section) == 0) {
-        grn_obj_unlink(ctx, current_res);
-        current_res = NULL;
-        break;
+      {
+        grn_index_datum index_datum;
+        unsigned int n_index_data;
+        n_index_data = grn_column_find_index_data(ctx, target, GRN_OP_EQUAL,
+                                                  &index_datum, 1);
+        if (n_index_data == 0) {
+          grn_obj_unlink(ctx, current_res);
+          current_res = NULL;
+          break;
+        }
+        index = index_datum.index;
+        section = index_datum.section;
       }
 
       if (section > 0) {

  Modified: lib/mrb/mrb_object.c (+10 -12)
===================================================================
--- lib/mrb/mrb_object.c    2015-03-02 23:26:29 +0900 (dc88b72)
+++ lib/mrb/mrb_object.c    2015-03-02 23:28:20 +0900 (8efaa41)
@@ -91,20 +91,18 @@ object_find_index(mrb_state *mrb, mrb_value self)
   grn_obj *object;
   mrb_value mrb_operator;
   grn_operator operator;
-  grn_obj *index;
-  int n_indexes;
-  int section_id;
+  grn_index_datum index_datum;
+  int n_index_data;
 
   mrb_get_args(mrb, "o", &mrb_operator);
   object = DATA_PTR(self);
   operator = grn_mrb_value_to_operator(mrb, mrb_operator);
-  n_indexes = grn_column_index(ctx,
-                               object,
-                               operator,
-                               &index,
-                               1,
-                               &section_id);
-  if (n_indexes == 0) {
+  n_index_data = grn_column_find_index_data(ctx,
+                                         object,
+                                         operator,
+                                         &index_datum,
+                                         1);
+  if (n_index_data == 0) {
     return mrb_nil_value();
   } else {
     grn_mrb_data *data;
@@ -113,8 +111,8 @@ object_find_index(mrb_state *mrb, mrb_value self)
 
     data = &(ctx->impl->mrb);
     klass = mrb_class_get_under(mrb, data->module, "IndexInfo");
-    args[0] = grn_mrb_value_from_grn_obj(mrb, index);
-    args[1] = mrb_fixnum_value(section_id);
+    args[0] = grn_mrb_value_from_grn_obj(mrb, index_datum.index);
+    args[1] = mrb_fixnum_value(index_datum.section);
     return mrb_obj_new(mrb, klass, 2, args);
   }
 }

  Added: test/command/suite/select/index/multi_column/multiple_indexes.expected (+33 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/index/multi_column/multiple_indexes.expected    2015-03-02 23:28:20 +0900 (84c2304)
@@ -0,0 +1,33 @@
+table_create Bigram TABLE_PAT_KEY ShortText   --default_tokenizer TokenBigramSplitSymbolAlpha   --normalizer NormalizerAuto
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos title COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+column_create Memos content COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+column_create Bigram memos1   COLUMN_INDEX|WITH_POSITION|WITH_SECTION   Memos title,content
+[[0,0.0,0.0],true]
+column_create Bigram memos2   COLUMN_INDEX|WITH_POSITION|WITH_SECTION   Memos content,title
+[[0,0.0,0.0],true]
+load --table Memos
+[
+  {
+    "_key": "2013-02-06",
+    "title": "Groonga",
+    "content": "It's a fast fulltext search engine!"
+  },
+  {
+    "_key": "2013-02-07",
+    "title": "Mroonga",
+    "content": "It's a MySQL storage engine to use Groonga!"
+  },
+  {
+    "_key": "2013-02-08",
+    "title": "Rroonga",
+    "content": "It's Rroonga bindings for Groonga!"
+  }
+]
+[[0,0.0,0.0],3]
+select Memos   --match_columns 'title'   --query 'Groonga'   --output_columns 'title,_score'
+[[0,0.0,0.0],[[[1],[["title","ShortText"],["_score","Int32"]],["Groonga",1]]]]

  Added: test/command/suite/select/index/multi_column/multiple_indexes.test (+38 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/index/multi_column/multiple_indexes.test    2015-03-02 23:28:20 +0900 (c145797)
@@ -0,0 +1,38 @@
+table_create Bigram TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigramSplitSymbolAlpha \
+  --normalizer NormalizerAuto
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos title COLUMN_SCALAR ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+column_create Bigram memos1 \
+  COLUMN_INDEX|WITH_POSITION|WITH_SECTION \
+  Memos title,content
+column_create Bigram memos2 \
+  COLUMN_INDEX|WITH_POSITION|WITH_SECTION \
+  Memos content,title
+
+load --table Memos
+[
+  {
+    "_key": "2013-02-06",
+    "title": "Groonga",
+    "content": "It's a fast fulltext search engine!"
+  },
+  {
+    "_key": "2013-02-07",
+    "title": "Mroonga",
+    "content": "It's a MySQL storage engine to use Groonga!"
+  },
+  {
+    "_key": "2013-02-08",
+    "title": "Rroonga",
+    "content": "It's Rroonga bindings for Groonga!"
+  }
+]
+
+select Memos \
+  --match_columns 'title' \
+  --query 'Groonga' \
+  --output_columns 'title,_score'
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index