[Groonga-commit] groonga/groonga at 7318a5d [master] Extract codes for finding an index in scan_info_build()

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Mar 3 17:51:19 JST 2014


Kouhei Sutou	2014-03-03 17:51:19 +0900 (Mon, 03 Mar 2014)

  New Revision: 7318a5de310fb23f47b99b292e0634117cb3cc38
  https://github.com/groonga/groonga/commit/7318a5de310fb23f47b99b292e0634117cb3cc38

  Message:
    Extract codes for finding an index in scan_info_build()

  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+58 -15)
===================================================================
--- lib/expr.c    2014-03-03 17:37:14 +0900 (7ddcacb)
+++ lib/expr.c    2014-03-03 17:51:19 +0900 (46baf69)
@@ -4294,6 +4294,52 @@ grn_scan_info_get_arg(grn_ctx *ctx, scan_info *si, int i)
   return si->args[i];
 }
 
+static uint32_t
+scan_info_build_find_index_column_forward_index(grn_ctx *ctx,
+                                                scan_info *si,
+                                                grn_expr_code *ec,
+                                                uint32_t n_rest_codes,
+                                                grn_operator op)
+{
+  uint32_t offset = 0;
+  grn_obj *index;
+  int sid;
+
+  if (grn_column_index(ctx, ec->value, op, &index, 1, &sid)) {
+    scan_info_put_index(ctx, si, index, sid, get_weight(ctx, ec));
+  }
+
+  return offset;
+}
+
+static uint32_t
+scan_info_build_find_index_column_inverted_index(grn_ctx *ctx,
+                                                 scan_info *si,
+                                                 grn_expr_code *ec,
+                                                 uint32_t n_rest_codes,
+                                                 grn_operator op)
+{
+  uint32_t offset = 0;
+  grn_obj *index;
+  int sid = 0;
+  int32_t weight = 0;
+
+  index = ec->value;
+  if (n_rest_codes > 2 &&
+      ec[1].value &&
+      ec[1].value->header.domain == GRN_DB_UINT32 &&
+      ec[2].op == GRN_OP_GET_MEMBER) {
+    sid = GRN_UINT32_VALUE(ec[1].value) + 1;
+    offset = 2;
+    weight = get_weight(ctx, ec + offset);
+  } else {
+    weight = get_weight(ctx, ec);
+  }
+  scan_info_put_index(ctx, si, index, sid, weight);
+
+  return offset;
+}
+
 static scan_info **
 scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
                 grn_operator op, uint32_t size)
@@ -4426,22 +4472,19 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
                   }
                   break;
                 case GRN_COLUMN_INDEX :
-                  if (GRN_OBJ_FORWARD_INDEX_COLUMNP(ec->value)) {
-                    if (grn_column_index(ctx, ec->value, c->op, &index, 1, &sid)) {
-                      scan_info_put_index(ctx, si, index, sid, get_weight(ctx, ec));
-                    }
-                  } else {
-                    sid = 0;
-                    index = ec->value;
-                    if (j > 2 &&
-                        ec[1].value &&
-                        ec[1].value->header.domain == GRN_DB_UINT32 &&
-                        ec[2].op == GRN_OP_GET_MEMBER) {
-                      sid = GRN_UINT32_VALUE(ec[1].value) + 1;
-                      j -= 2;
-                      ec += 2;
+                  {
+                    uint32_t offset;
+                    if (GRN_OBJ_FORWARD_INDEX_COLUMNP(ec->value)) {
+                      offset =
+                        scan_info_build_find_index_column_forward_index(
+                          ctx, si, ec, j, c->op);
+                    } else {
+                      offset =
+                        scan_info_build_find_index_column_inverted_index(
+                          ctx, si, ec, j, c->op);
                     }
-                    scan_info_put_index(ctx, si, index, sid, get_weight(ctx, ec));
+                    j -= offset;
+                    ec += offset;
                   }
                   break;
                 }
-------------- next part --------------
HTML����������������������������...
Download 



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