[Groonga-commit] groonga/groonga [master] Support AND operation for nested index

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Feb 15 12:56:29 JST 2013


Kouhei Sutou	2013-02-15 12:56:29 +0900 (Fri, 15 Feb 2013)

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

  Log:
    Support AND operation for nested index
    
    "COLUMN1.COLUMN2 >= 1 && COLUMN1.COLUMN2 <= 3" works by this change.
    
    But "1 <= COLUMN1.COLUMN2 && COLUMN1.COLUMN2 <= 3" doesn't work yet.
    It is evaluated as "COLUMN1.COLUMN2 <= 1 && COLUMN1.COLUMN2 <= 3". :<

  Added files:
    test/command/suite/select/index/nested/by_column/and.expected
    test/command/suite/select/index/nested/by_column/and.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+17 -11)
===================================================================
--- lib/expr.c    2013-02-14 18:55:52 +0900 (04f1931)
+++ lib/expr.c    2013-02-15 12:56:29 +0900 (036925c)
@@ -4000,7 +4000,8 @@ grn_table_select_(grn_ctx *ctx, grn_obj *table, grn_obj *expr, grn_obj *v,
 static inline grn_bool
 grn_table_select_index_range_column(grn_ctx *ctx, grn_obj *table,
                                     grn_obj *index,
-                                    scan_info *si, grn_obj *res)
+                                    scan_info *si, grn_operator logical_op,
+                                    grn_obj *res)
 {
   grn_bool processed = GRN_FALSE;
   grn_obj *index_table;
@@ -4051,13 +4052,13 @@ grn_table_select_index_range_column(grn_ctx *ctx, grn_obj *table,
       grn_id index_id;
       while ((index_id = grn_table_cursor_next(ctx, cursor))) {
         grn_ii_at(ctx, (grn_ii *)index, index_id,
-                  (grn_hash *)res, si->logical_op);
+                  (grn_hash *)res, logical_op);
       }
       grn_table_cursor_close(ctx, cursor);
       processed = GRN_TRUE;
     }
 
-    grn_ii_resolve_sel_and(ctx, (grn_hash *)res, si->logical_op);
+    grn_ii_resolve_sel_and(ctx, (grn_hash *)res, logical_op);
   }
   GRN_OBJ_FIN(ctx, &range);
 
@@ -4098,7 +4099,7 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table,
     if (!current_res) {
       return GRN_FALSE;
     }
-    if (!grn_table_select_index_range_column(ctx, table, index, si,
+    if (!grn_table_select_index_range_column(ctx, table, index, si, GRN_OP_OR,
                                              current_res)) {
       grn_obj_unlink(ctx, current_res);
       return GRN_FALSE;
@@ -4126,10 +4127,7 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table,
         break;
       }
 
-      if (i == 1) {
-        next_res = res;
-        next_op = si->logical_op;
-      } else {
+      {
         grn_obj *range;
         range = grn_ctx_at(ctx, DB_OBJ(index)->range);
         next_res = grn_table_create(ctx, NULL, 0, NULL,
@@ -4167,14 +4165,21 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table,
       grn_obj_unlink(ctx, domain);
       grn_obj_unlink(ctx, current_res);
 
-      if (rc != GRN_SUCCESS) {
+      if (rc == GRN_SUCCESS) {
+        if (i == 1) {
+          grn_table_setoperation(ctx, res, next_res, res, si->logical_op);
+          grn_obj_unlink(ctx, next_res);
+          current_res = res;
+        } else {
+          current_res = next_res;
+        }
+      } else {
         if (res != next_res) {
           grn_obj_unlink(ctx, next_res);
         }
         current_res = NULL;
         break;
       }
-      current_res = next_res;
     }
   }
 
@@ -4205,7 +4210,8 @@ grn_table_select_index_range(grn_ctx *ctx, grn_obj *table, grn_obj *index,
     GRN_OBJ_FIN(ctx, &accessor_stack);
     return processed;
   } else {
-    return grn_table_select_index_range_column(ctx, table, index, si, res);
+    return grn_table_select_index_range_column(ctx, table, index, si,
+                                               si->logical_op, res);
   }
 }
 

  Added: test/command/suite/select/index/nested/by_column/and.expected (+62 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/index/nested/by_column/and.expected    2013-02-15 12:56:29 +0900 (a98b2ca)
@@ -0,0 +1,62 @@
+table_create Users TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Users birthday COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create Files TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Files owner COLUMN_SCALAR Users
+[[0,0.0,0.0],true]
+column_create Users files_owner_index COLUMN_INDEX Files owner
+[[0,0.0,0.0],true]
+table_create Birthdays TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Birthdays users_birthday COLUMN_INDEX Users birthday
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"_key": "Alice",  "birthday": "1992-02-09 00:00:00"},
+{"_key": "Bob",    "birthday": "1988-01-04 00:00:00"},
+{"_key": "Carlos", "birthday": "1982-12-29 00:00:00"}
+]
+[[0,0.0,0.0],3]
+load --table Files
+[
+{"_key": "/home/alice/.zshrc",                  "owner": "Alice"},
+{"_key": "/home/bob/.bashrc",                   "owner": "Bob"},
+{"_key": "/home/calros/public_html/index.html", "owner": "Carlos"}
+]
+[[0,0.0,0.0],3]
+select Files   --filter 'owner.birthday >= "1988-01-04 00:00:00" && owner.birthday < "1992-02-09 00:00:00"'   --output_columns '_key, owner, owner.birthday'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "owner",
+          "Users"
+        ],
+        [
+          "owner.birthday",
+          "Time"
+        ]
+      ],
+      [
+        "/home/bob/.bashrc",
+        "Bob",
+        568220400.0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/index/nested/by_column/and.test (+28 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/index/nested/by_column/and.test    2013-02-15 12:56:29 +0900 (edb801f)
@@ -0,0 +1,28 @@
+table_create Users TABLE_PAT_KEY ShortText
+column_create Users birthday COLUMN_SCALAR Time
+
+table_create Files TABLE_PAT_KEY ShortText
+column_create Files owner COLUMN_SCALAR Users
+
+column_create Users files_owner_index COLUMN_INDEX Files owner
+
+table_create Birthdays TABLE_PAT_KEY Time
+column_create Birthdays users_birthday COLUMN_INDEX Users birthday
+
+load --table Users
+[
+{"_key": "Alice",  "birthday": "1992-02-09 00:00:00"},
+{"_key": "Bob",    "birthday": "1988-01-04 00:00:00"},
+{"_key": "Carlos", "birthday": "1982-12-29 00:00:00"}
+]
+
+load --table Files
+[
+{"_key": "/home/alice/.zshrc",                  "owner": "Alice"},
+{"_key": "/home/bob/.bashrc",                   "owner": "Bob"},
+{"_key": "/home/calros/public_html/index.html", "owner": "Carlos"}
+]
+
+select Files \
+  --filter 'owner.birthday >= "1988-01-04 00:00:00" && owner.birthday < "1992-02-09 00:00:00"' \
+  --output_columns '_key, owner, owner.birthday'
-------------- next part --------------
HTML����������������������������...
Download 



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