Kouhei Sutou
null+****@clear*****
Fri May 27 11:31:38 JST 2016
Kouhei Sutou 2016-05-27 11:31:38 +0900 (Fri, 27 May 2016) New Revision: 5e3ea8e85de02eadfc9cae56c46f338a74d8d9ba https://github.com/groonga/groonga/commit/5e3ea8e85de02eadfc9cae56c46f338a74d8d9ba Message: select: fix a bug that --drilldown_XXX aren't used as cache key Added files: test/command/suite/select/cache/drilldown.expected test/command/suite/select/cache/drilldown.test Modified files: lib/proc/proc_select.c Modified: lib/proc/proc_select.c (+39 -25) =================================================================== --- lib/proc/proc_select.c 2016-05-27 11:04:04 +0900 (dda8aef) +++ lib/proc/proc_select.c 2016-05-27 11:31:38 +0900 (cddb9cb) @@ -2672,22 +2672,28 @@ grn_select(grn_ctx *ctx, grn_select_data *data) sizeof(int) * 2; } GRN_HASH_EACH_END(ctx, cursor); } +#define DRILLDOWN_CACHE_SIZE(drilldown) \ + drilldown->keys.length + 1 + \ + drilldown->sort_keys.length + 1 + \ + drilldown->output_columns.length + 1 + \ + drilldown->label.length + 1 + \ + drilldown->calc_target_name.length + 1 + \ + drilldown->filter.length + 1 + \ + drilldown->table_name.length + 1 + \ + sizeof(int) * 2 + \ + sizeof(grn_table_group_flags) + if (data->drilldown.keys.length > 0) { + grn_drilldown_data *drilldown = &(data->drilldown); + cache_key_size += DRILLDOWN_CACHE_SIZE(drilldown); + } if (data->drilldowns) { GRN_HASH_EACH_BEGIN(ctx, data->drilldowns, cursor, id) { grn_drilldown_data *drilldown; grn_hash_cursor_get_value(ctx, cursor, (void **)&drilldown); - cache_key_size += - drilldown->keys.length + 1 + - drilldown->sort_keys.length + 1 + - drilldown->output_columns.length + 1 + - drilldown->label.length + 1 + - drilldown->calc_target_name.length + 1 + - drilldown->filter.length + 1 + - drilldown->table_name.length + 1 + - sizeof(int) * 2 + - sizeof(grn_table_group_flags); + cache_key_size += DRILLDOWN_CACHE_SIZE(drilldown); } GRN_HASH_EACH_END(ctx, cursor); } +#undef DRILLDOWN_CACHE_SIZE if (cache_key_size <= GRN_CACHE_MAX_KEY_SIZE) { grn_obj *cache_value; char *cp = cache_key; @@ -2718,27 +2724,35 @@ grn_select(grn_ctx *ctx, grn_select_data *data) cp += sizeof(int); } GRN_HASH_EACH_END(ctx, cursor); } +#define PUT_CACHE_KEY_DRILLDOWN(drilldown) do { \ + PUT_CACHE_KEY(drilldown->keys); \ + PUT_CACHE_KEY(drilldown->sort_keys); \ + PUT_CACHE_KEY(drilldown->output_columns); \ + PUT_CACHE_KEY(drilldown->label); \ + PUT_CACHE_KEY(drilldown->calc_target_name); \ + PUT_CACHE_KEY(drilldown->filter); \ + PUT_CACHE_KEY(drilldown->table_name); \ + grn_memcpy(cp, &(drilldown->offset), sizeof(int)); \ + cp += sizeof(int); \ + grn_memcpy(cp, &(drilldown->limit), sizeof(int)); \ + cp += sizeof(int); \ + grn_memcpy(cp, \ + &(drilldown->calc_types), \ + sizeof(grn_table_group_flags)); \ + cp += sizeof(grn_table_group_flags); \ + } while (GRN_FALSE) + if (data->drilldown.keys.length > 0) { + grn_drilldown_data *drilldown = &(data->drilldown); + PUT_CACHE_KEY_DRILLDOWN(drilldown); + } if (data->drilldowns) { GRN_HASH_EACH_BEGIN(ctx, data->drilldowns, cursor, id) { grn_drilldown_data *drilldown; grn_hash_cursor_get_value(ctx, cursor, (void **)&drilldown); - PUT_CACHE_KEY(drilldown->keys); - PUT_CACHE_KEY(drilldown->sort_keys); - PUT_CACHE_KEY(drilldown->output_columns); - PUT_CACHE_KEY(drilldown->label); - PUT_CACHE_KEY(drilldown->calc_target_name); - PUT_CACHE_KEY(drilldown->filter); - PUT_CACHE_KEY(drilldown->table_name); - grn_memcpy(cp, &(drilldown->offset), sizeof(int)); - cp += sizeof(int); - grn_memcpy(cp, &(drilldown->limit), sizeof(int)); - cp += sizeof(int); - grn_memcpy(cp, - &(drilldown->calc_types), - sizeof(grn_table_group_flags)); - cp += sizeof(grn_table_group_flags); + PUT_CACHE_KEY_DRILLDOWN(drilldown); } GRN_HASH_EACH_END(ctx, cursor); } +#undef PUT_CACHE_KEY_DRILLDOWN PUT_CACHE_KEY(data->match_escalation_threshold); PUT_CACHE_KEY(data->query_expander); PUT_CACHE_KEY(data->query_flags); Added: test/command/suite/select/cache/drilldown.expected (+111 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/cache/drilldown.expected 2016-05-27 11:31:38 +0900 (569d288) @@ -0,0 +1,111 @@ +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tag COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Hello Groonga!", "tag": "Groonga"}, +{"_key": "Hello Rroonga!", "tag": "Rroonga"} +] +[[0,0.0,0.0],2] +select Memos +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 2 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "tag", + "ShortText" + ] + ], + [ + 1, + "Hello Groonga!", + "Groonga" + ], + [ + 2, + "Hello Rroonga!", + "Rroonga" + ] + ] + ] +] +select Memos --drilldown tag +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 2 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "tag", + "ShortText" + ] + ], + [ + 1, + "Hello Groonga!", + "Groonga" + ], + [ + 2, + "Hello Rroonga!", + "Rroonga" + ] + ], + [ + [ + 2 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "_nsubrecs", + "Int32" + ] + ], + [ + "Groonga", + 1 + ], + [ + "Rroonga", + 1 + ] + ] + ] +] Added: test/command/suite/select/cache/drilldown.test (+17 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/cache/drilldown.test 2016-05-27 11:31:38 +0900 (4b2d961) @@ -0,0 +1,17 @@ +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tag COLUMN_SCALAR ShortText + +load --table Memos +[ +{"_key": "Hello Groonga!", "tag": "Groonga"}, +{"_key": "Hello Rroonga!", "tag": "Rroonga"} +] + +# For use cache +#@sleep 1 + +select Memos + +select Memos \ + --drilldown tag + -------------- next part -------------- HTML����������������������������... 다운로드