[Groonga-commit] groonga/groonga at 9101c8c [master] Use simple scan_info_build implementation for simple expression

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 8 16:11:12 JST 2016


Kouhei Sutou	2016-04-08 16:11:12 +0900 (Fri, 08 Apr 2016)

  New Revision: 9101c8c8703c5c7d409a8fcc8ca338359ee73283
  https://github.com/groonga/groonga/commit/9101c8c8703c5c7d409a8fcc8ca338359ee73283

  Message:
    Use simple scan_info_build implementation for simple expression

  Added files:
    test/command/suite/select/filter/simple/column_only.expected
    test/command/suite/select/filter/simple/column_only.test
    test/command/suite/select/filter/simple/constant_only.expected
    test/command/suite/select/filter/simple/constant_only.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+82 -7)
===================================================================
--- lib/expr.c    2016-04-08 15:19:28 +0900 (2d49b02)
+++ lib/expr.c    2016-04-08 16:11:12 +0900 (fb71a06)
@@ -4856,20 +4856,95 @@ grn_scan_info_build_full(grn_ctx *ctx, grn_obj *expr, int *n,
   return sis;
 }
 
+static scan_info **
+grn_scan_info_build_simple_open(grn_ctx *ctx, int *n, grn_operator logical_op)
+{
+  scan_info **sis;
+  scan_info *si;
+
+  sis = GRN_MALLOCN(scan_info *, 1);
+  if (!sis) {
+    ERR(GRN_NO_MEMORY_AVAILABLE,
+        "[scan_info][build] failed to allocate memory for scan_info **");
+    return NULL;
+  }
+
+  si = grn_scan_info_open(ctx, 0);
+  if (!si) {
+    ERR(GRN_NO_MEMORY_AVAILABLE,
+        "[scan_info][build] failed to allocate memory for scan_info *");
+    GRN_FREE(sis);
+    return NULL;
+  }
+
+  si->logical_op = logical_op;
+
+  sis[0] = si;
+  *n = 1;
+
+  return sis;
+}
+
+static scan_info **
+grn_scan_info_build_simple(grn_ctx *ctx, grn_obj *expr, int *n,
+                           grn_operator logical_op, grn_bool record_exist)
+{
+  grn_expr *e = (grn_expr *)expr;
+  grn_expr_code *code;
+  grn_expr_code *code_end;
+
+  code = e->codes;
+  code_end = e->codes + e->codes_curr;
+
+  if (e->codes_curr == 1) {
+    scan_info **sis;
+    scan_info *si;
+
+    switch (code->op) {
+    case GRN_OP_PUSH :
+    case GRN_OP_GET_VALUE :
+      break;
+    default :
+      return NULL;
+      break;
+    }
+
+    sis = grn_scan_info_build_simple_open(ctx, n, logical_op);
+    if (!sis) {
+      return NULL;
+    }
+
+    si = sis[0];
+    si->end = 0;
+    si->op = code->op;
+    return sis;
+  }
+
+  return NULL;
+}
+
 scan_info **
 grn_scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
                     grn_operator op, grn_bool record_exist)
 {
+  scan_info **sis;
+
+  sis = grn_scan_info_build_simple(ctx, expr, n, op, record_exist);
 #ifdef GRN_WITH_MRUBY
-  grn_ctx_impl_mrb_ensure_init(ctx);
-  if (ctx->rc != GRN_SUCCESS) {
-    return NULL;
-  }
-  if (ctx->impl->mrb.state) {
-    return grn_mrb_scan_info_build(ctx, expr, n, op, record_exist);
+  if (!sis) {
+    grn_ctx_impl_mrb_ensure_init(ctx);
+    if (ctx->rc != GRN_SUCCESS) {
+      return NULL;
+    }
+    if (ctx->impl->mrb.state) {
+      return grn_mrb_scan_info_build(ctx, expr, n, op, record_exist);
+    }
   }
 #endif
-  return grn_scan_info_build_full(ctx, expr, n, op, record_exist);
+  if (!sis) {
+    sis = grn_scan_info_build_full(ctx, expr, n, op, record_exist);
+  }
+  return sis;
 }
 
 void

  Added: test/command/suite/select/filter/simple/column_only.expected (+44 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/simple/column_only.expected    2016-04-08 16:11:12 +0900 (98d9056)
@@ -0,0 +1,44 @@
+table_create Logs TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs is_critical COLUMN_SCALAR Bool
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{"is_critical": true},
+{"is_critical": false},
+{"is_critical": true}
+]
+[[0,0.0,0.0],3]
+select Logs --filter is_critical
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        2
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "is_critical",
+          "Bool"
+        ]
+      ],
+      [
+        1,
+        true
+      ],
+      [
+        3,
+        true
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/simple/column_only.test (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/simple/column_only.test    2016-04-08 16:11:12 +0900 (9b144bf)
@@ -0,0 +1,11 @@
+table_create Logs TABLE_NO_KEY
+column_create Logs is_critical COLUMN_SCALAR Bool
+
+load --table Logs
+[
+{"is_critical": true},
+{"is_critical": false},
+{"is_critical": true}
+]
+
+select Logs --filter is_critical

  Added: test/command/suite/select/filter/simple/constant_only.expected (+9 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/simple/constant_only.expected    2016-04-08 16:11:12 +0900 (5ab3629)
@@ -0,0 +1,9 @@
+table_create Logs TABLE_NO_KEY
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{}
+]
+[[0,0.0,0.0],1]
+select Logs --filter true
+[[0,0.0,0.0],[[[1],[["_id","UInt32"]],[1]]]]

  Added: test/command/suite/select/filter/simple/constant_only.test (+8 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/simple/constant_only.test    2016-04-08 16:11:12 +0900 (b055e24)
@@ -0,0 +1,8 @@
+table_create Logs TABLE_NO_KEY
+
+load --table Logs
+[
+{}
+]
+
+select Logs --filter true
-------------- next part --------------
HTML����������������������������...
다운로드 



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