[Groonga-commit] groonga/groonga at 5920d71 [master] Fix a "AND min ID skip" bug

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Sep 20 14:11:38 JST 2018


Kouhei Sutou	2018-09-20 14:11:38 +0900 (Thu, 20 Sep 2018)

  Revision: 5920d71175efac3f6f91a60fb00f3bcda551ccce
  https://github.com/groonga/groonga/commit/5920d71175efac3f6f91a60fb00f3bcda551ccce

  Message:
    Fix a "AND min ID skip" bug
    
    It may be occurred with nested index search. So this change disables
    "AND min ID skip" optimization when nested index search is used.

  Added files:
    test/command/suite/select/filter/index/optimization/and_min_skip/equal_match_match.expected
    test/command/suite/select/filter/index/optimization/and_min_skip/equal_match_match.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+11 -7)
===================================================================
--- lib/expr.c    2018-09-19 13:31:48 +0900 (24c1514e5)
+++ lib/expr.c    2018-09-20 14:11:38 +0900 (f97d31224)
@@ -4036,13 +4036,9 @@ grn_table_select_index_match(grn_ctx *ctx,
   optarg.match_info.flags = GRN_MATCH_INFO_GET_MIN_RECORD_ID;
   ctx->flags |= GRN_CTX_TEMPORARY_DISABLE_II_RESOLVE_SEL_AND;
   for (j = 0; j < n_indexes; j++, ip++, wp += 2) {
+    grn_bool use_and_min_skip_enable;
     uint32_t sid = (uint32_t) wp[0];
     int32_t weight = wp[1];
-    if (grn_table_select_and_min_skip_enable) {
-      optarg.match_info.min = *min_id;
-    } else {
-      optarg.match_info.min = GRN_ID_NIL;
-    }
     if (sid > 0) {
       int weight_index = sid - 1;
       int current_vector_size;
@@ -4071,6 +4067,13 @@ grn_table_select_index_match(grn_ctx *ctx,
         continue;
       }
     }
+    use_and_min_skip_enable =
+      (grn_table_select_and_min_skip_enable && !GRN_ACCESSORP(ip[0]));
+    if (use_and_min_skip_enable) {
+      optarg.match_info.min = *min_id;
+    } else {
+      optarg.match_info.min = GRN_ID_NIL;
+    }
     grn_obj_search(ctx, ip[0], si->query, res, si->logical_op, &optarg);
     if (optarg.weight_vector) {
       int i;
@@ -4079,8 +4082,9 @@ grn_table_select_index_match(grn_ctx *ctx,
       }
     }
     GRN_BULK_REWIND(&wv);
-    if (!minimum_min_id_is_set ||
-        optarg.match_info.min < minimum_min_id) {
+    if (use_and_min_skip_enable &&
+        (!minimum_min_id_is_set ||
+         optarg.match_info.min < minimum_min_id)) {
       minimum_min_id_is_set = GRN_TRUE;
       minimum_min_id = optarg.match_info.min;
     }

  Added: test/command/suite/select/filter/index/optimization/and_min_skip/equal_match_match.expected (+71 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/index/optimization/and_min_skip/equal_match_match.expected    2018-09-20 14:11:38 +0900 (5dc5aea89)
@@ -0,0 +1,71 @@
+table_create Tags TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Tags label COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos content COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY ShortText   --normalize NormalizerNFKC100   --default_tokenizer TokenBigram
+[[0,0.0,0.0],true]
+column_create Terms tags_label COLUMN_INDEX|WITH_POSITION Tags label
+[[0,0.0,0.0],true]
+column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content
+[[0,0.0,0.0],true]
+column_create Tags memos_tag COLUMN_INDEX Memos tag
+[[0,0.0,0.0],true]
+load --table Tags
+[
+{"_key": "mroonga",  "label": "Mroonga"},
+{"_key": "pgroonga", "label": "PGroonga"},
+{"_key": "groonga",  "label": "Groonga"}
+]
+[[0,0.0,0.0],3]
+load --table Memos
+[
+{"_key": "groonga",  "tag": "groonga",  "content": "Groonga is fast"},
+{"_key": "mroonga",  "tag": "mroonga",  "content": "Mroonga is based on Groonga"},
+{"_key": "pgroonga", "tag": "pgroonga", "content": "PGroonga is based on Groonga"}
+]
+[[0,0.0,0.0],3]
+select Memos   --filter '_key == "groonga" && tag.label @ "Groonga" && content @ "Groonga"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "content",
+          "Text"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ],
+      [
+        1,
+        "groonga",
+        "Groonga is fast",
+        "groonga"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/index/optimization/and_min_skip/equal_match_match.test (+31 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/index/optimization/and_min_skip/equal_match_match.test    2018-09-20 14:11:38 +0900 (1fd6f3685)
@@ -0,0 +1,31 @@
+table_create Tags TABLE_HASH_KEY ShortText
+column_create Tags label COLUMN_SCALAR ShortText
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tag COLUMN_SCALAR Tags
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalize NormalizerNFKC100 \
+  --default_tokenizer TokenBigram
+column_create Terms tags_label COLUMN_INDEX|WITH_POSITION Tags label
+column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content
+
+column_create Tags memos_tag COLUMN_INDEX Memos tag
+
+load --table Tags
+[
+{"_key": "mroonga",  "label": "Mroonga"},
+{"_key": "pgroonga", "label": "PGroonga"},
+{"_key": "groonga",  "label": "Groonga"}
+]
+
+load --table Memos
+[
+{"_key": "groonga",  "tag": "groonga",  "content": "Groonga is fast"},
+{"_key": "mroonga",  "tag": "mroonga",  "content": "Mroonga is based on Groonga"},
+{"_key": "pgroonga", "tag": "pgroonga", "content": "PGroonga is based on Groonga"}
+]
+
+select Memos \
+  --filter '_key == "groonga" && tag.label @ "Groonga" && content @ "Groonga"'
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180920/da1848fa/attachment-0001.htm 



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