[Groonga-commit] groonga/groonga [master] Force index zero value

Back to archive index

Daijiro MORI null+****@clear*****
Fri Mar 8 14:06:34 JST 2013


Daijiro MORI	2013-03-08 14:06:34 +0900 (Fri, 08 Mar 2013)

  New Revision: 3cda23474f5320fdd575e3225da290364355430b
  https://github.com/groonga/groonga/commit/3cda23474f5320fdd575e3225da290364355430b

  Message:
    Force index zero value

  Modified files:
    lib/db.c
    lib/ii.c

  Modified: lib/db.c (+14 -1)
===================================================================
--- lib/db.c    2013-03-06 18:20:52 +0900 (390f662)
+++ lib/db.c    2013-03-08 14:06:34 +0900 (cfc0890)
@@ -4924,6 +4924,17 @@ grn_obj_size(grn_ctx *ctx, grn_obj *obj)
   }
 }
 
+static grn_bool
+obj_zero(grn_obj *obj)
+{
+  byte *v = GRN_BULK_HEAD(obj);
+  unsigned int s = GRN_BULK_VSIZE(obj);
+  for (; s; s--, v++) {
+    if (*v) { return GRN_FALSE; }
+  }
+  return GRN_TRUE;
+}
+
 inline static int
 call_hook(grn_ctx *ctx, grn_obj *obj, grn_id id, grn_obj *value, int flags)
 {
@@ -4939,7 +4950,9 @@ call_hook(grn_ctx *ctx, grn_obj *obj, grn_id id, grn_obj *value, int flags)
       unsigned int os;
       ov = GRN_BULK_HEAD(oldvalue);
       os = grn_obj_size(ctx, oldvalue);
-      if (ov && v && os == s && !memcmp(ov, v, s)) {
+      if ((ov && v && os == s && !memcmp(ov, v, s)) &&
+          !(obj->header.type == GRN_COLUMN_FIX_SIZE &&
+            obj_zero(value))) {
         grn_bulk_fin(ctx, oldvalue);
         return 0;
       }

  Modified: lib/ii.c (+10 -1)
===================================================================
--- lib/ii.c    2013-03-06 18:20:52 +0900 (c04cc39)
+++ lib/ii.c    2013-03-08 14:06:34 +0900 (cddfadf)
@@ -5037,6 +5037,7 @@ grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, unsigned int section,
                      grn_obj *oldvalue, grn_obj *newvalue, grn_obj *posting)
 {
   grn_id *tp;
+  grn_bool do_grn_ii_updspec_cmp = GRN_TRUE;
   grn_rc rc = GRN_SUCCESS;
   grn_ii_updspec **u, **un;
   grn_obj *old_, *old = oldvalue, *new_, *new = newvalue, oldv, newv, buf, *post = NULL;
@@ -5056,6 +5057,14 @@ grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, unsigned int section,
     switch (type) {
     case GRN_BULK :
       {
+        byte *v = GRN_BULK_HEAD(new);
+        unsigned int s = GRN_BULK_VSIZE(new);
+        for (; s; s--, v++) {
+          if (*v) { break; }
+        }
+        if (!s) {
+          do_grn_ii_updspec_cmp = GRN_FALSE;
+        }
         new_ = new;
         GRN_OBJ_INIT(&newv, GRN_VECTOR, GRN_OBJ_DO_SHALLOW_COPY, GRN_DB_TEXT);
         newv.u.v.body = new;
@@ -5188,7 +5197,7 @@ grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, unsigned int section,
     grn_hash *n = (grn_hash *)new;
     GRN_HASH_EACH(ctx, o, id, &tp, NULL, &u, {
       if (n && (eid = grn_hash_get(ctx, n, tp, sizeof(grn_id), (void **) &un))) {
-        if (!grn_ii_updspec_cmp(*u, *un)) {
+        if (do_grn_ii_updspec_cmp && !grn_ii_updspec_cmp(*u, *un)) {
           grn_ii_updspec_close(ctx, *un);
           grn_hash_delete_by_id(ctx, n, eid, NULL);
         }
-------------- next part --------------
HTML����������������������������...
Download 



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