Kouhei Sutou
null+****@clear*****
Fri Aug 24 18:19:17 JST 2012
Kouhei Sutou 2012-08-24 18:19:17 +0900 (Fri, 24 Aug 2012) New Revision: 8cc2e2fd0f74b40c1242b330f8f4e3b21d7aa265 https://github.com/groonga/groonga/commit/8cc2e2fd0f74b40c1242b330f8f4e3b21d7aa265 Merged 77fe51a: Merge pull request #28 from groonga/add-all-records Log: Add all_records() It matches all records. It's fast rather than "true" literal because all_records() doesn't evaluate on each record. It just copies all record IDs to result set table. Note that getting all records is heavy process. You should use it only when you need it. Added files: test/function/suite/select/function/all_records/function.expected test/function/suite/select/function/all_records/function.test test/function/suite/select/function/all_records/selector.expected test/function/suite/select/function/all_records/selector.test Modified files: lib/expr.c lib/proc.c Modified: lib/expr.c (+17 -0) =================================================================== --- lib/expr.c 2012-08-24 18:11:51 +0900 (fcf4ce7) +++ lib/expr.c 2012-08-24 18:19:17 +0900 (045beb8) @@ -4281,6 +4281,23 @@ grn_table_select(grn_ctx *ctx, grn_obj *table, grn_obj *expr, /* todo : handle SCAN_PRE_CONST */ break; } + } else { + switch (si->op) { + case GRN_OP_CALL : + if (selector_proc_p(si->args[0])) { + grn_rc rc; + grn_proc *proc = (grn_obj *)(si->args[0]); + rc = proc->selector(ctx, table, NULL, si->nargs, si->args, + res, si->logical_op); + if (rc) { + /* TODO: report error */ + } else { + done++; + } + } + default : + break; + } } if (!done) { e->codes = codes + si->start; Modified: lib/proc.c (+41 -0) =================================================================== --- lib/proc.c 2012-08-24 18:11:51 +0900 (32be4f1) +++ lib/proc.c 2012-08-24 18:19:17 +0900 (4381e96) @@ -2724,6 +2724,39 @@ func_edit_distance(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_ return obj; } +static grn_obj * +func_all_records(grn_ctx *ctx, int nargs, grn_obj **args, + grn_user_data *user_data) +{ + grn_obj *true_value; + if ((true_value = GRN_PROC_ALLOC(GRN_DB_BOOL, 0))) { + GRN_BOOL_SET(ctx, true_value, GRN_TRUE); + } + return true_value; +} + +static grn_rc +selector_all_records(grn_ctx *ctx, grn_obj *table, grn_obj *index, + int nargs, grn_obj **args, + grn_obj *res, grn_operator op) +{ + grn_obj score; + + GRN_UINT32_INIT(&score, 0); + GRN_UINT32_SET(ctx, &score, 1); + + GRN_TABLE_EACH(ctx, table, 0, 0, id, NULL, NULL, NULL, { + grn_id result_id; + result_id = grn_table_add(ctx, res, &id, sizeof(grn_id), NULL); + grn_obj_set_value(ctx, res, result_id, &score, GRN_OBJ_SET); + }); + + GRN_OBJ_FIN(ctx, &score); + + return ctx->rc; +} + + #define DEF_VAR(v,name_str) do {\ (v).name = (name_str);\ (v).name_size = GRN_STRLEN(name_str);\ @@ -2885,4 +2918,12 @@ grn_db_init_builtin_query(grn_ctx *ctx) grn_proc_create(ctx, "edit_distance", 13, GRN_PROC_FUNCTION, func_edit_distance, NULL, NULL, 0, NULL); + + { + grn_obj *selector_proc; + + selector_proc = grn_proc_create(ctx, "all_records", 11, GRN_PROC_FUNCTION, + func_all_records, NULL, NULL, 0, NULL); + grn_proc_set_selector(ctx, selector_proc, selector_all_records); + } } Added: test/function/suite/select/function/all_records/function.expected (+47 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/function/all_records/function.expected 2012-08-24 18:19:17 +0900 (e24e43f) @@ -0,0 +1,47 @@ +table_create Softwares TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +load --table Softwares +[ +["_key"], +["groonga"], +["mroonga"], +["rroonga"] +] +[[0,0.0,0.0],3] +select Softwares --filter 'all_records() == true' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ] + ], + [ + 1, + "groonga" + ], + [ + 2, + "mroonga" + ], + [ + 3, + "rroonga" + ] + ] + ] +] Added: test/function/suite/select/function/all_records/function.test (+11 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/function/all_records/function.test 2012-08-24 18:19:17 +0900 (c04d5cc) @@ -0,0 +1,11 @@ +table_create Softwares TABLE_HASH_KEY ShortText + +load --table Softwares +[ +["_key"], +["groonga"], +["mroonga"], +["rroonga"] +] + +select Softwares --filter 'all_records() == true' Added: test/function/suite/select/function/all_records/selector.expected (+47 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/function/all_records/selector.expected 2012-08-24 18:19:17 +0900 (9fe0e0c) @@ -0,0 +1,47 @@ +table_create Softwares TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +load --table Softwares +[ +["_key"], +["groonga"], +["mroonga"], +["rroonga"] +] +[[0,0.0,0.0],3] +select Softwares --filter 'all_records()' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ] + ], + [ + 1, + "groonga" + ], + [ + 2, + "mroonga" + ], + [ + 3, + "rroonga" + ] + ] + ] +] Added: test/function/suite/select/function/all_records/selector.test (+11 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/function/all_records/selector.test 2012-08-24 18:19:17 +0900 (a848ffa) @@ -0,0 +1,11 @@ +table_create Softwares TABLE_HASH_KEY ShortText + +load --table Softwares +[ +["_key"], +["groonga"], +["mroonga"], +["rroonga"] +] + +select Softwares --filter 'all_records()' -------------- next part -------------- HTML����������������������������... Download