[Groonga-commit] groonga/groonga at ec0e6f1 [master] select: support index on range search in slice

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Sep 5 16:20:55 JST 2016


Kouhei Sutou	2016-09-05 16:20:55 +0900 (Mon, 05 Sep 2016)

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

  Message:
    select: support index on range search in slice

  Added files:
    test/command/suite/select/slices/index/filtered/range.expected
    test/command/suite/select/slices/index/filtered/range.test
  Modified files:
    lib/db.c
    lib/expr.c
    lib/grn_report.h
    lib/report.c

  Modified: lib/db.c (+5 -0)
===================================================================
--- lib/db.c    2016-09-05 15:51:49 +0900 (9192e55)
+++ lib/db.c    2016-09-05 16:20:55 +0900 (ff97e0f)
@@ -3242,6 +3242,11 @@ grn_accessor_resolve_one_table(grn_ctx *ctx, grn_accessor *accessor,
     return ctx->rc;
   }
 
+  grn_report_table(ctx,
+                   "[accessor][resolve]",
+                   "",
+                   table);
+
   {
     grn_posting posting;
 

  Modified: lib/expr.c (+7 -1)
===================================================================
--- lib/expr.c    2016-09-05 15:51:49 +0900 (1ffa403)
+++ lib/expr.c    2016-09-05 16:20:55 +0900 (f893921)
@@ -6357,6 +6357,7 @@ grn_table_select_index_range_accessor(grn_ctx *ctx,
   grn_accessor *a;
   grn_obj *last_obj = NULL;
   int n_accessors;
+  grn_bool have_resolver = GRN_FALSE;
   grn_obj *base_res = NULL;
 
   for (a = (grn_accessor *)accessor; a; a = a->next) {
@@ -6369,6 +6370,7 @@ grn_table_select_index_range_accessor(grn_ctx *ctx,
     n_accessors++;
     if (GRN_OBJ_INDEX_COLUMNP(a->obj) ||
         grn_obj_is_table(ctx, a->obj)) {
+      have_resolver = GRN_TRUE;
       break;
     }
   }
@@ -6414,7 +6416,11 @@ grn_table_select_index_range_accessor(grn_ctx *ctx,
     grn_table_select_index_report(ctx, "[range][accessor]", index);
   }
 
-  rc = grn_accessor_resolve(ctx, accessor, n_accessors - 1, base_res, res, op);
+  if (n_accessors == 1 && have_resolver) {
+    rc = grn_accessor_resolve(ctx, accessor, 1, base_res, res, op);
+  } else {
+    rc = grn_accessor_resolve(ctx, accessor, n_accessors - 1, base_res, res, op);
+  }
   grn_obj_unlink(ctx, base_res);
 
   return rc == GRN_SUCCESS;

  Modified: lib/grn_report.h (+5 -0)
===================================================================
--- lib/grn_report.h    2016-09-05 15:51:49 +0900 (a514e46)
+++ lib/grn_report.h    2016-09-05 16:20:55 +0900 (a8bd52f)
@@ -37,6 +37,11 @@ void grn_report_index_not_used(grn_ctx *ctx,
                                grn_obj *index,
                                const char *reason);
 
+void grn_report_table(grn_ctx *ctx,
+                      const char *action,
+                      const char *tag,
+                      grn_obj *table);
+
 #ifdef __cplusplus
 }
 #endif

  Modified: lib/report.c (+39 -1)
===================================================================
--- lib/report.c    2016-09-05 15:51:49 +0900 (9305d0b)
+++ lib/report.c    2016-09-05 16:20:55 +0900 (b9e396e)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2015 Brazil
+  Copyright(C) 2015-2016 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -58,3 +58,41 @@ grn_report_index_not_used(grn_ctx *ctx,
           "%s[index-not-used]%s <%.*s>: %s",
           action, tag, index_name_size, index_name, reason);
 }
+
+void
+grn_report_table(grn_ctx *ctx,
+                 const char *action,
+                 const char *tag,
+                 grn_obj *table)
+{
+  grn_obj description;
+  grn_obj *target;
+
+  if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
+    return;
+  }
+
+  GRN_TEXT_INIT(&description, 0);
+  for (target = table; target; target = grn_ctx_at(ctx, target->header.domain)) {
+    char name[GRN_TABLE_MAX_KEY_SIZE];
+    int name_size;
+
+    name_size = grn_obj_name(ctx, target, name, GRN_TABLE_MAX_KEY_SIZE);
+    if (GRN_TEXT_LEN(&description) > 0) {
+      GRN_TEXT_PUTS(ctx, &description, " -> ");
+    }
+    if (name_size == 0) {
+      GRN_TEXT_PUTS(ctx, &description, "(temporary)");
+    } else {
+      GRN_TEXT_PUTS(ctx, &description, "<");
+      GRN_TEXT_PUT(ctx, &description, name, name_size);
+      GRN_TEXT_PUTS(ctx, &description, ">");
+    }
+  }
+  GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
+          "%s[table]%s %.*s",
+          action, tag,
+          (int)GRN_TEXT_LEN(&description),
+          GRN_TEXT_VALUE(&description));
+  GRN_OBJ_FIN(ctx, &description);
+}

  Added: test/command/suite/select/slices/index/filtered/range.expected (+99 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/slices/index/filtered/range.expected    2016-09-05 16:20:55 +0900 (e7e1547)
@@ -0,0 +1,99 @@
+table_create Dates TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos date COLUMN_SCALAR Dates
+[[0,0.0,0.0],true]
+column_create Memos tag COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+column_create Dates memos_date COLUMN_INDEX Memos date
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga is fast!", "date": 20160519, "tag": "Groonga"},
+{"_key": "Mroonga is fast!", "date": 20160520, "tag": "Mroonga"},
+{"_key": "Groonga sticker!", "date": 20160521, "tag": "Groonga"},
+{"_key": "Groonga is good!", "date": 20160522, "tag": "Groonga"}
+]
+[[0,0.0,0.0],4]
+log_level --level info
+[[0,0.0,0.0],true]
+select Memos   --filter 'tag @ "Groonga"'   --slices[groonga].filter 'date < 20160522'   --slices[groonga].sort_keys 'date'   --slices[groonga].output_columns '_key, date'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "date",
+          "Dates"
+        ],
+        [
+          "tag",
+          "ShortText"
+        ]
+      ],
+      [
+        1,
+        "Groonga is fast!",
+        20160519,
+        "Groonga"
+      ],
+      [
+        3,
+        "Groonga sticker!",
+        20160521,
+        "Groonga"
+      ],
+      [
+        4,
+        "Groonga is good!",
+        20160522,
+        "Groonga"
+      ]
+    ],
+    {
+      "groonga": [
+        [
+          2
+        ],
+        [
+          [
+            "_key",
+            "ShortText"
+          ],
+          [
+            "date",
+            "Dates"
+          ]
+        ],
+        [
+          "Groonga is fast!",
+          20160519
+        ],
+        [
+          "Groonga sticker!",
+          20160521
+        ]
+      ]
+    }
+  ]
+]
+#|i| [table][select][index][range] <Dates>
+#|i| [table][select][index][range][accessor] <Dates.memos_date>
+#|i| [accessor][resolve][table] (temporary) -> <Memos> -> <ShortText>

  Added: test/command/suite/select/slices/index/filtered/range.test (+23 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/slices/index/filtered/range.test    2016-09-05 16:20:55 +0900 (8297efb)
@@ -0,0 +1,23 @@
+table_create Dates TABLE_PAT_KEY UInt32
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos date COLUMN_SCALAR Dates
+column_create Memos tag COLUMN_SCALAR ShortText
+
+column_create Dates memos_date COLUMN_INDEX Memos date
+
+load --table Memos
+[
+{"_key": "Groonga is fast!", "date": 20160519, "tag": "Groonga"},
+{"_key": "Mroonga is fast!", "date": 20160520, "tag": "Mroonga"},
+{"_key": "Groonga sticker!", "date": 20160521, "tag": "Groonga"},
+{"_key": "Groonga is good!", "date": 20160522, "tag": "Groonga"}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Memos \
+  --filter 'tag @ "Groonga"' \
+  --slices[groonga].filter 'date < 20160522' \
+  --slices[groonga].sort_keys 'date' \
+  --slices[groonga].output_columns '_key, date'
-------------- next part --------------
HTML����������������������������...
Download 



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