From 655eaf54d496aa471ef9ad5ff8d28d2c50dd0c38 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Fri, 24 Apr 2020 15:46:00 +0200 Subject: [PATCH 2/4] add GUC to enable binary search --- src/backend/executor/execExpr.c | 7 +++---- src/backend/executor/execExprInterp.c | 3 +++ src/backend/utils/misc/guc.c | 23 +++++++++++++++++++++++ src/include/executor/execExpr.h | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c index c202cc7e89..29a5b06852 100644 --- a/src/backend/executor/execExpr.c +++ b/src/backend/executor/execExpr.c @@ -49,8 +49,6 @@ #include "utils/lsyscache.h" #include "utils/typcache.h" -#define MIN_ARRAY_SIZE_FOR_BINARY_SEARCH 9 - typedef struct LastAttnumInfo { AttrNumber last_inner; @@ -979,7 +977,8 @@ ExecInitExprRec(Expr *node, ExprState *state, * looping through the entire array for each execution. */ if (opexpr->useOr && arrayarg && IsA(arrayarg, Const) && - !((Const *) arrayarg)->constisnull) + !((Const *) arrayarg)->constisnull && + enable_saop_binsearch) { Datum arrdatum = ((Const *) arrayarg)->constvalue; ArrayType *arr = (ArrayType *) DatumGetPointer(arrdatum); @@ -995,7 +994,7 @@ ExecInitExprRec(Expr *node, ExprState *state, * array to make it worth it. */ nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr)); - if (nitems >= MIN_ARRAY_SIZE_FOR_BINARY_SEARCH) + if (nitems >= enable_saop_threshold) { /* * Find the ordering op that matches the originally diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 5bebafbf0c..f72ff52f02 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -87,6 +87,9 @@ #define EEO_USE_COMPUTED_GOTO #endif /* HAVE_COMPUTED_GOTO */ +bool enable_saop_binsearch = true; +int enable_saop_threshold = 8; + /* * Macros for opcode dispatch. * diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 5bdc02fce2..ff9143a4ab 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -44,6 +44,7 @@ #include "commands/vacuum.h" #include "commands/variable.h" #include "common/string.h" +#include "executor/execExpr.h" #include "funcapi.h" #include "jit/jit.h" #include "libpq/auth.h" @@ -2060,6 +2061,17 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, + { + {"enable_saop_binsearch", PGC_USERSET, QUERY_TUNING_METHOD, + gettext_noop("Enables the use of binary search when processing SAOP conditions."), + NULL, + GUC_EXPLAIN + }, + &enable_saop_binsearch, + true, + NULL, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL @@ -3400,6 +3412,17 @@ static struct config_int ConfigureNamesInt[] = NULL, assign_tcp_user_timeout, show_tcp_user_timeout }, + { + {"enable_saop_threshold", PGC_USERSET, QUERY_TUNING_GEQO, + gettext_noop("when to use bloom filter or binary search."), + NULL, + GUC_EXPLAIN + }, + &enable_saop_threshold, + 8, 0, INT_MAX, + NULL, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL diff --git a/src/include/executor/execExpr.h b/src/include/executor/execExpr.h index ac4478d060..feddde264d 100644 --- a/src/include/executor/execExpr.h +++ b/src/include/executor/execExpr.h @@ -17,6 +17,9 @@ #include "executor/nodeAgg.h" #include "nodes/execnodes.h" +extern PGDLLIMPORT bool enable_saop_binsearch; +extern PGDLLIMPORT int enable_saop_threshold; + /* forward references to avoid circularity */ struct ExprEvalStep; struct SubscriptingRefState; -- 2.21.1