Navigation Menu

Skip to content

Commit

Permalink
Fix a "AND min ID skip" bug
Browse files Browse the repository at this point in the history
It may be occurred with nested index search. So this change disables
"AND min ID skip" optimization when nested index search is used.
  • Loading branch information
kou committed Sep 20, 2018
1 parent 3f9f0f3 commit 5920d71
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/expr.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
@@ -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"
]
]
]
]
@@ -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"'

0 comments on commit 5920d71

Please sign in to comment.