Kouhei Sutou
null+****@clear*****
Wed May 17 09:51:17 JST 2017
Kouhei Sutou 2017-05-17 09:51:17 +0900 (Wed, 17 May 2017) New Revision: 4e171a1cb950c123c3a9f4fefb420700a5f35256 https://github.com/pgroonga/pgroonga/commit/4e171a1cb950c123c3a9f4fefb420700a5f35256 Message: Add pgroonga.match_escalation_threshold You can disable match escalation by setting -1 to the variable: SET pgroonga.match_escalation_threshold = -1; GitHub: fix #37 Reported by ArturFormella. Thanks!!! Added files: expected/variable/match-escalation-threshold/valid.out sql/variable/match-escalation-threshold/valid.sql Modified files: src/pgrn-global.c src/pgrn-global.h src/pgrn-variables.c src/pgroonga.c Added: expected/variable/match-escalation-threshold/valid.out (+27 -0) 100644 =================================================================== --- /dev/null +++ expected/variable/match-escalation-threshold/valid.out 2017-05-17 09:51:17 +0900 (59749e9) @@ -0,0 +1,27 @@ +-- To load PGroonga +SELECT pgroonga.command('status')::json->0->0; + ?column? +---------- + 0 +(1 row) + +SHOW pgroonga.match_escalation_threshold; + pgroonga.match_escalation_threshold +------------------------------------- + 0 +(1 row) + +SET pgroonga.match_escalation_threshold = -1; +SHOW pgroonga.match_escalation_threshold; + pgroonga.match_escalation_threshold +------------------------------------- + -1 +(1 row) + +SET pgroonga.match_escalation_threshold = default; +SHOW pgroonga.match_escalation_threshold; + pgroonga.match_escalation_threshold +------------------------------------- + 0 +(1 row) + Added: sql/variable/match-escalation-threshold/valid.sql (+8 -0) 100644 =================================================================== --- /dev/null +++ sql/variable/match-escalation-threshold/valid.sql 2017-05-17 09:51:17 +0900 (e3c01e0) @@ -0,0 +1,8 @@ +-- To load PGroonga +SELECT pgroonga.command('status')::json->0->0; + +SHOW pgroonga.match_escalation_threshold; +SET pgroonga.match_escalation_threshold = -1; +SHOW pgroonga.match_escalation_threshold; +SET pgroonga.match_escalation_threshold = default; +SHOW pgroonga.match_escalation_threshold; Modified: src/pgrn-global.c (+1 -0) =================================================================== --- src/pgrn-global.c 2017-05-09 08:59:08 +0900 (defcf38) +++ src/pgrn-global.c 2017-05-17 09:51:17 +0900 (2c75a3e) @@ -5,6 +5,7 @@ grn_ctx PGrnContext; struct PGrnBuffers PGrnBuffers; int PGrnKeepNSearchResults = -1; +int PGrnMatchEscalationThreshold = 0; static grn_ctx *ctx = &PGrnContext; Modified: src/pgrn-global.h (+1 -0) =================================================================== --- src/pgrn-global.h 2017-05-09 08:59:08 +0900 (27dfa45) +++ src/pgrn-global.h 2017-05-17 09:51:17 +0900 (234bf71) @@ -31,6 +31,7 @@ struct PGrnBuffers extern grn_ctx PGrnContext; extern struct PGrnBuffers PGrnBuffers; extern int PGrnKeepNSearchResults; +extern int PGrnMatchEscalationThreshold; void PGrnInitializeBuffers(void); void PGrnFinalizeBuffers(void); Modified: src/pgrn-variables.c (+46 -1) =================================================================== --- src/pgrn-variables.c 2017-05-09 08:59:08 +0900 (b6680eb) +++ src/pgrn-variables.c 2017-05-17 09:51:17 +0900 (4bd2540) @@ -167,7 +167,8 @@ PGrnQueryLogPathAssignRaw(const char *new_value) grn_default_query_logger_set_path(new_value); } - if (PGrnGroongaInitialized) { + if (PGrnGroongaInitialized) + { grn_ctx *ctx = &PGrnContext; grn_query_logger_reopen(ctx); } @@ -222,6 +223,31 @@ PGrnEnableWALAssign(bool new_value, void *extra) } } +static void +PGrnMatchEscalationThresholdAssignRaw(int new_value) +{ + if (!PGrnGroongaInitialized) + return; + + grn_set_default_match_escalation_threshold(new_value); + grn_ctx_set_match_escalation_threshold(&PGrnContext, new_value); +} + +#ifdef PGRN_IS_GREENPLUM +static bool +PGrnMatchEscalationThresholdAssign(int new_value, bool doit, GucSource source) +{ + PGrnMatchEscalationThresholdAssignRaw(new_value); + return true; +} +#else +static void +PGrnMatchEscalationThresholdAssign(int new_value, void *extra) +{ + PGrnMatchEscalationThresholdAssignRaw(new_value); +} +#endif + void PGrnInitializeVariables(void) { @@ -329,5 +355,24 @@ PGrnInitializeVariables(void) NULL, NULL); + PGrnDefineCustomIntVariable("pgroonga.match_escalation_threshold", + "The threshold number of matched records " + "for determining whether " + "loose search is used automatically. " + "-1 disables the auto loose search.", + "The default is 0. " + "It means that the number of matched records " + "is equal or less than 0, loose search is " + "used automtaically.", + &PGrnMatchEscalationThreshold, + grn_get_default_match_escalation_threshold(), + -1, + INT_MAX, + PGC_USERSET, + 0, + NULL, + PGrnMatchEscalationThresholdAssign, + NULL); + EmitWarningsOnPlaceholders("pgroonga"); } Modified: src/pgroonga.c (+2 -0) =================================================================== --- src/pgroonga.c 2017-05-09 08:59:08 +0900 (a4a3a1f) +++ src/pgroonga.c 2017-05-17 09:51:17 +0900 (64defe7) @@ -461,6 +461,8 @@ _PG_init(void) on_proc_exit(PGrnOnProcExit, 0); + grn_set_default_match_escalation_threshold(PGrnMatchEscalationThreshold); + if (grn_ctx_init(&PGrnContext, 0)) ereport(ERROR, (errcode(ERRCODE_SYSTEM_ERROR), -------------- next part -------------- HTML����������������������������...Download