Kouhei Sutou 2019-04-25 16:12:13 +0900 (Thu, 25 Apr 2019) Revision: 33ddccb9908ee3c3f2d0682b11114abde61d028e https://github.com/groonga/groonga/commit/33ddccb9908ee3c3f2d0682b11114abde61d028e Message: grn_obj_search: fix a bug that index search by record doesn't resolve AND Added files: test/command/suite/select/function/in_values/with_index/reference/and_optimized.expected test/command/suite/select/function/in_values/with_index/reference/and_optimized.test Modified files: lib/db.c Modified: lib/db.c (+4 -18) =================================================================== --- lib/db.c 2019-04-25 15:15:43 +0900 (a16d0dfee) +++ lib/db.c 2019-04-25 16:12:13 +0900 (cf5fca61a) @@ -3753,26 +3753,12 @@ grn_obj_search_column_index_by_id(grn_ctx *ctx, grn_obj *obj, grn_obj *res, grn_operator op, grn_search_optarg *optarg) { - grn_ii_cursor *c; - grn_obj_search_index_report(ctx, "[id]", obj); - - c = grn_ii_cursor_open(ctx, (grn_ii *)obj, tid, - GRN_ID_NIL, GRN_ID_MAX, 1, 0); - if (c) { - grn_posting *pos; - grn_hash *s = (grn_hash *)res; - while ((pos = grn_ii_cursor_next(ctx, c))) { - /* todo: support orgarg(op) - res_add(ctx, s, (grn_rset_posinfo *) pos, - get_weight(ctx, s, pos->rid, pos->sid, wvm, optarg), op); - */ - grn_hash_add(ctx, s, pos, s->key_size, NULL, NULL); - } - grn_ii_cursor_close(ctx, c); + grn_ii_at(ctx, (grn_ii *)obj, tid, (grn_hash *)res, op); + if (ctx->rc == GRN_SUCCESS) { + grn_ii_resolve_sel_and(ctx, (grn_hash *)res, op); } - - return GRN_SUCCESS; + return ctx->rc; } static grn_rc Added: test/command/suite/select/function/in_values/with_index/reference/and_optimized.expected (+65 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/in_values/with_index/reference/and_optimized.expected 2019-04-25 16:12:13 +0900 (97dfec7e0) @@ -0,0 +1,65 @@ +table_create Tags TABLE_PAT_KEY 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 Tags memos_tag COLUMN_INDEX Memos tag +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga is fast", "tag": "groonga"}, +{"_key": "Mroonga is fast", "tag": "mroonga"}, +{"_key": "Rroonga is fast", "tag": "rroonga"}, +{"_key": "Droonga is fast", "tag": "droonga"}, +{"_key": "Groonga is a HTTP server", "tag": "groonga"} +] +[[0,0.0,0.0],5] +select Memos --output_columns _key,tag --filter 'all_records() && (tag == "groonga" || tag == "mroonga" || tag == "droonga")' --sortby _id +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 4 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "tag", + "Tags" + ] + ], + [ + "Groonga is fast", + "groonga" + ], + [ + "Mroonga is fast", + "mroonga" + ], + [ + "Droonga is fast", + "droonga" + ], + [ + "Groonga is a HTTP server", + "groonga" + ] + ] + ] +] +#>select --filter "all_records() && (tag == \"groonga\" || tag == \"mroonga\" || tag == \"droonga\")" --output_columns "_key,tag" --sortby "_id" --table "Memos" +#:000000000000000 filter(5): all_records() +#:000000000000000 filter(4): in_values(Memos.tag, #<record:pat:Tags id:1 key:"groonga">, #<record:pat:Tags id:2 key:"mroonga">, #<record:pat:Tags id:4 key:"droonga">) +#:000000000000000 select(4) +#:000000000000000 sort(4) +#:000000000000000 output(4) +#<000000000000000 rc=0 Added: test/command/suite/select/function/in_values/with_index/reference/and_optimized.test (+24 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/in_values/with_index/reference/and_optimized.test 2019-04-25 16:12:13 +0900 (7b822933a) @@ -0,0 +1,24 @@ +#$GRN_EXPR_OPTIMIZE=yes + +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tag COLUMN_SCALAR Tags + +column_create Tags memos_tag COLUMN_INDEX Memos tag + +load --table Memos +[ +{"_key": "Groonga is fast", "tag": "groonga"}, +{"_key": "Mroonga is fast", "tag": "mroonga"}, +{"_key": "Rroonga is fast", "tag": "rroonga"}, +{"_key": "Droonga is fast", "tag": "droonga"}, +{"_key": "Groonga is a HTTP server", "tag": "groonga"} +] + +#@collect-query-log true +select Memos \ + --output_columns _key,tag \ + --filter 'all_records() && (tag == "groonga" || tag == "mroonga" || tag == "droonga")' \ + --sortby _id +#@collect-query-log false -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190425/3228dea7/attachment-0001.html>