[Groonga-commit] groonga/groonga at 8b077e8 [master] Support index search for 'vector_column[2] == 99'

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Feb 6 00:06:05 JST 2016


Kouhei Sutou	2016-02-06 00:06:05 +0900 (Sat, 06 Feb 2016)

  New Revision: 8b077e8f51ee7201b459322ca91c74df8d5aa940
  https://github.com/groonga/groonga/commit/8b077e8f51ee7201b459322ca91c74df8d5aa940

  Message:
    Support index search for 'vector_column[2] == 99'

  Added files:
    test/command/suite/select/filter/index/compare_operation/equal/vector_element_int32.expected
    test/command/suite/select/filter/index/compare_operation/equal/vector_element_int32.test
  Modified files:
    lib/expr.c
    lib/mrb/scripts/scan_info.rb
    lib/mrb/scripts/scan_info_builder.rb
    lib/mrb/scripts/scan_info_data.rb

  Modified: lib/expr.c (+72 -5)
===================================================================
--- lib/expr.c    2016-02-06 00:05:12 +0900 (069c92d)
+++ lib/expr.c    2016-02-06 00:06:05 +0900 (9ce1963)
@@ -4544,6 +4544,33 @@ grn_scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
         stat = SCAN_COL2;
       }
       break;
+    case GRN_OP_GET_REF :
+      switch (stat) {
+      case SCAN_START :
+        stat = SCAN_COL1;
+        break;
+      default :
+        return NULL;
+        break;
+      }
+      break;
+    case GRN_OP_GET_MEMBER :
+      switch (stat) {
+      case SCAN_CONST :
+        {
+          grn_expr_code *prev_c = c - 1;
+          if (prev_c->value->header.domain < GRN_DB_INT8 &&
+              prev_c->value->header.domain > GRN_DB_UINT64) {
+            return NULL;
+          }
+        }
+        stat = SCAN_COL1;
+        break;
+      default :
+        return NULL;
+        break;
+      }
+      break;
     default :
       return NULL;
       break;
@@ -4683,6 +4710,31 @@ grn_scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
         stat = SCAN_COL2;
       }
       break;
+    case GRN_OP_GET_REF :
+      switch (stat) {
+      case SCAN_START :
+        if (!si) { SI_ALLOC(si, i, c - e->codes); }
+        stat = SCAN_COL1;
+        if (si->nargs < GRN_SCAN_INFO_MAX_N_ARGS) {
+          si->args[si->nargs++] = c->value;
+        }
+        break;
+      default :
+        break;
+      }
+      break;
+    case GRN_OP_GET_MEMBER :
+      {
+        grn_obj *start_position;
+        grn_obj buffer;
+        start_position = si->args[--si->nargs];
+        GRN_INT32_INIT(&buffer, 0);
+        grn_obj_cast(ctx, start_position, &buffer, GRN_FALSE);
+        grn_scan_info_set_start_position(si, GRN_INT32_VALUE(&buffer));
+        GRN_OBJ_FIN(ctx, &buffer);
+      }
+      stat = SCAN_COL1;
+      break;
     default :
       break;
     }
