Kouhei Sutou 2018-11-16 18:59:22 +0900 (Fri, 16 Nov 2018) Revision: b4b304e8060f8e23fe60d0ae1e6dd435b94592b2 https://github.com/groonga/groonga/commit/b4b304e8060f8e23fe60d0ae1e6dd435b94592b2 Message: query-log condition: support "func() > 0" case Modified files: lib/expr.c test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.expected test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.test Modified: lib/expr.c (+55 -21) =================================================================== --- lib/expr.c 2018-11-13 17:16:46 +0900 (d8f0a25b3) +++ lib/expr.c 2018-11-16 18:59:22 +0900 (a3a9c49db) @@ -4712,6 +4712,34 @@ grn_table_select_inspect_condition_argument(grn_ctx *ctx, } } +static void +grn_table_select_inspect_condition_call(grn_ctx *ctx, + grn_obj *buffer, + grn_expr_code *codes, + uint32_t start, + uint32_t end) +{ + uint32_t i; + + for (i = start; i <= end; i++) { + grn_expr_code *code = codes + i; + if (i == start) { + if (grn_obj_is_proc(ctx, code->value)) { + grn_inspect_name(ctx, buffer, code->value); + } else { + grn_table_select_inspect_condition_argument(ctx, buffer, code->value); + } + GRN_TEXT_PUTC(ctx, buffer, '('); + } else if (code->value) { + if (i > start + 1) { + GRN_TEXT_PUTS(ctx, buffer, ", "); + } + grn_table_select_inspect_condition_argument(ctx, buffer, code->value); + } + } + GRN_TEXT_PUTC(ctx, buffer, ')'); +} + static const char * grn_table_select_inspect_condition(grn_ctx *ctx, grn_obj *buffer, @@ -4741,23 +4769,11 @@ grn_table_select_inspect_condition(grn_ctx *ctx, switch (last_operator) { case GRN_OP_CALL : - for (i = si->start; i <= si->end; i++) { - grn_expr_code *code = expr->codes + i; - if (i == si->start) { - if (grn_obj_is_proc(ctx, code->value)) { - grn_inspect_name(ctx, buffer, code->value); - } else { - grn_table_select_inspect_condition_argument(ctx, buffer, code->value); - } - GRN_TEXT_PUTC(ctx, buffer, '('); - } else if (code->value) { - if (i > si->start + 1) { - GRN_TEXT_PUTS(ctx, buffer, ", "); - } - grn_table_select_inspect_condition_argument(ctx, buffer, code->value); - } - } - GRN_TEXT_PUTC(ctx, buffer, ')'); + grn_table_select_inspect_condition_call(ctx, + buffer, + expr->codes, + si->start, + si->end); break; case GRN_OP_EQUAL : case GRN_OP_NOT_EQUAL : @@ -4784,11 +4800,29 @@ grn_table_select_inspect_condition(grn_ctx *ctx, GRN_TEXT_PUTC(ctx, buffer, '('); for (i = si->start; i < si->end; i++) { grn_expr_code *code = expr->codes + i; - GRN_TEXT_PUTS(ctx, buffer, ", "); - if (code->value) { - grn_table_select_inspect_condition_argument(ctx, buffer, code->value); + if (i != si->start) { + GRN_TEXT_PUTS(ctx, buffer, ", "); + } + if (code->modify > 0 && code[code->modify].op == GRN_OP_CALL) { + grn_table_select_inspect_condition_call(ctx, + buffer, + code, + 0, + code->modify); + if (i + code->modify < si->end && + code[code->modify + 1].op == GRN_OP_PUSH) { + i += code->modify; + } else { + i += code->modify - 1; + } } else { - GRN_TEXT_PUTS(ctx, buffer, grn_operator_to_string(code->op)); + if (code->value) { + grn_table_select_inspect_condition_argument(ctx, + buffer, + code->value); + } else { + GRN_TEXT_PUTS(ctx, buffer, grn_operator_to_string(code->op)); + } } } GRN_TEXT_PUTC(ctx, buffer, ')'); Modified: test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.expected (+7 -0) =================================================================== --- test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.expected 2018-11-13 17:16:46 +0900 (76a0c7adf) +++ test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.expected 2018-11-16 18:59:22 +0900 (596c76281) @@ -62,3 +62,10 @@ select Shops --sortby '+_score, +name' --output_columns 'name, _score, locatio ] ] ] +#>select --filter "geo_in_circle(location, \"128429532x503148672\", 3000, \"rect\") > 0" --output_columns "name, _score, location" --scorer "_score = geo_distance(location, \"128429532x503148672\", \"rect\") * 1000" --sortby "+_score, +name" --table "Shops" +#:000000000000000 filter(7): greater(geo_in_circle(Shops.location, "128429532x503148672", 3000, "rect"), 0) +#:000000000000000 select(7) +#:000000000000000 score(7) +#:000000000000000 sort(7) +#:000000000000000 output(7) +#<000000000000000 rc=0 Modified: test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.test (+3 -0) =================================================================== --- test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.test 2018-11-13 17:16:46 +0900 (84be31540) +++ test/command/suite/select/filter/geo_in_circle/approximate_type/rect/not_use_index.test 2018-11-16 18:59:22 +0900 (42e8ca37a) @@ -1,6 +1,9 @@ #@include fixture/geo/taiyaki/init.grn +#$GRN_QUERY_LOG_SHOW_CONDITION=yes +#@collect-query-log true select Shops --sortby '+_score, +name' \ --output_columns 'name, _score, location' \ --filter 'geo_in_circle(location, "128429532x503148672", 3000, "rect") > 0' \ --scorer '_score = geo_distance(location, "128429532x503148672", "rect") * 1000' +#@collect-query-log false -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181116/0875971a/attachment-0001.html>