Kouhei Sutou
null+****@clear*****
Sun May 22 21:11:50 JST 2016
Kouhei Sutou 2016-05-22 21:11:50 +0900 (Sun, 22 May 2016) New Revision: e84fb8a6d12d0787ffaf49716f5b1461f79cab62 https://github.com/groonga/groonga/commit/e84fb8a6d12d0787ffaf49716f5b1461f79cab62 Message: select: evaluate slices before output Modified files: lib/proc/proc_select.c Modified: lib/proc/proc_select.c (+30 -40) =================================================================== --- lib/proc/proc_select.c 2016-05-22 21:05:07 +0900 (7614690) +++ lib/proc/proc_select.c 2016-05-22 21:11:50 +0900 (c233857) @@ -1468,17 +1468,6 @@ grn_select_output(grn_ctx *ctx, } static grn_bool -grn_select_prepare_slices(grn_ctx *ctx, - grn_select_data *data) -{ - if (data->slices) { - data->output.n_elements += 1; - } - - return GRN_TRUE; -} - -static grn_bool grn_select_slice_execute(grn_ctx *ctx, grn_select_data *data, grn_obj *table, @@ -1569,15 +1558,34 @@ grn_select_slices_execute(grn_ctx *ctx, } static grn_bool -grn_select_slices_output(grn_ctx *ctx, - grn_select_data *data, - grn_obj *table, - grn_hash *slices) +grn_select_prepare_slices(grn_ctx *ctx, + grn_select_data *data) +{ + if (!data->slices) { + return GRN_TRUE; + } + + if (!grn_select_slices_execute(ctx, data, data->tables.result, data->slices)) { + return GRN_FALSE; + } + + data->output.n_elements += 1; + + return GRN_TRUE; +} + +static grn_bool +grn_select_output_slices(grn_ctx *ctx, + grn_select_data *data) { grn_bool succeeded = GRN_TRUE; unsigned int n_available_results = 0; - GRN_HASH_EACH_BEGIN(ctx, slices, cursor, id) { + if (!data->slices) { + return GRN_TRUE; + } + + GRN_HASH_EACH_BEGIN(ctx, data->slices, cursor, id) { grn_slice_data *slice; grn_hash_cursor_get_value(ctx, cursor, (void **)&slice); @@ -1587,7 +1595,7 @@ grn_select_slices_output(grn_ctx *ctx, } GRN_HASH_EACH_END(ctx, cursor); GRN_OUTPUT_MAP_OPEN("SLICES", n_available_results); - GRN_HASH_EACH_BEGIN(ctx, slices, cursor, id) { + GRN_HASH_EACH_BEGIN(ctx, data->slices, cursor, id) { grn_slice_data *slice; uint32_t n_hits; int offset; @@ -1663,24 +1671,6 @@ grn_select_slices_output(grn_ctx *ctx, } static grn_bool -grn_select_slices(grn_ctx *ctx, - grn_select_data *data) -{ - if (!data->slices) { - return GRN_TRUE; - } - - if (!grn_select_slices_execute(ctx, data, data->tables.result, data->slices)) { - return GRN_FALSE; - } - if (!grn_select_slices_output(ctx, data, data->tables.result, data->slices)) { - return GRN_FALSE; - } - - return GRN_TRUE; -} - -static grn_bool grn_select_prepare_drilldowns(grn_ctx *ctx, grn_select_data *data) { @@ -2526,10 +2516,6 @@ grn_select(grn_ctx *ctx, grn_select_data *data) /* For select results */ data->output.n_elements = 1; - if (!grn_select_prepare_slices(ctx, data)) { - goto exit; - } - if (!grn_select_prepare_drilldowns(ctx, data)) { goto exit; } @@ -2549,6 +2535,10 @@ grn_select(grn_ctx *ctx, grn_select_data *data) goto exit; } + if (!grn_select_prepare_slices(ctx, data)) { + goto exit; + } + GRN_OUTPUT_ARRAY_OPEN("RESULT", data->output.n_elements); if (!grn_select_output(ctx, data)) { @@ -2556,7 +2546,7 @@ grn_select(grn_ctx *ctx, grn_select_data *data) goto exit; } - if (!grn_select_slices(ctx, data)) { + if (!grn_select_output_slices(ctx, data)) { GRN_OUTPUT_ARRAY_CLOSE(); goto exit; } -------------- next part -------------- HTML����������������������������...下载