@@ -5759,12 +5811,27 @@ grn_table_select_index(grn_ctx *ctx, grn_obj *table, scan_info *si,
             if (ii_cursor) {
               grn_posting *posting;
               while ((posting = grn_ii_cursor_next(ctx, ii_cursor))) {
-                if (sid == 0 || posting->sid == sid) {
-                  grn_posting new_posting = *posting;
-                  new_posting.weight *= weight;
-                  grn_ii_posting_add(ctx, &new_posting, (grn_hash *)res,
-                                     si->logical_op);
+                grn_posting new_posting;
+
+                if (!(sid == 0 || posting->sid == sid)) {
+                  continue;
                 }
+
+                if (si->position.specified) {
+                  while ((posting = grn_ii_cursor_next_pos(ctx, ii_cursor))) {
+                    if (posting->pos == si->position.start) {
+                      break;
+                    }
+                  }
+                  if (!posting) {
+                    continue;
+                  }
+                }
+
+                new_posting = *posting;
+                new_posting.weight *= weight;
+                grn_ii_posting_add(ctx, &new_posting, (grn_hash *)res,
+                                   si->logical_op);
               }
               grn_ii_cursor_close(ctx, ii_cursor);
               processed = GRN_TRUE;

  Modified: lib/mrb/scripts/scan_info.rb (+3 -0)
===================================================================
--- lib/mrb/scripts/scan_info.rb    2016-02-06 00:05:12 +0900 (a98cf79)
+++ lib/mrb/scripts/scan_info.rb    2016-02-06 00:06:05 +0900 (acdb2ee)
@@ -30,6 +30,9 @@ module Groonga
                   search_index.scorer_args_expr,
                   search_index.scorer_args_expr_offset || 0)
       end
+      if data.start_position
+        self.start_position = data.start_position
+      end
     end
   end
 end

  Modified: lib/mrb/scripts/scan_info_builder.rb (+28 -1)
===================================================================
--- lib/mrb/scripts/scan_info_builder.rb    2016-02-06 00:05:12 +0900 (cbfaebd)
+++ lib/mrb/scripts/scan_info_builder.rb    2016-02-06 00:06:05 +0900 (41efb01)
@@ -117,6 +117,18 @@ module Groonga
           else
             status = Status::COL2
           end
+        when Operator::GET_REF
+          data ||= ScanInfoData.new(i)
+          case status
+          when Status::START
+            data ||= ScanInfoData.new(i)
+            status = Status::COL1
+            data.args << code.value
+          end
+        when Operator::GET_MEMBER
+          index = data.args.pop
+          data.start_position = index.value
+          status = Status::COL1
         end
       end
 
@@ -143,7 +155,7 @@ module Groonga
       status = Status::START
       variable = @expression[0]
       codes =****@expre*****
-      codes.each do |code|
+      codes.each_with_index do |code, i|
         case code.op
         when *RELATION_OPERATORS
           return false if status < Status::COL1
@@ -184,6 +196,21 @@ module Groonga
           else
             status = Status::COL2
           end
+        when Operator::GET_REF
+          case status
+          when Status::START
+            status = Status::COL1
+          else
+            return false
+          end
+        when Operator::GET_MEMBER
+          case status
+          when Status::CONST
+            return false unless codes[i - 1].value.value.is_a?(Integer)
+            status = Status::COL1
+          else
+            return false
+          end
         else
           return false
         end

  Modified: lib/mrb/scripts/scan_info_data.rb (+2 -0)
===================================================================
--- lib/mrb/scripts/scan_info_data.rb    2016-02-06 00:05:12 +0900 (7f22532)
+++ lib/mrb/scripts/scan_info_data.rb    2016-02-06 00:06:05 +0900 (e46bbe7)
@@ -12,6 +12,7 @@ module Groonga
     attr_accessor :flags
     attr_accessor :max_interval
     attr_accessor :similarity_threshold
+    attr_accessor :start_position
     def initialize(start)
       @start = start
       @end = 0
@@ -23,6 +24,7 @@ module Groonga
       @flags = ScanInfo::Flags::PUSH
       @max_interval = nil
       @similarity_threshold = nil
+      @start_position = nil
     end
 
     def match_resolve_index

  Added: test/command/suite/select/filter/index/compare_operation/equal/vector_element_int32.expected (+17 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/index/compare_operation/equal/vector_element_int32.expected    2016-02-06 00:06:05 +0900 (10fffed)
@@ -0,0 +1,17 @@
+table_create Values TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Values numbers COLUMN_VECTOR Int32
+[[0,0.0,0.0],true]
+table_create Numbers TABLE_PAT_KEY Int32
+[[0,0.0,0.0],true]
+column_create Numbers values_numbers COLUMN_INDEX|WITH_POSITION Values numbers
+[[0,0.0,0.0],true]
+load --table Values
+[
+{"numbers": [2, 1, 3]},
+{"numbers": [2, 3, 4]},
+{"numbers": [3, 9, -1]}
+]
+[[0,0.0,0.0],3]
+select Values   --filter 'numbers[1] == 3'   --output_columns 'numbers'
+[[0,0.0,0.0],[[[1],[["numbers","Int32"]],[[2,3,4]]]]]

  Added: test/command/suite/select/filter/index/compare_operation/equal/vector_element_int32.test (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/index/compare_operation/equal/vector_element_int32.test    2016-02-06 00:06:05 +0900 (5581561)
@@ -0,0 +1,16 @@
+table_create Values TABLE_NO_KEY
+column_create Values numbers COLUMN_VECTOR Int32
+
+table_create Numbers TABLE_PAT_KEY Int32
+column_create Numbers values_numbers COLUMN_INDEX|WITH_POSITION Values numbers
+
+load --table Values
+[
+{"numbers": [2, 1, 3]},
+{"numbers": [2, 3, 4]},
+{"numbers": [3, 9, -1]}
+]
+
+select Values \
+  --filter 'numbers[1] == 3' \
+  --output_columns 'numbers'
-------------- next part --------------
HTML����������������������������...
下載 



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