forked from huawei/openGauss-server
fix conflict
This commit is contained in:
commit
82d949068d
|
|
@ -653,7 +653,7 @@ enable_auto_explain|bool|0,0|NULL|NULL|
|
|||
auto_explain_level|enum|off,log,notice|NULL|NULL|
|
||||
cost_weight_index|real|1e-10,1e+10|NULL|NULL|
|
||||
default_limit_rows|real|-100,1.79769e+308|NULL|NULL|
|
||||
sql_beta_feature|enum|no_unique_index_first,sel_semi_poisson,sel_expr_instr,param_path_gen,rand_cost_opt,param_path_opt,page_est_opt,none|NULL|NULL|
|
||||
sql_beta_feature|enum|join_sel_with_cast_func,no_unique_index_first,sel_semi_poisson,sel_expr_instr,param_path_gen,rand_cost_opt,param_path_opt,page_est_opt,none|NULL|NULL|
|
||||
xlog_idle_flushes_before_sleep|int64|0,576460752303423487|NULL|NULL|
|
||||
wal_writer_cpu|int|-1,2147483647|NULL|NULL|
|
||||
wal_file_init_num|int|1,2147483647|NULL|NULL|
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ OBJS = acl.o arrayfuncs.o array_selfuncs.o array_typanalyze.o \
|
|||
tsquery_op.o tsquery_rewrite.o tsquery_util.o tsrank.o \
|
||||
tsvector.o tsvector_op.o tsvector_parser.o \
|
||||
txid.o uuid.o windowfuncs.o xml.o extended_statistics.o clientlogic_bytea.o clientlogicsettings.o \
|
||||
median_aggs.o
|
||||
median_aggs.o expr_distinct.o
|
||||
|
||||
like.o: like.cpp like_match.cpp
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,434 @@
|
|||
/* -------------------------------------------------------------------------
|
||||
*
|
||||
* expr_distinct.cpp
|
||||
* utility functions for get number of distinct of expressions
|
||||
*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/backend/utils/adt/expr_distinct.cpp
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "access/transam.h"
|
||||
#include "access/sysattr.h"
|
||||
#include "catalog/pg_statistic.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "nodes/nodes.h"
|
||||
#include "optimizer/cost.h"
|
||||
#include "optimizer/optimizerdebug.h"
|
||||
#include "optimizer/pathnode.h"
|
||||
#include "optimizer/planner.h"
|
||||
#include "optimizer/prep.h"
|
||||
#include "optimizer/restrictinfo.h"
|
||||
#include "optimizer/streamplan.h"
|
||||
#include "optimizer/var.h"
|
||||
#include "parser/analyze.h"
|
||||
#include "parser/parse_clause.h"
|
||||
#include "parser/parse_coerce.h"
|
||||
#include "parser/parsetree.h"
|
||||
#include "parser/parse_relation.h"
|
||||
#include "storage/buf/bufmgr.h"
|
||||
#include "storage/proc.h"
|
||||
#include "utils/dynahash.h"
|
||||
#include "utils/expr_distinct.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/selfuncs.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
/*
|
||||
* Context for estimate number of distinct of function
|
||||
*/
|
||||
typedef struct {
|
||||
double numDistinct[2]; /* numdistinct of the var */
|
||||
Oid attType; /* attType of current values */
|
||||
int numMcv; /* original number of MCV values in stats */
|
||||
int numHisBounds; /* original number of histogram bounds in stats */
|
||||
/* following data may change during runtime */
|
||||
int numFMcv; /* length of array mcvValues, may be changed at runtime */
|
||||
int numFHisBounds; /* length of array hisValues, simliar to mcvValues */
|
||||
Datum *fMcv; /* "MCV" values or f(..(MCV)), except NULL */
|
||||
Datum *fHisBounds; /* "histogram bounds" or f(..g(histogram bounds)), except NULL */
|
||||
bool needAdjust; /* whether var distinct need adjust */
|
||||
} EstiFuncDistinctContext;
|
||||
|
||||
static char *GetFunctionNameWithDefault(Oid fnOid);
|
||||
static void EstimateExprNumDistinct(PlannerInfo *root, VariableStatData *varData, Node *node, bool isJoinVar,
|
||||
bool *isDefault);
|
||||
static void GetNumDistinctFuncExpr(PlannerInfo *root, VariableStatData *varData, FuncExpr *funcExpr, bool isJoinVar);
|
||||
static void GetExprNumDistinctWalker(PlannerInfo *root, VariableStatData *varData, Node *node, bool isJoinVar);
|
||||
static void TransferFunctionNumDistinct(PlannerInfo *root, VariableStatData *varData, FuncExpr *funcExpr,
|
||||
bool isJoinVar);
|
||||
static bool CheckFuncArgsForTransferNumDistinct(FuncExpr *funcExpr, Node **varNode);
|
||||
static bool IsFunctionTransferNumDistinct(FuncExpr *funcExpr);
|
||||
|
||||
|
||||
/*
|
||||
* The array collects all of the type-cast functions which can transfer number of distinct from any one of
|
||||
* its arguments, other parameters are viewed as Const.
|
||||
*/
|
||||
static Oid g_typeCastFuncOids[] = {
|
||||
/* type cast from bool */
|
||||
BOOLTOINT1FUNCOID, BOOLTOINT2FUNCOID, BOOLTOINT4FUNCOID, BOOLTOINT8FUNCOID, BOOLTOTEXTFUNCOID,
|
||||
|
||||
/* type cast from int1 */
|
||||
I1TOI2FUNCOID, I1TOI4FUNCOID, I1TOI8FUNCOID, I1TOF4FUNCOID, I1TOF8FUNCOID, INT1TOBPCHARFUNCOID,
|
||||
INT1TOVARCHARFUNCOID, INT1TONVARCHAR2FUNCOID, INT1TOTEXTFUNCOID, INT1TONUMERICFUNCOID, INT1TOINTERVALFUNCOID,
|
||||
|
||||
/* type cast from int2 */
|
||||
I2TOI1FUNCOID, INT2TOINT4FUNCOID, INT2TOFLOAT4FUNCOID, INT2TOFLOAT8FUNCOID, INT2TOBPCHAR, INT2TOTEXTFUNCOID,
|
||||
INT2TOVARCHARFUNCOID, INT2TOINT8FUNCOID, INT2TONUMERICFUNCOID, INT2TOINTERVALFUNCOID,
|
||||
|
||||
/* type cast from int4 */
|
||||
I4TOI1FUNCOID, INT4TOINT2FUNCOID, INT4TOINT8FUNCOID, INT4TOFLOAT8FUNCOID, INTEGER2CASHFUNCOID,
|
||||
INT4TONUMERICFUNCOID, INT4TOINTERVALFUNCOID, INT4TOHEXFUNCOID, INT4TOBPCHARFUNCOID, INT4TOTEXTFUNCOID,
|
||||
INT4TOVARCHARFUNCOID, INT4TOCHARFUNCOID, INT4TOCHRFUNCOID,
|
||||
|
||||
/* type cast from int8 */
|
||||
I8TOI1FUNCOID, INT8TOINT2FUNCOID, INT8TOINT4FUNCOID, INT8TOBPCHARFUNCOID, INT8TOTEXTFUNCOID, INT8TOVARCHARFUNCOID,
|
||||
INT8TONUMERICFUNCOID, INT8TOHEXFUNCOID,
|
||||
|
||||
/* type cast from float4/float8 */
|
||||
FLOAT4TOBPCHARFUNCOID, FLOAT4TOTEXTFUNCOID, FLOAT4TOVARCHARFUNCOID, FLOAT4TOFLOAT8FUNCOID,
|
||||
FLOAT4TONUMERICFUNCOID, FLOAT8TOBPCHARFUNCOID, FLOAT8TOINTERVALFUNCOID, FLOAT8TOTEXTFUNCOID,
|
||||
FLOAT8TOVARCHARFUNCOID, FLOAT8TONUMERICFUNCOID, FLOAT8TOTIMESTAMPFUNCOID,
|
||||
|
||||
/* type cast from numeric */
|
||||
NUMERICTOBPCHARFUNCOID, NUMERICTOTEXTFUNCOID, NUMERICTOVARCHARFUNCOID,
|
||||
|
||||
/* type cast from timestamp/date/time */
|
||||
DEFAULTFORMATTIMESTAMP2CHARFUNCOID, DEFAULTFORMATTIMESTAMPTZ2CHARFUNCOID, TIMESATMPTOTEXTFUNCOID,
|
||||
TIMESTAMPTOVARCHARFUNCOID, TIMESTAMP2TIMESTAMPTZFUNCOID, TIMESTAMPTZ2TIMESTAMPFUNCOID,
|
||||
DATETIMESTAMPTZFUNCOID, DATETOTIMESTAMPFUNCOID, DATETOBPCHARFUNCOID, DATETOVARCHARFUNCOID, DATETOTEXTFUNCOID,
|
||||
DATEANDTIMETOTIMESTAMPFUNCOID, DTAETIME2TIMESTAMPTZFUNCOID, TIMETOINTERVALFUNCOID, TIMESTAMPZONETOTEXTFUNCOID,
|
||||
TIME2TIMETZFUNCOID, RELTIMETOINTERVALFUNCOID,
|
||||
|
||||
/* type cast from text */
|
||||
TODATEDEFAULTFUNCOID, TODATEFUNCOID, TOTIMESTAMPFUNCOID, TOTIMESTAMPDEFAULTFUNCOID,
|
||||
TEXTTOREGCLASSFUNCOID, TEXTTOINT1FUNCOID, TEXTTOINT2FUNCOID, TEXTTOINT4FUNCOID, TEXTTOINT8FUNCOID,
|
||||
TEXTTONUMERICFUNCOID, TEXTTOTIMESTAMP, TIMESTAMPTONEWTIMEZONEFUNCOID, TIMESTAMPTZTONEWTIMEZONEFUNCOID,
|
||||
HEXTORAWFUNCOID,
|
||||
|
||||
/* type cast from char/varchar/bpchar */
|
||||
VARCHARTONUMERICFUNCOID, VARCHARTOINT4FUNCOID, VARCHARTOINT8FUNCOID, VARCHARTOTIMESTAMPFUNCOID,
|
||||
BPCHARTOINT4FUNCOID, BPCHARTOINT8FUNCOID, BPCHARTONUMERICFUNCOID, BPCHARTOTIMESTAMPFUNCOID,
|
||||
RTRIM1FUNCOID, BPCHARTEXTFUNCOID, CHARTOBPCHARFUNCOID, CHARTOTEXTFUNCOID
|
||||
};
|
||||
|
||||
static char *GetFunctionNameWithDefault(Oid fnOid)
|
||||
{
|
||||
char *funcName = get_func_name(fnOid);
|
||||
if (funcName == NULL) {
|
||||
funcName = "unknown-name";
|
||||
}
|
||||
return funcName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Entrance of the distinct estimation for expr whose stats is unavailable
|
||||
*
|
||||
* Handle expr-case in get_variable_numdistinct, aim to estimate variable distinct if no stats
|
||||
* (for the variable) are available. Also, GUC 'cost_model_version' controls the behaviour of
|
||||
* the router.
|
||||
*
|
||||
* Note:
|
||||
* - function get_variable_numdistinct and get_variable_numdistinct_router should be called
|
||||
* after examine_variable, otherwise, it may fail to get stats which actually exists.
|
||||
* - This function may fail to estimate expr distinct, returns 0.0 (means unknown).
|
||||
* - adjust ratio will be applied to the raw distinct if needAdjust is true, and
|
||||
* varData->needAdjust is used to transfer the indicators.
|
||||
*/
|
||||
double GetExprNumDistinctRouter(VariableStatData *varData, bool needAdjust, STATS_EST_TYPE eType, bool isJoinVar)
|
||||
{
|
||||
double distinct = 0.0;
|
||||
|
||||
int idx = 0;
|
||||
bool saveNeedAdjust = varData->needAdjust;
|
||||
varData->needAdjust = needAdjust;
|
||||
|
||||
ereport(DEBUG2, (errmodule(MOD_OPT), errmsg(
|
||||
"[Get Expr NumDistinct Router]: -------- <START>: adjust: %s --------", needAdjust ? "true" : "false")));
|
||||
if (IS_PGXC_COORDINATOR && (eType == STATS_TYPE_LOCAL)) {
|
||||
/* for local distinct */
|
||||
idx = 0;
|
||||
} else {
|
||||
/* for global distinct */
|
||||
idx = 1;
|
||||
}
|
||||
if (varData->numDistinct[idx] > 0.0) {
|
||||
distinct = clamp_row_est(varData->numDistinct[idx]);
|
||||
} else if (!varData->isEstimated) {
|
||||
GetExprNumDistinctWalker(varData->root, varData, varData->var, isJoinVar);
|
||||
varData->isEstimated = true;
|
||||
if (varData->numDistinct[idx] > 0.0) {
|
||||
distinct = clamp_row_est(varData->numDistinct[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
varData->needAdjust = saveNeedAdjust;
|
||||
ereport(DEBUG2, (errmodule(MOD_OPT),
|
||||
errmsg("[Get Expr NumDistinct Router]: -------- <END>: distinct: %.0lf --------", distinct)));
|
||||
|
||||
return distinct;
|
||||
}
|
||||
|
||||
/*
|
||||
* implementation of GetExprNumDistinctRouter with "cost_model_version = 1"
|
||||
*
|
||||
* NB: parameters node may be varData->var or other form or sub-node of varData->var
|
||||
*/
|
||||
static void GetExprNumDistinctWalker(PlannerInfo *root, VariableStatData *varData, Node *node, bool isJoinVar)
|
||||
{
|
||||
char *exprName = NULL;
|
||||
|
||||
errno_t rc =
|
||||
memset_s(varData->numDistinct, sizeof(varData->numDistinct[0]) * 2, 0, sizeof(varData->numDistinct[0]) * 2);
|
||||
securec_check(rc, "\0", "\0");
|
||||
|
||||
switch (nodeTag(node)) {
|
||||
case T_FuncExpr:
|
||||
exprName = "FuncExpr";
|
||||
GetNumDistinctFuncExpr(root, varData, (FuncExpr *)node, isJoinVar);
|
||||
break;
|
||||
default:
|
||||
exprName = "Unknown-Expr";
|
||||
break;
|
||||
}
|
||||
|
||||
ereport(DEBUG2,
|
||||
(errmodule(MOD_OPT),
|
||||
(errmsg("[%s Distinct Estimation]: local distinct is %.0lf, global distinct is %.0lf",
|
||||
exprName, varData->numDistinct[0], varData->numDistinct[1]))));
|
||||
}
|
||||
|
||||
/*
|
||||
* Estimate the number of distinct of function expression.
|
||||
*
|
||||
* Parameters:
|
||||
* @in funcExpr: the function expression to calculate distinct value
|
||||
* @in isJoinVar: is the node used for join?
|
||||
*
|
||||
* @out: vardata: set the distinct value on numdistinct.
|
||||
*/
|
||||
static void GetNumDistinctFuncExpr(PlannerInfo *root, VariableStatData *varData, FuncExpr *funcExpr, bool isJoinVar)
|
||||
{
|
||||
if (funcExpr->funcid >= FirstNormalObjectId) {
|
||||
/* user-defined function, do nothing */
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Let p denotes function can transfer distinct, f all other functions, w type-cast functions
|
||||
* which can also transfer distinct. In general, p contains w. Then all possible cases are:
|
||||
* 1. p(p(p(..p(var)))): p include w,
|
||||
* transfer distinct of var to top level
|
||||
* 2. p(p(p(..p(f(var))))): p include w,
|
||||
* transfer distinct of f to top level, distinct of f is estimated from var
|
||||
* 3. f(var):
|
||||
* estimate distinct of f from var
|
||||
* 4. f(w(..w(var))
|
||||
* estimate distinct of f from var
|
||||
* 5. ..f(..(p(..))): p except w
|
||||
* can not estimate, return unknown
|
||||
* 6. ..f(..(f(..))):
|
||||
* can not estimate, return unknown
|
||||
*/
|
||||
|
||||
/* bool-return function */
|
||||
if (get_func_rettype(funcExpr->funcid) == BOOLOID) {
|
||||
varData->numDistinct[0] = 2.0;
|
||||
varData->numDistinct[1] = 2.0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (funcExpr->args == NULL) {
|
||||
ereport(DEBUG2,
|
||||
(errmodule(MOD_OPT),
|
||||
errmsg("[Func Distinct Estimation]:can not get number of distinct of function oid %u with no argument",
|
||||
funcExpr->funcid)));
|
||||
return;
|
||||
}
|
||||
|
||||
/* if failed to transfer, we can not estimate either */
|
||||
if (IsFunctionTransferNumDistinct(funcExpr)) {
|
||||
/* transfer the number of distinct */
|
||||
TransferFunctionNumDistinct(root, varData, funcExpr, isJoinVar);
|
||||
} else {
|
||||
/* estimate the number of distinct */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Estimate the number of distinct of the specifed node, work for get_num_distinct_coalesce,
|
||||
* get_num_distinct_casewhen and so on. The estimated numdistinct are always given, stored in
|
||||
* vardata->numdistinct[2].
|
||||
*
|
||||
* Parameters:
|
||||
* @in varData: the info we need to calculate distinct value, numdistinct is returned in varData
|
||||
* @in node: the node to calculate distinct value
|
||||
* @in isJoinVar: is the node used for join?
|
||||
* @out isDefault: is the numdistinct is a default value ?
|
||||
*/
|
||||
static void EstimateExprNumDistinct(PlannerInfo *root, VariableStatData *varData, Node *node, bool isJoinVar,
|
||||
bool *isDefault)
|
||||
{
|
||||
VariableStatData tmpVarData;
|
||||
SpecialJoinInfo sjInfo;
|
||||
errno_t rc = EOK;
|
||||
|
||||
varData->numDistinct[0] = 0.0;
|
||||
varData->numDistinct[1] = 0.0;
|
||||
|
||||
/* return after count it if it's Const. */
|
||||
if (IsA(node, Const)) {
|
||||
varData->numDistinct[0] = 1.0;
|
||||
varData->numDistinct[1] = 1.0;
|
||||
*isDefault = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/* XXX should min_lefthand ? */
|
||||
rc = memset_s(&sjInfo, sizeof(sjInfo), 0, sizeof(sjInfo));
|
||||
securec_check(rc, "\0", "\0");
|
||||
sjInfo.min_lefthand = root->all_baserels;
|
||||
sjInfo.min_righthand = NULL;
|
||||
|
||||
examine_variable(root, node, 0, &tmpVarData);
|
||||
tmpVarData.needAdjust = varData->needAdjust;
|
||||
double joinRatio = get_join_ratio(&tmpVarData, &sjInfo);
|
||||
varData->numDistinct[0] =
|
||||
get_variable_numdistinct(&tmpVarData, isDefault, tmpVarData.needAdjust, joinRatio, &sjInfo,
|
||||
STATS_TYPE_LOCAL, isJoinVar);
|
||||
varData->numDistinct[1] =
|
||||
get_variable_numdistinct(&tmpVarData, isDefault, tmpVarData.needAdjust, joinRatio, &sjInfo,
|
||||
STATS_TYPE_GLOBAL, isJoinVar);
|
||||
ReleaseVariableStats(tmpVarData);
|
||||
}
|
||||
|
||||
/*
|
||||
* try to transfer number of distinct of given funcExpr, return unknown if fail
|
||||
*/
|
||||
static void TransferFunctionNumDistinct(PlannerInfo *root, VariableStatData *varData, FuncExpr *funcExpr,
|
||||
bool isJoinVar)
|
||||
{
|
||||
bool isDefault = false;
|
||||
Node *varNode = NULL;
|
||||
|
||||
/* check arguments and find the var-argument */
|
||||
if (!CheckFuncArgsForTransferNumDistinct(funcExpr, &varNode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* recursive to the arg, if there is no distinct for the arg, return unknown */
|
||||
EstimateExprNumDistinct(root, varData, varNode, isJoinVar, &isDefault);
|
||||
|
||||
ereport(DEBUG2,
|
||||
(errmodule(MOD_OPT),
|
||||
errmsg("[Func Distinct Estimation]: succeed to transfer number of distinct of function oid: %u",
|
||||
funcExpr->funcid)));
|
||||
}
|
||||
|
||||
/*
|
||||
* check arguments of the func, return true and var-node if ok. Assume there is only one var or expr(var,..) in
|
||||
* its arguments. We allow f(var, const), f(const, var), f(expr(var), const) and f(expr(var1, var2), const)
|
||||
*
|
||||
* return true if ok, and varNode indicates the location of the Var
|
||||
*/
|
||||
static bool CheckFuncArgsForTransferNumDistinct(FuncExpr *funcExpr, Node **varNode)
|
||||
{
|
||||
ListCell *listCell = NULL;
|
||||
int numVars = 0;
|
||||
Node *lastNode = NULL;
|
||||
|
||||
/* find the first "var" */
|
||||
foreach (listCell, funcExpr->args) {
|
||||
Node *node = (Node *)lfirst(listCell);
|
||||
if (IsA(node, Var)) {
|
||||
numVars++;
|
||||
lastNode = node;
|
||||
} else if (IsA(node, Const)) {
|
||||
continue;
|
||||
} else {
|
||||
List *varList =
|
||||
pull_var_clause(node, PVC_RECURSE_AGGREGATES, PVC_RECURSE_PLACEHOLDERS, PVC_RECURSE_SPECIAL_EXPR);
|
||||
if (varList != NULL) {
|
||||
numVars++;
|
||||
lastNode = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numVars == 0) {
|
||||
*varNode = (Node *)linitial(funcExpr->args);
|
||||
return true;
|
||||
} else if (numVars == 1) {
|
||||
*varNode = lastNode;
|
||||
return true;
|
||||
} else {
|
||||
*varNode = NULL;
|
||||
ereport(DEBUG2, (errmodule(MOD_OPT),
|
||||
errmsg("[Check Args for Transfer]: more than one var-arguments for function oid: %u",
|
||||
funcExpr->funcid)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* check if the function can transfer number of distinct from one of its parameters
|
||||
*/
|
||||
static bool IsFunctionTransferNumDistinct(FuncExpr *funcExpr)
|
||||
{
|
||||
/*
|
||||
* We explicitly allow or disallow functions to transfer number of distinct.
|
||||
*
|
||||
* If a function called in form of COERCE_EXPLICIT_CAST/COERCE_IMPLICIT_CAST, we can not
|
||||
* conclude that this function can transfer number of distinct, e.g.
|
||||
*
|
||||
* create table t1(price text);
|
||||
* values: '20.01',
|
||||
* '20.02',
|
||||
* '20.12',
|
||||
* '20.30',
|
||||
* '20.99',
|
||||
* '20.88'
|
||||
* select price from t1 where int1(price) = 20;
|
||||
* The filter transformed by Optimizer is:
|
||||
* (((numeric_in(textout(price), 0::oid, (-1)))::tinyint)::bigint = 20)
|
||||
*
|
||||
* numeric::tinyint is the function numeric_int1 which is called as COERCE_EXPLICIT_CAST,
|
||||
* and it will make rounding to ensure an integer is assigned to int1. Hence a explicitly
|
||||
* cast function may not transfer number of distinct.
|
||||
*/
|
||||
|
||||
Oid funcId = funcExpr->funcid;
|
||||
char *funcName = GetFunctionNameWithDefault(funcExpr->funcid);
|
||||
|
||||
/* special functions whose oid is not built-in, but we can transfer numdistinct for them */
|
||||
if (strcmp(funcName, "to_text") == 0 || strcmp(funcName, "to_varchar2") == 0 ||
|
||||
strcmp(funcName, "to_nvarchar2") == 0 || strcmp(funcName, "to_ts") == 0 ||
|
||||
(strcmp(funcName, "to_number") == 0 && (funcId != TONUMBERFUNCOID))) {
|
||||
pfree(funcName);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)lengthof(g_typeCastFuncOids); i++) {
|
||||
if (g_typeCastFuncOids[i] == funcId) {
|
||||
pfree(funcName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
pfree(funcName);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -139,6 +139,7 @@
|
|||
#include "utils/bytea.h"
|
||||
#include "utils/date.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/expr_distinct.h"
|
||||
#include "utils/extended_statistics.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
|
@ -193,7 +194,7 @@ static Const* string_to_bytea_const(const char* str, size_t str_len);
|
|||
static List* specialExpr_group_num(PlannerInfo* root, List* nodeList, double* numdistinct, double rows);
|
||||
static List* add_unique_group_var(
|
||||
PlannerInfo* root, List* varinfos, Node* var, VariableStatData* vardata, STATS_EST_TYPE eType = STATS_TYPE_LOCAL);
|
||||
static double get_join_ratio(VariableStatData* vardata, SpecialJoinInfo* sjinfo);
|
||||
extern double get_join_ratio(VariableStatData* vardata, SpecialJoinInfo* sjinfo);
|
||||
bool can_use_possion(VariableStatData* vardata, SpecialJoinInfo* sjinfo, double* ratio);
|
||||
extern Datum pg_stat_get_last_analyze_time(PG_FUNCTION_ARGS);
|
||||
extern List* find_skew_join_distribute_keys(Plan* plan);
|
||||
|
|
@ -2275,9 +2276,9 @@ static double eqjoinsel_inner(
|
|||
double relfrac1 = 1.0, relfrac2 = 1.0, relfrac;
|
||||
|
||||
nd1 = get_variable_numdistinct(
|
||||
vardata1, &isdefault1, true, get_join_ratio(vardata1, sjinfo), sjinfo, STATS_TYPE_GLOBAL);
|
||||
vardata1, &isdefault1, true, get_join_ratio(vardata1, sjinfo), sjinfo, STATS_TYPE_GLOBAL, true);
|
||||
nd2 = get_variable_numdistinct(
|
||||
vardata2, &isdefault2, true, get_join_ratio(vardata2, sjinfo), sjinfo, STATS_TYPE_GLOBAL);
|
||||
vardata2, &isdefault2, true, get_join_ratio(vardata2, sjinfo), sjinfo, STATS_TYPE_GLOBAL, true);
|
||||
opfuncoid = get_opcode(opera);
|
||||
|
||||
if (HeapTupleIsValid(vardata1->statsTuple)) {
|
||||
|
|
@ -2655,9 +2656,9 @@ static double eqjoinsel_semi(
|
|||
|
||||
Oid opfuncoid = OidIsValid(opera) ? get_opcode(opera) : InvalidOid;
|
||||
nd1 = get_variable_numdistinct(
|
||||
vardata1, &isdefault1, true, get_join_ratio(vardata1, sjinfo), sjinfo, STATS_TYPE_GLOBAL);
|
||||
vardata1, &isdefault1, true, get_join_ratio(vardata1, sjinfo), sjinfo, STATS_TYPE_GLOBAL, true);
|
||||
nd2 = get_variable_numdistinct(
|
||||
vardata2, &isdefault2, true, get_join_ratio(vardata2, sjinfo), sjinfo, STATS_TYPE_GLOBAL);
|
||||
vardata2, &isdefault2, true, get_join_ratio(vardata2, sjinfo), sjinfo, STATS_TYPE_GLOBAL, true);
|
||||
/*
|
||||
* We clamp nd2 to be not more than what we estimate the inner relation's
|
||||
* size to be. This is intuitively somewhat reasonable since obviously
|
||||
|
|
@ -2861,9 +2862,9 @@ static double neqjoinsel_semi(
|
|||
|
||||
nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
|
||||
nd1 = get_variable_numdistinct(
|
||||
vardata1, &isdefault1, true, get_join_ratio(vardata1, sjinfo), sjinfo, STATS_TYPE_GLOBAL);
|
||||
vardata1, &isdefault1, true, get_join_ratio(vardata1, sjinfo), sjinfo, STATS_TYPE_GLOBAL, true);
|
||||
nd2 = get_variable_numdistinct(
|
||||
vardata2, &isdefault2, true, get_join_ratio(vardata2, sjinfo), sjinfo, STATS_TYPE_GLOBAL);
|
||||
vardata2, &isdefault2, true, get_join_ratio(vardata2, sjinfo), sjinfo, STATS_TYPE_GLOBAL, true);
|
||||
|
||||
/*
|
||||
* When one of the sides contains zero distinct values, the selectivity is zero;
|
||||
|
|
@ -4550,6 +4551,8 @@ void examine_variable(PlannerInfo* root, Node* node, int varRelid, VariableStatD
|
|||
errno_t rc = memset_s(vardata, sizeof(VariableStatData), 0, sizeof(VariableStatData));
|
||||
securec_check(rc, "\0", "\0");
|
||||
|
||||
vardata->root = root;
|
||||
|
||||
/* we enable possion to estimate distinct for default. */
|
||||
vardata->enablePossion = true;
|
||||
/* Save the exposed type of the expression */
|
||||
|
|
@ -4980,7 +4983,7 @@ statistic_proc_security_check(const VariableStatData *vardata, Oid func_oid)
|
|||
* compare the result to exact integer counts, or might divide by it.
|
||||
*/
|
||||
double get_variable_numdistinct(VariableStatData* vardata, bool* isdefault, bool adjust_rows, double join_ratio,
|
||||
SpecialJoinInfo* sjinfo, STATS_EST_TYPE eType)
|
||||
SpecialJoinInfo* sjinfo, STATS_EST_TYPE eType, bool isJoinVar)
|
||||
{
|
||||
double stadistinct;
|
||||
double stanullfrac = 0.0;
|
||||
|
|
@ -5067,6 +5070,19 @@ double get_variable_numdistinct(VariableStatData* vardata, bool* isdefault, bool
|
|||
if (vardata->isunique)
|
||||
stadistinct = -1.0 * (1.0 - stanullfrac);
|
||||
|
||||
/*
|
||||
* If no stats, try to get the estimation
|
||||
*/
|
||||
if (ENABLE_SQL_BETA_FEATURE(JOIN_SEL_WITH_CAST_FUNC) && !HeapTupleIsValid(vardata->statsTuple) &&
|
||||
stadistinct == 0.0) {
|
||||
stadistinct = GetExprNumDistinctRouter(vardata, adjust_rows, eType, isJoinVar);
|
||||
if (stadistinct > 0.0) {
|
||||
ereport(DEBUG2, (errmodule(MOD_OPT),
|
||||
errmsg("[Get Variable Distinct]: direct distinct is %.0lf by router, early return", stadistinct)));
|
||||
return clamp_row_est(stadistinct);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Otherwise we need to get the relation size; punt if not available.
|
||||
*/
|
||||
|
|
@ -6502,7 +6518,8 @@ static void genericcostestimate(PlannerInfo* root, IndexPath* path, double loop_
|
|||
* enough to not alter index-vs-seqscan decisions, but will prevent
|
||||
* indexes of different sizes from looking exactly equally attractive.
|
||||
*/
|
||||
*indexTotalCost += index->pages * spc_random_page_cost / 100000.0;
|
||||
if (ENABLE_SQL_BETA_FEATURE(INDEX_COST_WITH_LEAF_PAGES_ONLY))
|
||||
*indexTotalCost += index->pages * spc_random_page_cost / 100000.0;
|
||||
|
||||
/*
|
||||
* CPU cost: any complex expressions in the indexquals will need to be
|
||||
|
|
@ -8697,7 +8714,7 @@ void set_varratio_after_calc_selectivity(
|
|||
* Return:
|
||||
* minimum join ratio with specific relation
|
||||
*/
|
||||
static double get_join_ratio(VariableStatData* vardata, SpecialJoinInfo* sjinfo)
|
||||
double get_join_ratio(VariableStatData* vardata, SpecialJoinInfo* sjinfo)
|
||||
{
|
||||
double ratio = 1.0;
|
||||
ListCell* lc = NULL;
|
||||
|
|
|
|||
|
|
@ -994,6 +994,9 @@ static const struct config_enum_entry sql_beta_options[] = {
|
|||
{"page_est_opt", PAGE_EST_OPT, false},
|
||||
{"param_path_opt", PARAM_PATH_OPT, false},
|
||||
{"no_unique_index_first", NO_UNIQUE_INDEX_FIRST, false},
|
||||
{"join_sel_with_cast_func", JOIN_SEL_WITH_CAST_FUNC, false},
|
||||
{"canonical_pathkey", CANONICAL_PATHKEY, false},
|
||||
{"index_cost_with_leaf_pages_only", INDEX_COST_WITH_LEAF_PAGES_ONLY, false},
|
||||
{NULL, 0, false}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5573,7 +5573,7 @@ void convert_ORANY_to_join(
|
|||
|
||||
/* Replace this any sublink with "not null" expr. */
|
||||
or_clause =
|
||||
(BoolExpr*)replace_node_clause((Node*)or_clause, (Node*)any_sublink, (Node*)nullTest, RNC_RECURSE_AGGREF);
|
||||
(BoolExpr*)replace_node_clause((Node*)or_clause, (Node*)any_sublink, (Node*)nullTest, RNC_RECURSE_AGGREF | RNC_REPLACE_FIRST_ONLY);
|
||||
|
||||
if (root->glob->sublink_counter != 0 && ENABLE_PRED_PUSH_ALL(root)) {
|
||||
char *subquery_name = denominate_sublink_name(root->glob->sublink_counter);
|
||||
|
|
|
|||
|
|
@ -736,8 +736,12 @@ static void pgarch_ArchiverObsCopyLoop(XLogRecPtr flushPtr, doArchive fun)
|
|||
}
|
||||
|
||||
XLogRecPtr restartLsn = getRestartLsnFromSlot();
|
||||
/* we need to initialize the archive slot */
|
||||
if (restartLsn == InvalidXLogRecPtr) {
|
||||
continue;
|
||||
ereport(WARNING, (errmsg("the archive slot is not initialized, "
|
||||
"we should restart the archiver and init the archive slot")));
|
||||
t_thrd.arch.ready_to_stop = true;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 size = isObsSlot() ? OBS_XLOG_SLICE_BLOCK_SIZE : NAS_XLOG_FILE_SIZE;
|
||||
|
|
|
|||
|
|
@ -1980,4 +1980,4 @@ int PthreadMutexUnlock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace)
|
|||
RESUME_INTERRUPTS();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -94,6 +94,7 @@ lnext:
|
|||
ExecRowMark* erm = aerm->rowmark;
|
||||
Datum datum;
|
||||
bool isNull = false;
|
||||
bool rowMovement = false;
|
||||
HeapTupleData tuple;
|
||||
Buffer buffer;
|
||||
TM_FailureData tmfd;
|
||||
|
|
@ -141,7 +142,7 @@ lnext:
|
|||
Datum part_datum;
|
||||
|
||||
part_datum = ExecGetJunkAttribute(slot, aerm->toidAttNo, &isNull);
|
||||
|
||||
rowMovement = erm->relation->rd_rel->relrowmovement;
|
||||
tblid = DatumGetObjectId(part_datum);
|
||||
/* if it is a partition */
|
||||
if (tblid != erm->relation->rd_id) {
|
||||
|
|
@ -214,6 +215,16 @@ lnext:
|
|||
copy_tuple = tableam_tuple_lock_updated(estate->es_output_cid, bucket_rel, lock_mode, &tmfd.ctid, tmfd.xmax);
|
||||
if (copy_tuple == NULL) {
|
||||
/* Tuple was deleted, so don't return it */
|
||||
if (rowMovement) {
|
||||
/*
|
||||
* the may be a row movement update action which delete tuple from original
|
||||
* partition and insert tuple to new partition or we can add lock on the tuple to
|
||||
* be delete or updated to avoid throw exception
|
||||
*/
|
||||
ereport(ERROR, (errcode(ERRCODE_TRANSACTION_ROLLBACK),
|
||||
errmsg("partition table update conflict"),
|
||||
errdetail("disable row movement of table can avoid this conflict")));
|
||||
}
|
||||
goto lnext;
|
||||
}
|
||||
/* remember the actually locked tuple's TID */
|
||||
|
|
@ -242,6 +253,17 @@ lnext:
|
|||
|
||||
/* Tuple was deleted, so don't return it */
|
||||
Assert(ItemPointerEquals(&tmfd.ctid, &tuple.t_self));
|
||||
if (rowMovement) {
|
||||
/*
|
||||
* the may be a row movement update action which delete tuple from original
|
||||
* partition and insert tuple to new partition or we can add lock on the tuple to
|
||||
* be delete or updated to avoid throw exception
|
||||
*/
|
||||
ereport(ERROR, (errcode(ERRCODE_TRANSACTION_ROLLBACK),
|
||||
errmsg("partition table update conflict"),
|
||||
errdetail("disable row movement of table can avoid this conflict")));
|
||||
}
|
||||
|
||||
goto lnext;
|
||||
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -111,7 +111,9 @@ void log_slot_drop(const char *name)
|
|||
XLogRecPtr Ptr;
|
||||
ReplicationSlotPersistentData xlrec;
|
||||
|
||||
int rc = memcpy_s(xlrec.name.data, NAMEDATALEN, name, NAMEDATALEN);
|
||||
errno_t rc = memset_s(xlrec.name.data, NAMEDATALEN, 0, NAMEDATALEN);
|
||||
securec_check(rc, "\0", "\0");
|
||||
rc = memcpy_s(xlrec.name.data, NAMEDATALEN, name, strlen(name));
|
||||
securec_check(rc, "\0", "\0");
|
||||
START_CRIT_SECTION();
|
||||
XLogBeginInsert();
|
||||
|
|
|
|||
|
|
@ -168,7 +168,6 @@ typedef FormData_pg_proc *Form_pg_proc;
|
|||
#define TINTERVALINFUNCOID 246
|
||||
#define TINTERVALOUTFUNCOID 247
|
||||
#define TIMENOWFUNCOID 250
|
||||
#define INT4TOFLOAT8FUNCOID 316
|
||||
#define BTINT4CMP_OID 351
|
||||
#define RTRIM1FUNCOID 401
|
||||
#define NAME2TEXTFUNCOID 406
|
||||
|
|
@ -440,5 +439,99 @@ typedef FormData_pg_proc *Form_pg_proc;
|
|||
#define OID_REGEXP_SPLIT_TO_TABLE 2765
|
||||
#define OID_REGEXP_SPLIT_TO_TABLE_NO_FLAG 2766
|
||||
|
||||
/* cast functions oid */
|
||||
#define INT4TOCHARFUNCOID 78
|
||||
#define INT2TOFLOAT8FUNCOID 235
|
||||
#define INT2TOFLOAT4FUNCOID 236
|
||||
#define FLOAT4TOFLOAT8FUNCOID 311
|
||||
#define INT2TOINT4FUNCOID 313
|
||||
#define INT4TOINT2FUNCOID 314
|
||||
#define INT4TOFLOAT8FUNCOID 316
|
||||
#define BPCHARTEXTFUNCOID 405
|
||||
#define BOOLTOTEXTFUNCOID 2971
|
||||
#define BOOLTOINT8FUNCOID 3178
|
||||
#define BOOLTOINT2FUNCOID 3181
|
||||
#define INT8TOINT4FUNCOID 480
|
||||
#define INT4TOINT8FUNCOID 481
|
||||
#define INT8TOINT2FUNCOID 714
|
||||
#define INT2TOINT8FUNCOID 754
|
||||
#define CHARTOBPCHARFUNCOID 860
|
||||
#define CHARTOTEXTFUNCOID 946
|
||||
#define FLOAT8TOTIMESTAMPFUNCOID 1158
|
||||
#define TIMESTAMPTZTONEWTIMEZONEFUNCOID 1159
|
||||
#define RELTIMETOINTERVALFUNCOID 1177
|
||||
#define TIMETOINTERVALFUNCOID 1370
|
||||
#define INT4TOCHRFUNCOID 1621
|
||||
#define INT4TOHEXFUNCOID 2089
|
||||
#define INT8TOHEXFUNCOID 2090
|
||||
#define INT4TONUMERICFUNCOID 1740
|
||||
#define FLOAT4TONUMERICFUNCOID 1742
|
||||
#define FLOAT8TONUMERICFUNCOID 1743
|
||||
#define INT8TONUMERICFUNCOID 1781
|
||||
#define INT2TONUMERICFUNCOID 1782
|
||||
#define TEXTTOREGCLASSFUNCOID 1079
|
||||
#define DATEANDTIMETOTIMESTAMPFUNCOID 2025
|
||||
#define TIMESTAMPTONEWTIMEZONEFUNCOID 2069
|
||||
#define TEXTTOTIMESTAMP 4073
|
||||
#define HEXTORAWFUNCOID 4038
|
||||
#define DATETOTEXTFUNCOID 4159
|
||||
#define DATETOBPCHARFUNCOID 4160
|
||||
#define DATETOVARCHARFUNCOID 4161
|
||||
#define TIMESTAMPZONETOTEXTFUNCOID 4177
|
||||
#define TIMESATMPTOTEXTFUNCOID 4178
|
||||
#define TIMESTAMPTOVARCHARFUNCOID 4179
|
||||
#define FLOAT8TOINTERVALFUNCOID 4229
|
||||
#define INT1TONUMERICFUNCOID 5521
|
||||
#define I1TOI2FUNCOID 5523
|
||||
#define I2TOI1FUNCOID 5524
|
||||
#define I1TOI4FUNCOID 5525
|
||||
#define I4TOI1FUNCOID 5526
|
||||
#define I1TOI8FUNCOID 5527
|
||||
#define I8TOI1FUNCOID 5528
|
||||
#define I1TOF4FUNCOID 5529
|
||||
#define I1TOF8FUNCOID 5531
|
||||
#define BOOLTOINT1FUNCOID 5534
|
||||
#define INT4TOBPCHARFUNCOID 3192
|
||||
#define DATETOTIMESTAMPFUNCOID 2024
|
||||
#define BOOLTOINT4FUNCOID 2558
|
||||
#define INT1TOINTERVALFUNCOID 3189
|
||||
#define INT2TOINTERVALFUNCOID 3190
|
||||
#define INT4TOINTERVALFUNCOID 3191
|
||||
#define INT1TOTEXTFUNCOID 4165
|
||||
#define INT2TOTEXTFUNCOID 4166
|
||||
#define INT4TOTEXTFUNCOID 4167
|
||||
#define INT8TOTEXTFUNCOID 4168
|
||||
#define FLOAT4TOTEXTFUNCOID 4169
|
||||
#define FLOAT8TOTEXTFUNCOID 4170
|
||||
#define NUMERICTOTEXTFUNCOID 4171
|
||||
#define BPCHARTONUMERICFUNCOID 4172
|
||||
#define VARCHARTONUMERICFUNCOID 4173
|
||||
#define VARCHARTOINT4FUNCOID 4174
|
||||
#define BPCHARTOINT4FUNCOID 4175
|
||||
#define VARCHARTOINT8FUNCOID 4176
|
||||
#define INT2TOVARCHARFUNCOID 4180
|
||||
#define INT4TOVARCHARFUNCOID 4181
|
||||
#define INT8TOVARCHARFUNCOID 4182
|
||||
#define NUMERICTOVARCHARFUNCOID 4183
|
||||
#define FLOAT4TOVARCHARFUNCOID 4184
|
||||
#define FLOAT8TOVARCHARFUNCOID 4185
|
||||
#define VARCHARTOTIMESTAMPFUNCOID 4186
|
||||
#define BPCHARTOTIMESTAMPFUNCOID 4187
|
||||
#define TEXTTOINT1FUNCOID 4188
|
||||
#define TEXTTOINT2FUNCOID 4189
|
||||
#define TEXTTOINT4FUNCOID 4190
|
||||
#define TEXTTOINT8FUNCOID 4191
|
||||
#define TEXTTONUMERICFUNCOID 4194
|
||||
#define BPCHARTOINT8FUNCOID 4195
|
||||
#define INT1TOVARCHARFUNCOID 4065
|
||||
#define INT1TONVARCHAR2FUNCOID 4066
|
||||
#define INT1TOBPCHARFUNCOID 4067
|
||||
#define INT2TOBPCHAR 4068
|
||||
#define INT8TOBPCHARFUNCOID 4069
|
||||
#define FLOAT4TOBPCHARFUNCOID 4070
|
||||
#define FLOAT8TOBPCHARFUNCOID 4071
|
||||
#define NUMERICTOBPCHARFUNCOID 4072
|
||||
|
||||
|
||||
#endif /* PG_PROC_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
/* -------------------------------------------------------------------------
|
||||
*
|
||||
* expr_distinct.h
|
||||
* functions for get number of distinct of expressions.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
|
||||
*
|
||||
* src/include/utils/expr_distinct.h
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef EXPR_DISTINCT_H
|
||||
#define EXPR_DISTINCT_H
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "nodes/relation.h"
|
||||
#include "utils/selfuncs.h"
|
||||
#include "utils/be_module.h"
|
||||
|
||||
extern double GetExprNumDistinctRouter(VariableStatData *varData, bool needAdjust, STATS_EST_TYPE eType,
|
||||
bool isJoinVar);
|
||||
|
||||
#endif /* EXPR_DISTINCT_H */
|
||||
|
|
@ -357,7 +357,10 @@ typedef enum {
|
|||
RAND_COST_OPT = 8, /* Optimizing sc_random_page_cost */
|
||||
PARAM_PATH_OPT = 16, /* Parametrized Path Optimization. */
|
||||
PAGE_EST_OPT = 32, /* More accurate (rowstored) index pages estimation */
|
||||
NO_UNIQUE_INDEX_FIRST = 64 /* use unique index first rule in path generation */
|
||||
NO_UNIQUE_INDEX_FIRST = 64, /* use unique index first rule in path generation */
|
||||
JOIN_SEL_WITH_CAST_FUNC = 128, /* support cast function while calculating join selectivity */
|
||||
CANONICAL_PATHKEY = 256, /* Use canonicalize pathkeys directly */
|
||||
INDEX_COST_WITH_LEAF_PAGES_ONLY = 512 /* compute index cost with consideration of leaf-pages-only */
|
||||
} sql_beta_param;
|
||||
|
||||
#define ENABLE_PRED_PUSH(root) \
|
||||
|
|
|
|||
|
|
@ -100,6 +100,13 @@ typedef struct VariableStatData {
|
|||
bool isunique; /* matches unique index or DISTINCT clause */
|
||||
bool enablePossion; /* indentify we can use possion or not */
|
||||
bool acl_ok; /* result of ACL check on table or column */
|
||||
PlannerInfo *root; /* Planner info the var reference */
|
||||
double numDistinct[2]; /* estimated numdistinct, 0: means unknown, [0]: local, [1]: global */
|
||||
bool isEstimated; /* indicate that whether estimation have already been done */
|
||||
PlannerInfo *baseRoot; /* Planner info of the baseVar */
|
||||
Node *baseVar; /* base Var, owner of the statsTuple */
|
||||
RelOptInfo *baseRel; /* rel of the baseVar */
|
||||
bool needAdjust; /* true if need adjust on rel */
|
||||
} VariableStatData;
|
||||
|
||||
#define ReleaseVariableStats(vardata) \
|
||||
|
|
@ -129,6 +136,7 @@ typedef struct {
|
|||
} GroupVarInfo;
|
||||
|
||||
extern void set_local_rel_size(PlannerInfo* root, RelOptInfo* rel);
|
||||
extern double get_join_ratio(VariableStatData* vardata, SpecialJoinInfo* sjinfo);
|
||||
extern double get_multiple_by_distkey(PlannerInfo* root, List* distkey, double rows);
|
||||
extern double estimate_agg_num_distinct(PlannerInfo* root, List* group_exprs, Plan* plan, const double* numGroups);
|
||||
extern double estimate_agg_num_distinct(PlannerInfo* root, List* group_exprs, Path* path, const double* numGroups);
|
||||
|
|
@ -168,7 +176,8 @@ extern bool get_restriction_variable(
|
|||
extern void get_join_variables(PlannerInfo* root, List* args, SpecialJoinInfo* sjinfo, VariableStatData* vardata1,
|
||||
VariableStatData* vardata2, bool* join_is_reversed);
|
||||
extern double get_variable_numdistinct(VariableStatData* vardata, bool* isdefault, bool adjust_rows = true,
|
||||
double join_ratio = 1.0, SpecialJoinInfo* sjinfo = NULL, STATS_EST_TYPE eType = STATS_TYPE_GLOBAL);
|
||||
double join_ratio = 1.0, SpecialJoinInfo* sjinfo = NULL, STATS_EST_TYPE eType = STATS_TYPE_GLOBAL,
|
||||
bool isJoinVar = false);
|
||||
extern double mcv_selectivity(VariableStatData* vardata, FmgrInfo* opproc, Datum constval, bool varonleft,
|
||||
double* sumcommonp, Oid equaloperator, bool* inmcv, double* lastcommonp = NULL);
|
||||
extern double histogram_selectivity(VariableStatData* vardata, FmgrInfo* opproc, Datum constval, bool varonleft,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ set enable_seqscan=off;
|
|||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
|
||||
drop table if exists test_bypass_sq1;
|
||||
NOTICE: table "test_bypass_sq1" does not exist, skipping
|
||||
create table test_bypass_sq1(col1 int, col2 int, col3 text);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ set enable_seqscan=off;
|
|||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
|
||||
-- create table
|
||||
drop table if exists test_bypass_sq1;
|
||||
NOTICE: table "test_bypass_sq1" does not exist, skipping
|
||||
|
|
|
|||
|
|
@ -227,11 +227,11 @@ Number of partition: 5 (View pg_partition to check each partition range.)
|
|||
|
||||
insert into test_gpi_create_like values(generate_series(0,9999), 1);
|
||||
explain (costs off) select * from test_gpi_create_like where c1 = 0;
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------
|
||||
Bitmap Heap Scan on test_gpi_create_like
|
||||
Recheck Cond: (c1 = 0)
|
||||
-> Bitmap Index Scan on test_gpi_create_like_c1_tableoid_idx
|
||||
-> Bitmap Index Scan on test_gpi_create_like_c1_c2_tableoid_idx
|
||||
Index Cond: (c1 = 0)
|
||||
(4 rows)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ select a.relname,a.parttype,a.reloptions from pg_partition a, pg_class b where a
|
|||
(2 rows)
|
||||
|
||||
explain (costs off) select * from test_gpi_more_invalid where a >= 3000;
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------
|
||||
Index Scan using global_index_gpi_more_invalid_b on test_gpi_more_invalid
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------
|
||||
Index Only Scan using global_index_gpi_more_invalid_a_b_c on test_gpi_more_invalid
|
||||
Index Cond: (a >= 3000)
|
||||
(2 rows)
|
||||
|
||||
|
|
@ -55,10 +55,10 @@ explain (costs off) select count(*) from test_gpi_more_invalid where a <= 100 an
|
|||
(4 rows)
|
||||
|
||||
explain (costs off) select count(*) from test_gpi_more_invalid where a > 3000;
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------
|
||||
Aggregate
|
||||
-> Index Only Scan using global_index_gpi_more_invalid_b on test_gpi_more_invalid
|
||||
-> Index Only Scan using global_index_gpi_more_invalid_a_b_c on test_gpi_more_invalid
|
||||
Index Cond: (a > 3000)
|
||||
(3 rows)
|
||||
|
||||
|
|
|
|||
|
|
@ -119,12 +119,11 @@ select * from gpi_index_test where a < 200 and b > 190 order by a;
|
|||
-- multi column index with global index
|
||||
create index gpi_index_test_global_a_b on gpi_index_test(a,b) global;
|
||||
explain (costs off) select * from gpi_index_test where a = 200 and b = 100;
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------
|
||||
Index Scan using gpi_index_test_global_b on gpi_index_test
|
||||
Index Cond: (b = 100)
|
||||
Filter: (a = 200)
|
||||
(3 rows)
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------
|
||||
Index Scan using gpi_index_test_global_a_b on gpi_index_test
|
||||
Index Cond: ((a = 200) AND (b = 100))
|
||||
(2 rows)
|
||||
|
||||
select * from gpi_index_test where a = 100 and b = 100 order by a;
|
||||
a | b | c
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,33 +1,34 @@
|
|||
set enable_opfusion=on;
|
||||
set enable_partition_opfusion=on;
|
||||
set enable_bitmapscan=off;
|
||||
set enable_seqscan=off;
|
||||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
--create table
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
set enable_opfusion=on;
|
||||
set enable_partition_opfusion=on;
|
||||
set enable_bitmapscan=off;
|
||||
set enable_seqscan=off;
|
||||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
|
||||
--create table
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
NOTICE: table "test_bypass_sql_partition" does not exist, skipping
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
|
||||
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
|
||||
|
||||
|
||||
|
||||
explain execute p11(0,0,'test_insert');
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
|
||||
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
|
||||
|
||||
|
||||
|
||||
explain execute p11(0,0,'test_insert');
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -35,13 +36,13 @@ explain execute p11(0,0,'test_insert');
|
|||
-> Result (cost=0.00..0.01 rows=1 width=0)
|
||||
(3 rows)
|
||||
|
||||
execute p11(10,10,'test_insert');
|
||||
execute p11(12,12,'test_insert');
|
||||
execute p11(-1,-1,'test_insert2');
|
||||
execute p11(23,23,'test_insert2');
|
||||
execute p11(33,33,'test_insert3');
|
||||
execute p11(0,0,'test_insert3');
|
||||
explain execute p12(1,1);
|
||||
execute p11(10,10,'test_insert');
|
||||
execute p11(12,12,'test_insert');
|
||||
execute p11(-1,-1,'test_insert2');
|
||||
execute p11(23,23,'test_insert2');
|
||||
execute p11(33,33,'test_insert3');
|
||||
execute p11(0,0,'test_insert3');
|
||||
explain execute p12(1,1);
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -49,18 +50,18 @@ explain execute p12(1,1);
|
|||
-> Result (cost=0.00..0.01 rows=1 width=0)
|
||||
(3 rows)
|
||||
|
||||
execute p12(1,1);
|
||||
execute p12(22,22);
|
||||
execute p12(20,20);
|
||||
|
||||
--nobypass
|
||||
execute p11(null,null,null);
|
||||
execute p12(1,1);
|
||||
execute p12(22,22);
|
||||
execute p12(20,20);
|
||||
|
||||
--nobypass
|
||||
execute p11(null,null,null);
|
||||
ERROR: inserted partition key does not map to any table partition
|
||||
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
execute p_insert1;
|
||||
--bypass
|
||||
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
|
||||
explain execute p13(0,0);
|
||||
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
execute p_insert1;
|
||||
--bypass
|
||||
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
|
||||
explain execute p13(0,0);
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -71,39 +72,39 @@ explain execute p13(0,0);
|
|||
Selected Partitions: PART
|
||||
(6 rows)
|
||||
|
||||
execute p13(0,0);
|
||||
execute p13(0,0);
|
||||
col1 | col2 | col3
|
||||
------+------+--------------
|
||||
0 | 0 | test_insert3
|
||||
0 | 0 | aaaaaaa
|
||||
(2 rows)
|
||||
|
||||
execute p13(10,0);
|
||||
execute p13(10,0);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
10 | 0 | aaaaaaa
|
||||
(1 row)
|
||||
|
||||
execute p13(20,0);
|
||||
execute p13(20,0);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
20 | 0 | aaaaaaa
|
||||
(1 row)
|
||||
|
||||
execute p13(30,0);
|
||||
execute p13(30,0);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
30 | 0 | aaaaaaa
|
||||
(1 row)
|
||||
|
||||
execute p13(40,0);
|
||||
execute p13(40,0);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
40 | 0 | aaaaaaa
|
||||
(1 row)
|
||||
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p13(0,0);
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p13(0,0);
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -114,16 +115,16 @@ explain execute p13(0,0);
|
|||
Selected Partitions: PART
|
||||
(6 rows)
|
||||
|
||||
execute p13(0,0);
|
||||
execute p13(0,0);
|
||||
col1 | col2 | col3
|
||||
------+------+--------------
|
||||
0 | 0 | test_insert3
|
||||
0 | 0 | aaaaaaa
|
||||
(2 rows)
|
||||
|
||||
reset enable_indexonlyscan;
|
||||
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
|
||||
explain execute p15 (0,0,'test_update',-1);
|
||||
reset enable_indexonlyscan;
|
||||
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
|
||||
explain execute p15 (0,0,'test_update',-1);
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -135,9 +136,9 @@ explain execute p15 (0,0,'test_update',-1);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p15 (0,0,'test_update',-1);
|
||||
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
|
||||
explain execute p16(5,3,1,1);
|
||||
execute p15 (0,0,'test_update',-1);
|
||||
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
|
||||
explain execute p16(5,3,1,1);
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -149,13 +150,13 @@ explain execute p16(5,3,1,1);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p16(5,3,1,1);
|
||||
|
||||
|
||||
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
|
||||
execute p101 (111,'test_update2',-1);
|
||||
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
|
||||
execute p102 (1);
|
||||
execute p16(5,3,1,1);
|
||||
|
||||
|
||||
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
|
||||
execute p101 (111,'test_update2',-1);
|
||||
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
|
||||
execute p102 (1);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
1 | 0 | aaaaaaa
|
||||
|
|
@ -172,14 +173,14 @@ execute p102 (1);
|
|||
1 | 100 | aaaaaaa
|
||||
(12 rows)
|
||||
|
||||
|
||||
|
||||
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
|
||||
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
|
||||
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
|
||||
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
|
||||
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
|
||||
explain execute p1011;
|
||||
|
||||
|
||||
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
|
||||
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
|
||||
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
|
||||
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
|
||||
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
|
||||
explain execute p1011;
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -187,8 +188,8 @@ explain execute p1011;
|
|||
-> Result (cost=0.00..0.01 rows=1 width=0)
|
||||
(3 rows)
|
||||
|
||||
execute p1011;
|
||||
explain execute p1012;
|
||||
execute p1011;
|
||||
explain execute p1012;
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -199,13 +200,13 @@ explain execute p1012;
|
|||
Selected Partitions: 1
|
||||
(6 rows)
|
||||
|
||||
execute p1012;
|
||||
execute p1012;
|
||||
col1 | col2 | col3
|
||||
------+------+----------
|
||||
-3 | -3 | test_pbe
|
||||
(1 row)
|
||||
|
||||
explain execute p1013;
|
||||
explain execute p1013;
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -217,8 +218,8 @@ explain execute p1013;
|
|||
Selected Partitions: 1
|
||||
(7 rows)
|
||||
|
||||
execute p1013;
|
||||
explain execute p1014;
|
||||
execute p1013;
|
||||
explain execute p1014;
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -230,14 +231,14 @@ explain execute p1014;
|
|||
Selected Partitions: 1
|
||||
(7 rows)
|
||||
|
||||
execute p1014;
|
||||
execute p1014;
|
||||
col1 | col2 | col3
|
||||
------+------+----------
|
||||
-3 | 10 | test_pbe
|
||||
(1 row)
|
||||
|
||||
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
|
||||
explain execute p10141;
|
||||
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
|
||||
explain execute p10141;
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -249,15 +250,15 @@ explain execute p10141;
|
|||
Selected Partitions: 1
|
||||
(7 rows)
|
||||
|
||||
execute p10141;
|
||||
execute p10141;
|
||||
col1 | col2
|
||||
------+------
|
||||
-3 | 10
|
||||
(1 row)
|
||||
|
||||
|
||||
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p1021(1);
|
||||
|
||||
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p1021(1);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -269,16 +270,16 @@ explain execute p1021(1);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p1021(1);
|
||||
execute p1021(1);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
1 | 0 | aaaaaaa
|
||||
(1 row)
|
||||
|
||||
--bypass through index only scan
|
||||
|
||||
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p10211(1);
|
||||
--bypass through index only scan
|
||||
|
||||
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p10211(1);
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -290,14 +291,14 @@ explain execute p10211(1);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p10211(1);
|
||||
execute p10211(1);
|
||||
col1 | col2
|
||||
------+------
|
||||
1 | 0
|
||||
(1 row)
|
||||
|
||||
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
|
||||
explain execute p10212(1);
|
||||
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
|
||||
explain execute p10212(1);
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -309,7 +310,7 @@ explain execute p10212(1);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p10212(1);
|
||||
execute p10212(1);
|
||||
col1 | col2
|
||||
------+------
|
||||
1 | 2
|
||||
|
|
@ -325,8 +326,8 @@ execute p10212(1);
|
|||
1 | 100
|
||||
(11 rows)
|
||||
|
||||
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
|
||||
explain execute p10213(1);
|
||||
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
|
||||
explain execute p10213(1);
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -338,14 +339,14 @@ explain execute p10213(1);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p10213(1);
|
||||
execute p10213(1);
|
||||
col1 | col2
|
||||
------+------
|
||||
1 | 0
|
||||
(1 row)
|
||||
|
||||
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
|
||||
explain execute p10214(1);
|
||||
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
|
||||
explain execute p10214(1);
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -357,7 +358,7 @@ explain execute p10214(1);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p10214(1);
|
||||
execute p10214(1);
|
||||
col1 | col2
|
||||
------+------
|
||||
1 | 0
|
||||
|
|
@ -374,25 +375,25 @@ execute p10214(1);
|
|||
1 | 100
|
||||
(12 rows)
|
||||
|
||||
|
||||
|
||||
|
||||
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
|
||||
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
|
||||
execute p1024;
|
||||
|
||||
|
||||
|
||||
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
|
||||
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
|
||||
execute p1024;
|
||||
col1 | col2 | col3
|
||||
------+------+-------------
|
||||
0 | -1 | test_update
|
||||
(1 row)
|
||||
|
||||
execute p1025(1);
|
||||
execute p1025(1);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
1 | 0 | aaaaaaa
|
||||
(1 row)
|
||||
|
||||
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
|
||||
execute p104 (3);
|
||||
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
|
||||
execute p104 (3);
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
3 | 0 | aaaaaaa
|
||||
|
|
@ -408,16 +409,16 @@ execute p104 (3);
|
|||
3 | 100 | aaaaaaa
|
||||
(11 rows)
|
||||
|
||||
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
|
||||
execute p1052(2);
|
||||
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
|
||||
execute p1052(2);
|
||||
col1 | col2
|
||||
------+------
|
||||
2 | 0
|
||||
2 | 10
|
||||
(2 rows)
|
||||
|
||||
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
|
||||
execute p10601 (0,10,1);
|
||||
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
|
||||
execute p10601 (0,10,1);
|
||||
col1 | col2
|
||||
------+------
|
||||
1 | 2
|
||||
|
|
@ -513,17 +514,17 @@ execute p10601 (0,10,1);
|
|||
9 | 100
|
||||
(91 rows)
|
||||
|
||||
|
||||
--nobypass
|
||||
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
execute p1020;
|
||||
|
||||
--nobypass
|
||||
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
execute p1020;
|
||||
col1 | col2 | col3
|
||||
------+------+---------
|
||||
1 | 0 | aaaaaaa
|
||||
(1 row)
|
||||
|
||||
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
explain execute p10200;
|
||||
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
explain execute p10200;
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not support query in multiple partitions.
|
||||
|
|
@ -535,14 +536,14 @@ explain execute p10200;
|
|||
Selected Partitions: 1..8
|
||||
(7 rows)
|
||||
|
||||
execute p10200;
|
||||
execute p10200;
|
||||
col1 | col2
|
||||
------+------
|
||||
1 | 0
|
||||
(1 row)
|
||||
|
||||
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
|
||||
explain execute p1022(0,3);
|
||||
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
|
||||
explain execute p1022(0,3);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
|
||||
|
|
@ -554,7 +555,7 @@ explain execute p1022(0,3);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p1022(0,3);
|
||||
execute p1022(0,3);
|
||||
col1 | col2 | col3
|
||||
------+------+-------------
|
||||
0 | -1 | test_update
|
||||
|
|
@ -562,7 +563,7 @@ execute p1022(0,3);
|
|||
0 | 1 | test
|
||||
(3 rows)
|
||||
|
||||
explain execute p1022(0,null);
|
||||
explain execute p1022(0,null);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
|
||||
|
|
@ -574,7 +575,7 @@ explain execute p1022(0,null);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p1022(0,null);
|
||||
execute p1022(0,null);
|
||||
col1 | col2 | col3
|
||||
------+------+-------------
|
||||
0 | -1 | test_update
|
||||
|
|
@ -691,8 +692,8 @@ execute p1022(0,null);
|
|||
0 | 100 | aaaaaaa
|
||||
(112 rows)
|
||||
|
||||
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
|
||||
explain execute p1023(0,3,2);
|
||||
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
|
||||
explain execute p1023(0,3,2);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
|
||||
|
|
@ -704,7 +705,7 @@ explain execute p1023(0,3,2);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p1023(0,3,2);
|
||||
execute p1023(0,3,2);
|
||||
col1 | col2 | col3
|
||||
------+------+------
|
||||
0 | 1 | test
|
||||
|
|
@ -712,9 +713,9 @@ execute p1023(0,3,2);
|
|||
0 | 3 | test
|
||||
(3 rows)
|
||||
|
||||
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
|
||||
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
|
||||
explain execute p1026(0,3);
|
||||
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
|
||||
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
|
||||
explain execute p1026(0,3);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
|
||||
|
|
@ -727,7 +728,7 @@ explain execute p1026(0,3);
|
|||
Selected Partitions: PART
|
||||
(8 rows)
|
||||
|
||||
execute p1026(0,3);
|
||||
execute p1026(0,3);
|
||||
col1 | col2 | col3
|
||||
------+------+-------------
|
||||
0 | -1 | test_update
|
||||
|
|
@ -735,7 +736,7 @@ execute p1026(0,3);
|
|||
0 | 1 | test
|
||||
(3 rows)
|
||||
|
||||
explain execute p1027(0,3,2);
|
||||
explain execute p1027(0,3,2);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because query used limit grammar with a non-constant value.
|
||||
|
|
@ -748,7 +749,7 @@ explain execute p1027(0,3,2);
|
|||
Selected Partitions: PART
|
||||
(8 rows)
|
||||
|
||||
execute p1027(0,3,2);
|
||||
execute p1027(0,3,2);
|
||||
col1 | col2 | col3
|
||||
------+------+------
|
||||
0 | 1 | test
|
||||
|
|
@ -756,24 +757,24 @@ execute p1027(0,3,2);
|
|||
0 | 3 | test
|
||||
(3 rows)
|
||||
|
||||
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
|
||||
execute p103 (2);
|
||||
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
|
||||
execute p103 (2);
|
||||
col1 | col2
|
||||
------+------
|
||||
0 | 2
|
||||
1 | 2
|
||||
(2 rows)
|
||||
|
||||
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
|
||||
execute p105 (5);
|
||||
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
|
||||
execute p105 (5);
|
||||
col1 | col2
|
||||
------+------
|
||||
-3 | 10
|
||||
-1 | 111
|
||||
(2 rows)
|
||||
|
||||
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
|
||||
execute p1051(5,3);
|
||||
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
|
||||
execute p1051(5,3);
|
||||
col1 | col2
|
||||
------+------
|
||||
4 | 0
|
||||
|
|
@ -781,8 +782,8 @@ execute p1051(5,3);
|
|||
4 | 20
|
||||
(3 rows)
|
||||
|
||||
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
|
||||
execute p106 (0,1);
|
||||
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
|
||||
execute p106 (0,1);
|
||||
col1 | col2
|
||||
------+------
|
||||
1 | 2
|
||||
|
|
@ -790,16 +791,16 @@ execute p106 (0,1);
|
|||
1 | 20
|
||||
(3 rows)
|
||||
|
||||
|
||||
--bypass
|
||||
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
|
||||
execute p17 (3,3);
|
||||
|
||||
--bypass
|
||||
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
|
||||
execute p17 (3,3);
|
||||
col1 | col2 | col3
|
||||
------+------+------
|
||||
(0 rows)
|
||||
|
||||
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
|
||||
explain execute p18(3,7,3,3);
|
||||
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
|
||||
explain execute p18(3,7,3,3);
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -811,9 +812,9 @@ explain execute p18(3,7,3,3);
|
|||
Selected Partitions: PART
|
||||
(7 rows)
|
||||
|
||||
execute p18(3,7,3,3);
|
||||
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
|
||||
execute p111;
|
||||
execute p18(3,7,3,3);
|
||||
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
|
||||
execute p111;
|
||||
col1 | col2
|
||||
------+------
|
||||
19 | 100
|
||||
|
|
@ -918,8 +919,8 @@ execute p111;
|
|||
11 | 0
|
||||
(100 rows)
|
||||
|
||||
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
|
||||
execute p112;
|
||||
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
|
||||
execute p112;
|
||||
col1 | col2
|
||||
------+------
|
||||
11 | 0
|
||||
|
|
@ -934,9 +935,9 @@ execute p112;
|
|||
11 | 90
|
||||
(10 rows)
|
||||
|
||||
--nobypass
|
||||
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
|
||||
explain execute p181(111);
|
||||
--nobypass
|
||||
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
|
||||
explain execute p181(111);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because the partition key is not in the parameters.
|
||||
|
|
@ -948,23 +949,23 @@ explain execute p181(111);
|
|||
Selected Partitions: NONE
|
||||
(7 rows)
|
||||
|
||||
execute p181(111);
|
||||
|
||||
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
execute p191;
|
||||
execute p181(111);
|
||||
|
||||
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
execute p191;
|
||||
col1 | col2 | col3
|
||||
------+------+------
|
||||
(0 rows)
|
||||
|
||||
execute p192;
|
||||
|
||||
--error
|
||||
execute p11(null,null,'test_null');
|
||||
execute p192;
|
||||
|
||||
--error
|
||||
execute p11(null,null,'test_null');
|
||||
ERROR: inserted partition key does not map to any table partition
|
||||
--bypass through index only scan
|
||||
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
|
||||
explain execute p11301 (2);
|
||||
--bypass through index only scan
|
||||
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
|
||||
explain execute p11301 (2);
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -975,7 +976,7 @@ explain execute p11301 (2);
|
|||
Selected Partitions: PART
|
||||
(6 rows)
|
||||
|
||||
execute p11301 (2);
|
||||
execute p11301 (2);
|
||||
col1 | col2
|
||||
------+------
|
||||
2 | 100
|
||||
|
|
@ -991,8 +992,8 @@ execute p11301 (2);
|
|||
2 | 0
|
||||
(11 rows)
|
||||
|
||||
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
|
||||
explain execute p11401 (2);
|
||||
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
|
||||
explain execute p11401 (2);
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -1003,7 +1004,7 @@ explain execute p11401 (2);
|
|||
Selected Partitions: PART
|
||||
(6 rows)
|
||||
|
||||
execute p11401 (2);
|
||||
execute p11401 (2);
|
||||
col1 | col2
|
||||
------+------
|
||||
2 | 0
|
||||
|
|
@ -1019,8 +1020,8 @@ execute p11401 (2);
|
|||
2 | 100
|
||||
(11 rows)
|
||||
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p11301 (2);
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p11301 (2);
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[Bypass]
|
||||
|
|
@ -1031,7 +1032,7 @@ explain execute p11301 (2);
|
|||
Selected Partitions: PART
|
||||
(6 rows)
|
||||
|
||||
execute p11401 (2);
|
||||
execute p11401 (2);
|
||||
col1 | col2
|
||||
------+------
|
||||
2 | 0
|
||||
|
|
@ -1047,13 +1048,13 @@ execute p11401 (2);
|
|||
2 | 100
|
||||
(11 rows)
|
||||
|
||||
reset enable_indexonlyscan;
|
||||
--nobypass
|
||||
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
|
||||
execute p120 (0, 9);
|
||||
--not bypass
|
||||
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
|
||||
explain execute p115;
|
||||
reset enable_indexonlyscan;
|
||||
--nobypass
|
||||
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
|
||||
execute p120 (0, 9);
|
||||
--not bypass
|
||||
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
|
||||
explain execute p115;
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because query's scan operator is not index.
|
||||
|
|
@ -1065,7 +1066,7 @@ explain execute p115;
|
|||
Selected Partitions: 1..8
|
||||
(7 rows)
|
||||
|
||||
execute p115;
|
||||
execute p115;
|
||||
col1 | col2 | col3
|
||||
------+------+--------------
|
||||
-1 | 111 | test_update2
|
||||
|
|
@ -2149,8 +2150,8 @@ execute p115;
|
|||
0 | -1 | test_update
|
||||
(1079 rows)
|
||||
|
||||
prepare p116 as select * from test_bypass_sql_partition order by col2;
|
||||
explain execute p116;
|
||||
prepare p116 as select * from test_bypass_sql_partition order by col2;
|
||||
explain execute p116;
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------------------
|
||||
[No Bypass]reason: Bypass not executed because query's scan operator is not index.
|
||||
|
|
@ -2162,7 +2163,7 @@ explain execute p116;
|
|||
Selected Partitions: 1..8
|
||||
(7 rows)
|
||||
|
||||
execute p116;
|
||||
execute p116;
|
||||
col1 | col2 | col3
|
||||
------+------+--------------
|
||||
0 | -1 | test_update
|
||||
|
|
@ -3246,10 +3247,10 @@ execute p116;
|
|||
-1 | 111 | test_update2
|
||||
(1079 rows)
|
||||
|
||||
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
|
||||
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
|
||||
execute p117;
|
||||
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
|
||||
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
|
||||
execute p117;
|
||||
col1 | col2
|
||||
------+------
|
||||
-3 | 10
|
||||
|
|
@ -3264,7 +3265,7 @@ execute p117;
|
|||
0 | 6
|
||||
(10 rows)
|
||||
|
||||
execute p118;
|
||||
execute p118;
|
||||
col2 | col1
|
||||
------+------
|
||||
10 | -3
|
||||
|
|
@ -3279,7 +3280,7 @@ execute p118;
|
|||
6 | 0
|
||||
(10 rows)
|
||||
|
||||
execute p119;
|
||||
execute p119;
|
||||
col1 | col2
|
||||
------+------
|
||||
79 | 100
|
||||
|
|
@ -3294,11 +3295,11 @@ execute p119;
|
|||
79 | 10
|
||||
(10 rows)
|
||||
|
||||
|
||||
|
||||
--bypass
|
||||
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
|
||||
execute p_select1(0);
|
||||
|
||||
|
||||
--bypass
|
||||
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
|
||||
execute p_select1(0);
|
||||
col1 | col2 | col3
|
||||
------+------+-------------
|
||||
0 | -1 | test_update
|
||||
|
|
@ -3313,8 +3314,8 @@ execute p_select1(0);
|
|||
0 | 8 | test
|
||||
(10 rows)
|
||||
|
||||
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
|
||||
execute p_select2(0);
|
||||
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
|
||||
execute p_select2(0);
|
||||
col1 | col2 | col3
|
||||
------+------+-------------
|
||||
0 | -1 | test_update
|
||||
|
|
@ -3329,12 +3330,12 @@ execute p_select2(0);
|
|||
0 | 8 | test
|
||||
(10 rows)
|
||||
|
||||
|
||||
--nobypass
|
||||
|
||||
|
||||
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
|
||||
execute p_select3;
|
||||
|
||||
--nobypass
|
||||
|
||||
|
||||
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
|
||||
execute p_select3;
|
||||
col1 | col2
|
||||
------+------
|
||||
-3 | 10
|
||||
|
|
@ -3349,9 +3350,9 @@ execute p_select3;
|
|||
0 | 6
|
||||
(10 rows)
|
||||
|
||||
|
||||
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
|
||||
execute p_select4(20,10);
|
||||
|
||||
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
|
||||
execute p_select4(20,10);
|
||||
col1 | col2
|
||||
------+------
|
||||
11 | 0
|
||||
|
|
@ -3366,40 +3367,40 @@ execute p_select4(20,10);
|
|||
11 | 90
|
||||
(10 rows)
|
||||
|
||||
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
|
||||
execute p_select5(11,15);
|
||||
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
|
||||
execute p_select5(11,15);
|
||||
col1 | col2
|
||||
------+------
|
||||
(0 rows)
|
||||
|
||||
--bypass
|
||||
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
|
||||
execute p_update1(1, 10);
|
||||
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
|
||||
execute p_update2('test_null',1,1);
|
||||
--nobypass
|
||||
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
|
||||
update test_bypass_sql_partition set col3='test_null' where true;
|
||||
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
|
||||
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
|
||||
execute p_update3(1,1,10);
|
||||
|
||||
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
|
||||
execute p_update4('test_null',11,15);
|
||||
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
|
||||
execute p_update5('test_null',1,10);
|
||||
|
||||
--bypass
|
||||
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
|
||||
execute p_delete1 (1);
|
||||
|
||||
--nobypass
|
||||
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
|
||||
execute p_delete3(1,10);
|
||||
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
|
||||
execute p_delete4(1,10);
|
||||
prepare p_delete2 as delete from test_bypass_sql_partition where true;
|
||||
execute p_delete2;
|
||||
reset enable_partition_opfusion;
|
||||
drop table test_bypass_sql_partition;
|
||||
|
||||
--bypass
|
||||
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
|
||||
execute p_update1(1, 10);
|
||||
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
|
||||
execute p_update2('test_null',1,1);
|
||||
--nobypass
|
||||
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
|
||||
update test_bypass_sql_partition set col3='test_null' where true;
|
||||
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
|
||||
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
|
||||
execute p_update3(1,1,10);
|
||||
|
||||
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
|
||||
execute p_update4('test_null',11,15);
|
||||
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
|
||||
execute p_update5('test_null',1,10);
|
||||
|
||||
--bypass
|
||||
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
|
||||
execute p_delete1 (1);
|
||||
|
||||
--nobypass
|
||||
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
|
||||
execute p_delete3(1,10);
|
||||
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
|
||||
execute p_delete4(1,10);
|
||||
prepare p_delete2 as delete from test_bypass_sql_partition where true;
|
||||
execute p_delete2;
|
||||
reset enable_partition_opfusion;
|
||||
drop table test_bypass_sql_partition;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ set enable_seqscan=off;
|
|||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
|
||||
|
||||
drop table if exists test_bypass_sq1;
|
||||
create table test_bypass_sq1(col1 int, col2 int, col3 text);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ set enable_seqscan=off;
|
|||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
|
||||
|
||||
-- create table
|
||||
drop table if exists test_bypass_sq1;
|
||||
|
|
|
|||
|
|
@ -1,254 +1,255 @@
|
|||
set enable_opfusion=on;
|
||||
set enable_partition_opfusion=on;
|
||||
set enable_bitmapscan=off;
|
||||
set enable_seqscan=off;
|
||||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
--create table
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
--insert
|
||||
explain insert into test_bypass_sql_partition values (0,0,'test_insert');
|
||||
insert into test_bypass_sql_partition values (0,0,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (0,1,'test_insert');
|
||||
insert into test_bypass_sql_partition values (0,1,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (11,1,'test_insert');
|
||||
insert into test_bypass_sql_partition values (11,1,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (11,2,'test_insert');
|
||||
insert into test_bypass_sql_partition values (11,2,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (0,10,'test_insert2');
|
||||
insert into test_bypass_sql_partition values (0,10,'test_insert2');
|
||||
explain insert into test_bypass_sql_partition values (2,12,'test_insert2');
|
||||
insert into test_bypass_sql_partition values (2,12,'test_insert2');
|
||||
explain insert into test_bypass_sql_partition values (30,0,'test_insert3');
|
||||
insert into test_bypass_sql_partition values (30,0,'test_insert3');
|
||||
explain insert into test_bypass_sql_partition values (3,3,'test_insert3');
|
||||
insert into test_bypass_sql_partition values (3,3,'test_insert3');
|
||||
explain insert into test_bypass_sql_partition(col1,col2) values (1,1);
|
||||
insert into test_bypass_sql_partition(col1,col2) values (1,1);
|
||||
explain insert into test_bypass_sql_partition(col1,col2) values (22,2);
|
||||
insert into test_bypass_sql_partition(col1,col2) values (22,2);
|
||||
explain insert into test_bypass_sql_partition(col1,col2) values (33,3);
|
||||
insert into test_bypass_sql_partition(col1,col2) values (33,3);
|
||||
--error
|
||||
explain insert into test_bypass_sql_partition values (null,null,null);
|
||||
insert into test_bypass_sql_partition values (null,null,null);
|
||||
--nobypass
|
||||
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
--select
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
--bypass
|
||||
set enable_indexonlyscan=off;
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=0;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=0;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
|
||||
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
|
||||
select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
|
||||
explain select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
|
||||
select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=-1;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=-1;
|
||||
reset enable_indexonlyscan;
|
||||
--bypass though index only scan
|
||||
set enable_indexscan = off;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
|
||||
reset enable_indexscan;
|
||||
--error
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
|
||||
--nobypass
|
||||
explain select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
|
||||
|
||||
--update
|
||||
--bypass
|
||||
|
||||
explain update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=0 and col2=0;
|
||||
update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=10 and col2=0;
|
||||
explain update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
|
||||
update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
|
||||
explain update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
|
||||
update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
|
||||
--not bypass
|
||||
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
explain select * from test_bypass_sql_partition where col3 is not null;
|
||||
explain update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
|
||||
update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
|
||||
|
||||
|
||||
--bypass
|
||||
explain update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
|
||||
update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
|
||||
explain select * from test_bypass_sql_partition where col1=0 order by col1;
|
||||
select * from test_bypass_sql_partition where col1=0 order by col1;
|
||||
explain select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
|
||||
select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
|
||||
explain select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
|
||||
select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
|
||||
|
||||
--nobypass
|
||||
explain select * from test_bypass_sql_partition where col2=20 order by col1;
|
||||
select * from test_bypass_sql_partition where col2=20 order by col1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
|
||||
explain select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
|
||||
select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
|
||||
|
||||
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
|
||||
--bypass though index only scan
|
||||
set enable_indexscan = off;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
|
||||
explain select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
|
||||
select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
|
||||
--nobypass
|
||||
explain select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
|
||||
select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
|
||||
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
|
||||
|
||||
explain select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
|
||||
|
||||
reset enable_indexscan;
|
||||
|
||||
--nobypass
|
||||
explain select * from test_bypass_sql_partition where col1>col2 limit 10;
|
||||
explain select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
|
||||
select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
|
||||
explain select * from test_bypass_sql_partition where col3='test_update2';
|
||||
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
|
||||
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset 3;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset null;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
|
||||
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update offset 3;
|
||||
explain update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
|
||||
update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
|
||||
explain delete from test_bypass_sql_partition where col1=1 and col2=1;
|
||||
delete from test_bypass_sql_partition where col1=1 and col2=1;
|
||||
--error
|
||||
explain delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
explain insert into test_bypass_sql_partition values (null,null,null);
|
||||
insert into test_bypass_sql_partition values (null,null,null);
|
||||
--bypass / set enable_bitmapscan=off;
|
||||
select * from test_bypass_sql_partition where col1=3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10 desc; --order by is supported when ordered col is in index
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
|
||||
--not bypass
|
||||
explain select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
|
||||
explain select * from test_bypass_sql_partition where col1 > 0 order by col1,col2 desc limit 10;
|
||||
--bypass
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10 ;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10;
|
||||
--not bypass
|
||||
explain select * from test_bypass_sql_partition where true;
|
||||
explain select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
--bypass
|
||||
|
||||
select col2, col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc limit 10;
|
||||
explain insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1=0;
|
||||
|
||||
delete from test_bypass_sql_partition where col1=1;
|
||||
delete from test_bypass_sql_partition where col1 > 10 and col1 < 0;
|
||||
delete from test_bypass_sql_partition where col1 <= 11 and col1 >= 15;
|
||||
|
||||
--nobypass
|
||||
delete from test_bypass_sql_partition where col1 > 10;
|
||||
delete from test_bypass_sql_partition where col1 < 10;
|
||||
delete from test_bypass_sql_partition where col1 >= 10 and col1 <= 30;
|
||||
reset enable_partition_opfusion;
|
||||
drop table test_bypass_sql_partition;
|
||||
|
||||
set enable_opfusion=on;
|
||||
set enable_partition_opfusion=on;
|
||||
set enable_bitmapscan=off;
|
||||
set enable_seqscan=off;
|
||||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
|
||||
--create table
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
--insert
|
||||
explain insert into test_bypass_sql_partition values (0,0,'test_insert');
|
||||
insert into test_bypass_sql_partition values (0,0,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (0,1,'test_insert');
|
||||
insert into test_bypass_sql_partition values (0,1,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (11,1,'test_insert');
|
||||
insert into test_bypass_sql_partition values (11,1,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (11,2,'test_insert');
|
||||
insert into test_bypass_sql_partition values (11,2,'test_insert');
|
||||
explain insert into test_bypass_sql_partition values (0,10,'test_insert2');
|
||||
insert into test_bypass_sql_partition values (0,10,'test_insert2');
|
||||
explain insert into test_bypass_sql_partition values (2,12,'test_insert2');
|
||||
insert into test_bypass_sql_partition values (2,12,'test_insert2');
|
||||
explain insert into test_bypass_sql_partition values (30,0,'test_insert3');
|
||||
insert into test_bypass_sql_partition values (30,0,'test_insert3');
|
||||
explain insert into test_bypass_sql_partition values (3,3,'test_insert3');
|
||||
insert into test_bypass_sql_partition values (3,3,'test_insert3');
|
||||
explain insert into test_bypass_sql_partition(col1,col2) values (1,1);
|
||||
insert into test_bypass_sql_partition(col1,col2) values (1,1);
|
||||
explain insert into test_bypass_sql_partition(col1,col2) values (22,2);
|
||||
insert into test_bypass_sql_partition(col1,col2) values (22,2);
|
||||
explain insert into test_bypass_sql_partition(col1,col2) values (33,3);
|
||||
insert into test_bypass_sql_partition(col1,col2) values (33,3);
|
||||
--error
|
||||
explain insert into test_bypass_sql_partition values (null,null,null);
|
||||
insert into test_bypass_sql_partition values (null,null,null);
|
||||
--nobypass
|
||||
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
--select
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
--bypass
|
||||
set enable_indexonlyscan=off;
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=0;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=0;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 and col2 <= 20 order by col1,col2;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 for update limit 1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and col2>0 order by col1,col2 limit 0;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 order by col1,col2 for update limit 0;
|
||||
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
|
||||
select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2;
|
||||
explain select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
|
||||
select * from test_bypass_sql_partition where col1 is not null and col2 = 0 order by col1;
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=-1;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=-1;
|
||||
reset enable_indexonlyscan;
|
||||
--bypass though index only scan
|
||||
set enable_indexscan = off;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0;
|
||||
reset enable_indexscan;
|
||||
--error
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1;
|
||||
explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
|
||||
select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1;
|
||||
--nobypass
|
||||
explain select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
|
||||
explain select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10;
|
||||
|
||||
--update
|
||||
--bypass
|
||||
|
||||
explain update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=0 and col2=0;
|
||||
update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=10 and col2=0;
|
||||
explain update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
|
||||
update test_bypass_sql_partition set col2=col1-1,col3='test_update' where col1=20 and col2=2;
|
||||
explain update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
|
||||
update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col2=10;
|
||||
--not bypass
|
||||
explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
explain select * from test_bypass_sql_partition where col3 is not null;
|
||||
explain update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
|
||||
update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null;
|
||||
|
||||
|
||||
--bypass
|
||||
explain update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
|
||||
update test_bypass_sql_partition set col2=111,col3='test_update2' where col1=0;
|
||||
explain select * from test_bypass_sql_partition where col1=0 order by col1;
|
||||
select * from test_bypass_sql_partition where col1=0 order by col1;
|
||||
explain select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
|
||||
select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 2;
|
||||
explain select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
|
||||
select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1;
|
||||
|
||||
--nobypass
|
||||
explain select * from test_bypass_sql_partition where col2=20 order by col1;
|
||||
select * from test_bypass_sql_partition where col2=20 order by col1;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limit 10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 10;
|
||||
explain select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
|
||||
select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3;
|
||||
|
||||
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
|
||||
--bypass though index only scan
|
||||
set enable_indexscan = off;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
|
||||
select col1,col2 from test_bypass_sql_partition where col1=0 order by col2;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
|
||||
explain select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
|
||||
select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit 3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null;
|
||||
--nobypass
|
||||
explain select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
|
||||
select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10;
|
||||
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1 is null and col2 is null limit 10;
|
||||
|
||||
explain select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 10;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 order by col1 limit 10;
|
||||
|
||||
reset enable_indexscan;
|
||||
|
||||
--nobypass
|
||||
explain select * from test_bypass_sql_partition where col1>col2 limit 10;
|
||||
explain select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
|
||||
select * from test_bypass_sql_partition where col1=3 and col2=3 for update;
|
||||
explain select * from test_bypass_sql_partition where col3='test_update2';
|
||||
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
|
||||
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 limit 3 offset 3;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset 3;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update limit 3 offset null;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
|
||||
select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 order by col1 offset 3;
|
||||
explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update offset 3;
|
||||
explain update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
|
||||
update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2;
|
||||
explain delete from test_bypass_sql_partition where col1=1 and col2=1;
|
||||
delete from test_bypass_sql_partition where col1=1 and col2=1;
|
||||
--error
|
||||
explain delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
explain insert into test_bypass_sql_partition values (null,null,null);
|
||||
insert into test_bypass_sql_partition values (null,null,null);
|
||||
--bypass / set enable_bitmapscan=off;
|
||||
select * from test_bypass_sql_partition where col1=3;
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10 desc; --order by is supported when ordered col is in index
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1;
|
||||
--not bypass
|
||||
explain select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
|
||||
select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10;
|
||||
explain select * from test_bypass_sql_partition where col1 > 0 order by col1,col2 desc limit 10;
|
||||
--bypass
|
||||
explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10 ;
|
||||
select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10;
|
||||
--not bypass
|
||||
explain select * from test_bypass_sql_partition where true;
|
||||
explain select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
--bypass
|
||||
|
||||
select col2, col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10;
|
||||
select col1, col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc limit 10;
|
||||
explain insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1=0;
|
||||
|
||||
delete from test_bypass_sql_partition where col1=1;
|
||||
delete from test_bypass_sql_partition where col1 > 10 and col1 < 0;
|
||||
delete from test_bypass_sql_partition where col1 <= 11 and col1 >= 15;
|
||||
|
||||
--nobypass
|
||||
delete from test_bypass_sql_partition where col1 > 10;
|
||||
delete from test_bypass_sql_partition where col1 < 10;
|
||||
delete from test_bypass_sql_partition where col1 >= 10 and col1 <= 30;
|
||||
reset enable_partition_opfusion;
|
||||
drop table test_bypass_sql_partition;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,245 +1,246 @@
|
|||
set enable_opfusion=on;
|
||||
set enable_partition_opfusion=on;
|
||||
set enable_bitmapscan=off;
|
||||
set enable_seqscan=off;
|
||||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
--create table
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
|
||||
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
|
||||
|
||||
|
||||
|
||||
explain execute p11(0,0,'test_insert');
|
||||
execute p11(10,10,'test_insert');
|
||||
execute p11(12,12,'test_insert');
|
||||
execute p11(-1,-1,'test_insert2');
|
||||
execute p11(23,23,'test_insert2');
|
||||
execute p11(33,33,'test_insert3');
|
||||
execute p11(0,0,'test_insert3');
|
||||
explain execute p12(1,1);
|
||||
execute p12(1,1);
|
||||
execute p12(22,22);
|
||||
execute p12(20,20);
|
||||
|
||||
--nobypass
|
||||
execute p11(null,null,null);
|
||||
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
execute p_insert1;
|
||||
--bypass
|
||||
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
|
||||
explain execute p13(0,0);
|
||||
execute p13(0,0);
|
||||
execute p13(10,0);
|
||||
execute p13(20,0);
|
||||
execute p13(30,0);
|
||||
execute p13(40,0);
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p13(0,0);
|
||||
execute p13(0,0);
|
||||
reset enable_indexonlyscan;
|
||||
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
|
||||
explain execute p15 (0,0,'test_update',-1);
|
||||
execute p15 (0,0,'test_update',-1);
|
||||
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
|
||||
explain execute p16(5,3,1,1);
|
||||
execute p16(5,3,1,1);
|
||||
|
||||
|
||||
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
|
||||
execute p101 (111,'test_update2',-1);
|
||||
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
|
||||
execute p102 (1);
|
||||
|
||||
|
||||
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
|
||||
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
|
||||
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
|
||||
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
|
||||
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
|
||||
explain execute p1011;
|
||||
execute p1011;
|
||||
explain execute p1012;
|
||||
execute p1012;
|
||||
explain execute p1013;
|
||||
execute p1013;
|
||||
explain execute p1014;
|
||||
execute p1014;
|
||||
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
|
||||
explain execute p10141;
|
||||
execute p10141;
|
||||
|
||||
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p1021(1);
|
||||
execute p1021(1);
|
||||
--bypass through index only scan
|
||||
|
||||
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p10211(1);
|
||||
execute p10211(1);
|
||||
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
|
||||
explain execute p10212(1);
|
||||
execute p10212(1);
|
||||
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
|
||||
explain execute p10213(1);
|
||||
execute p10213(1);
|
||||
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
|
||||
explain execute p10214(1);
|
||||
execute p10214(1);
|
||||
|
||||
|
||||
|
||||
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
|
||||
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
|
||||
execute p1024;
|
||||
execute p1025(1);
|
||||
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
|
||||
execute p104 (3);
|
||||
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
|
||||
execute p1052(2);
|
||||
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
|
||||
execute p10601 (0,10,1);
|
||||
|
||||
--nobypass
|
||||
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
execute p1020;
|
||||
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
explain execute p10200;
|
||||
execute p10200;
|
||||
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
|
||||
explain execute p1022(0,3);
|
||||
execute p1022(0,3);
|
||||
explain execute p1022(0,null);
|
||||
execute p1022(0,null);
|
||||
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
|
||||
explain execute p1023(0,3,2);
|
||||
execute p1023(0,3,2);
|
||||
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
|
||||
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
|
||||
explain execute p1026(0,3);
|
||||
execute p1026(0,3);
|
||||
explain execute p1027(0,3,2);
|
||||
execute p1027(0,3,2);
|
||||
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
|
||||
execute p103 (2);
|
||||
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
|
||||
execute p105 (5);
|
||||
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
|
||||
execute p1051(5,3);
|
||||
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
|
||||
execute p106 (0,1);
|
||||
|
||||
--bypass
|
||||
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
|
||||
execute p17 (3,3);
|
||||
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
|
||||
explain execute p18(3,7,3,3);
|
||||
execute p18(3,7,3,3);
|
||||
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
|
||||
execute p111;
|
||||
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
|
||||
execute p112;
|
||||
--nobypass
|
||||
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
|
||||
explain execute p181(111);
|
||||
execute p181(111);
|
||||
|
||||
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
execute p191;
|
||||
execute p192;
|
||||
|
||||
--error
|
||||
execute p11(null,null,'test_null');
|
||||
--bypass through index only scan
|
||||
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
|
||||
explain execute p11301 (2);
|
||||
execute p11301 (2);
|
||||
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
|
||||
explain execute p11401 (2);
|
||||
execute p11401 (2);
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p11301 (2);
|
||||
execute p11401 (2);
|
||||
reset enable_indexonlyscan;
|
||||
--nobypass
|
||||
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
|
||||
execute p120 (0, 9);
|
||||
--not bypass
|
||||
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
|
||||
explain execute p115;
|
||||
execute p115;
|
||||
prepare p116 as select * from test_bypass_sql_partition order by col2;
|
||||
explain execute p116;
|
||||
execute p116;
|
||||
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
|
||||
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
|
||||
execute p117;
|
||||
execute p118;
|
||||
execute p119;
|
||||
|
||||
|
||||
--bypass
|
||||
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
|
||||
execute p_select1(0);
|
||||
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
|
||||
execute p_select2(0);
|
||||
|
||||
--nobypass
|
||||
|
||||
|
||||
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
|
||||
execute p_select3;
|
||||
|
||||
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
|
||||
execute p_select4(20,10);
|
||||
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
|
||||
execute p_select5(11,15);
|
||||
--bypass
|
||||
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
|
||||
execute p_update1(1, 10);
|
||||
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
|
||||
execute p_update2('test_null',1,1);
|
||||
--nobypass
|
||||
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
|
||||
update test_bypass_sql_partition set col3='test_null' where true;
|
||||
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
|
||||
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
|
||||
execute p_update3(1,1,10);
|
||||
|
||||
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
|
||||
execute p_update4('test_null',11,15);
|
||||
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
|
||||
execute p_update5('test_null',1,10);
|
||||
|
||||
--bypass
|
||||
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
|
||||
execute p_delete1 (1);
|
||||
|
||||
--nobypass
|
||||
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
|
||||
execute p_delete3(1,10);
|
||||
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
|
||||
execute p_delete4(1,10);
|
||||
prepare p_delete2 as delete from test_bypass_sql_partition where true;
|
||||
execute p_delete2;
|
||||
reset enable_partition_opfusion;
|
||||
drop table test_bypass_sql_partition;
|
||||
|
||||
set enable_opfusion=on;
|
||||
set enable_partition_opfusion=on;
|
||||
set enable_bitmapscan=off;
|
||||
set enable_seqscan=off;
|
||||
set opfusion_debug_mode = 'log';
|
||||
set log_min_messages=debug;
|
||||
set logging_module = 'on(OPFUSION)';
|
||||
set sql_beta_feature = 'index_cost_with_leaf_pages_only';
|
||||
--create table
|
||||
drop table if exists test_bypass_sql_partition;
|
||||
create table test_bypass_sql_partition(col1 int, col2 int, col3 text)
|
||||
partition by range (col1)
|
||||
(
|
||||
partition test_bypass_sql_partition_1 values less than(10),
|
||||
partition test_bypass_sql_partition_2 values less than(20),
|
||||
partition test_bypass_sql_partition_3 values less than(30),
|
||||
partition test_bypass_sql_partition_4 values less than(40),
|
||||
partition test_bypass_sql_partition_5 values less than(50),
|
||||
partition test_bypass_sql_partition_6 values less than(60),
|
||||
partition test_bypass_sql_partition_7 values less than(70),
|
||||
partition test_bypass_sql_partition_8 values less than(80)
|
||||
);
|
||||
create index itest_bypass_sql_partition on test_bypass_sql_partition(col1,col2) local;
|
||||
insert into test_bypass_sql_partition select generate_series(0,79,1), generate_series(0,100,10), repeat('a',7);
|
||||
prepare p11 as insert into test_bypass_sql_partition values($1,$2,$3);
|
||||
prepare p12 as insert into test_bypass_sql_partition(col1,col2) values ($1,$2);
|
||||
|
||||
|
||||
|
||||
explain execute p11(0,0,'test_insert');
|
||||
execute p11(10,10,'test_insert');
|
||||
execute p11(12,12,'test_insert');
|
||||
execute p11(-1,-1,'test_insert2');
|
||||
execute p11(23,23,'test_insert2');
|
||||
execute p11(33,33,'test_insert3');
|
||||
execute p11(0,0,'test_insert3');
|
||||
explain execute p12(1,1);
|
||||
execute p12(1,1);
|
||||
execute p12(22,22);
|
||||
execute p12(20,20);
|
||||
|
||||
--nobypass
|
||||
execute p11(null,null,null);
|
||||
prepare p_insert1 as insert into test_bypass_sql_partition values(0,generate_series(1,100),'test');
|
||||
execute p_insert1;
|
||||
--bypass
|
||||
prepare p13 as select * from test_bypass_sql_partition where col1=$1 and col2=$2;
|
||||
explain execute p13(0,0);
|
||||
execute p13(0,0);
|
||||
execute p13(10,0);
|
||||
execute p13(20,0);
|
||||
execute p13(30,0);
|
||||
execute p13(40,0);
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p13(0,0);
|
||||
execute p13(0,0);
|
||||
reset enable_indexonlyscan;
|
||||
prepare p15 as update test_bypass_sql_partition set col2=col2+$4,col3=$3 where col1=$1 and col2=$2;
|
||||
explain execute p15 (0,0,'test_update',-1);
|
||||
execute p15 (0,0,'test_update',-1);
|
||||
prepare p16 as update test_bypass_sql_partition set col2=mod($1,$2) where col1=$3 and col2=$4;
|
||||
explain execute p16(5,3,1,1);
|
||||
execute p16(5,3,1,1);
|
||||
|
||||
|
||||
prepare p101 as update test_bypass_sql_partition set col2=$1,col3=$2 where col1=$3 ;
|
||||
execute p101 (111,'test_update2',-1);
|
||||
prepare p102 as select * from test_bypass_sql_partition where col1=$1;
|
||||
execute p102 (1);
|
||||
|
||||
|
||||
prepare p1011 as insert into test_bypass_sql_partition values(-3,-3,'test_pbe');
|
||||
prepare p1013 as update test_bypass_sql_partition set col2=10 where col1=-3;
|
||||
prepare p1012 as select * from test_bypass_sql_partition where col1=-3;
|
||||
prepare p1014 as select * from test_bypass_sql_partition where col1=-3 for update;
|
||||
prepare p1015 as delete from test_bypass_sql_partition where col1=-3;
|
||||
explain execute p1011;
|
||||
execute p1011;
|
||||
explain execute p1012;
|
||||
execute p1012;
|
||||
explain execute p1013;
|
||||
execute p1013;
|
||||
explain execute p1014;
|
||||
execute p1014;
|
||||
prepare p10141 as select col1,col2 from test_bypass_sql_partition where col1=-3 for update;
|
||||
explain execute p10141;
|
||||
execute p10141;
|
||||
|
||||
prepare p1021 as select * from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p1021(1);
|
||||
execute p1021(1);
|
||||
--bypass through index only scan
|
||||
|
||||
prepare p10211 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1;
|
||||
explain execute p10211(1);
|
||||
execute p10211(1);
|
||||
prepare p10212 as select col1,col2 from test_bypass_sql_partition where col1=$1 offset 1;
|
||||
explain execute p10212(1);
|
||||
execute p10212(1);
|
||||
prepare p10213 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit 1 offset null;
|
||||
explain execute p10213(1);
|
||||
execute p10213(1);
|
||||
prepare p10214 as select col1,col2 from test_bypass_sql_partition where col1=$1 limit null offset null;
|
||||
explain execute p10214(1);
|
||||
execute p10214(1);
|
||||
|
||||
|
||||
|
||||
prepare p1024 as select * from test_bypass_sql_partition where col1=0 order by col1 for update limit 1;
|
||||
prepare p1025 as select * from test_bypass_sql_partition where col1=$1 for update limit 1;
|
||||
execute p1024;
|
||||
execute p1025(1);
|
||||
prepare p104 as select * from test_bypass_sql_partition where col1=$1 order by col1;
|
||||
execute p104 (3);
|
||||
prepare p1052 as select col1,col2 from test_bypass_sql_partition where col1=$1 order by col1 for update limit 2;
|
||||
execute p1052(2);
|
||||
prepare p10601 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col1<$2 and col2>$3 order by col1;
|
||||
execute p10601 (0,10,1);
|
||||
|
||||
--nobypass
|
||||
prepare p1020 as select * from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
execute p1020;
|
||||
prepare p10200 as select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1;
|
||||
explain execute p10200;
|
||||
execute p10200;
|
||||
prepare p1022 as select * from test_bypass_sql_partition where col1=$1 limit $2;
|
||||
explain execute p1022(0,3);
|
||||
execute p1022(0,3);
|
||||
explain execute p1022(0,null);
|
||||
execute p1022(0,null);
|
||||
prepare p1023 as select * from test_bypass_sql_partition where col1=$1 limit $2 offset $3;
|
||||
explain execute p1023(0,3,2);
|
||||
execute p1023(0,3,2);
|
||||
prepare p1026 as select * from test_bypass_sql_partition where col1=$1 for update limit $2;
|
||||
prepare p1027 as select * from test_bypass_sql_partition where col1=$1 for update limit $2 offset $3;
|
||||
explain execute p1026(0,3);
|
||||
execute p1026(0,3);
|
||||
explain execute p1027(0,3,2);
|
||||
execute p1027(0,3,2);
|
||||
prepare p103 as select col1,col2 from test_bypass_sql_partition where col2=$1 order by col1;
|
||||
execute p103 (2);
|
||||
prepare p105 as select col1,col2 from test_bypass_sql_partition where col1<$1 order by col1 limit 2;
|
||||
execute p105 (5);
|
||||
prepare p1051 as select col1,col2 from test_bypass_sql_partition where col1<$1 and col1>$2 order by col1 limit 3;
|
||||
execute p1051(5,3);
|
||||
prepare p106 as select col1,col2 from test_bypass_sql_partition where col1>$1 and col2>$2 order by col1 limit 3;
|
||||
execute p106 (0,1);
|
||||
|
||||
--bypass
|
||||
prepare p17 as select * from test_bypass_sql_partition where col1=$1 and col2=$2 for update;
|
||||
execute p17 (3,3);
|
||||
prepare p18 as update test_bypass_sql_partition set col2=$1*$2 where col1=$3 and col2=$4;
|
||||
explain execute p18(3,7,3,3);
|
||||
execute p18(3,7,3,3);
|
||||
prepare p111 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 desc;
|
||||
execute p111;
|
||||
prepare p112 as select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 order by col1 limit 10;
|
||||
execute p112;
|
||||
--nobypass
|
||||
prepare p181 as update test_bypass_sql_partition set col2= $1 where col1 is null;
|
||||
explain execute p181(111);
|
||||
execute p181(111);
|
||||
|
||||
prepare p191 as select * from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
prepare p192 as delete from test_bypass_sql_partition where col1 is null and col2 is null;
|
||||
execute p191;
|
||||
execute p192;
|
||||
|
||||
--error
|
||||
execute p11(null,null,'test_null');
|
||||
--bypass through index only scan
|
||||
prepare p11301 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2 desc;
|
||||
explain execute p11301 (2);
|
||||
execute p11301 (2);
|
||||
prepare p11401 as select col1,col2 from test_bypass_sql_partition where col1 = $1 order by col1,col2;
|
||||
explain execute p11401 (2);
|
||||
execute p11401 (2);
|
||||
set enable_indexonlyscan=off;
|
||||
explain execute p11301 (2);
|
||||
execute p11401 (2);
|
||||
reset enable_indexonlyscan;
|
||||
--nobypass
|
||||
prepare p120 as insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1>$1 and col1<$2;
|
||||
execute p120 (0, 9);
|
||||
--not bypass
|
||||
prepare p115 as select * from test_bypass_sql_partition order by col2 desc;
|
||||
explain execute p115;
|
||||
execute p115;
|
||||
prepare p116 as select * from test_bypass_sql_partition order by col2;
|
||||
explain execute p116;
|
||||
execute p116;
|
||||
prepare p117 as select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10;
|
||||
prepare p118 as select col2, col1 from test_bypass_sql_partition order by col1 limit 10;
|
||||
prepare p119 as select col1, col2 from test_bypass_sql_partition order by col1 desc limit 10;
|
||||
execute p117;
|
||||
execute p118;
|
||||
execute p119;
|
||||
|
||||
|
||||
--bypass
|
||||
prepare p_select1 as select * from test_bypass_sql_partition where col1 = $1 limit 10;
|
||||
execute p_select1(0);
|
||||
prepare p_select2 as select * from test_bypass_sql_partition where col1 = $1 limit 10 for update;
|
||||
execute p_select2(0);
|
||||
|
||||
--nobypass
|
||||
|
||||
|
||||
prepare p_select3 as select col1, col2 from test_bypass_sql_partition limit 10;
|
||||
execute p_select3;
|
||||
|
||||
prepare p_select4 as select col1, col2 from test_bypass_sql_partition where col1 < $1 and col1 > $2 limit 10;
|
||||
execute p_select4(20,10);
|
||||
prepare p_select5 as select col1, col2 from test_bypass_sql_partition where col1 <= $1 and col1 >=$2 limit 10;
|
||||
execute p_select5(11,15);
|
||||
--bypass
|
||||
prepare p_update1 as update test_bypass_sql_partition set col3=$1 where col1=$2;
|
||||
execute p_update1(1, 10);
|
||||
prepare p_update2 as update test_bypass_sql_partition set col3=$1,col2=col1-$2 where col1=$3;
|
||||
execute p_update2('test_null',1,1);
|
||||
--nobypass
|
||||
update test_bypass_sql_partition set col3='test_null' where col1 < 70;
|
||||
update test_bypass_sql_partition set col3='test_null' where true;
|
||||
update test_bypass_sql_partition set col1 = 1 where col1 > 1 and col1 < 10;
|
||||
prepare p_update3 as update test_bypass_sql_partition set col1 = $1 where col1 > $2 and col1 < $3;
|
||||
execute p_update3(1,1,10);
|
||||
|
||||
prepare p_update4 as update test_bypass_sql_partition set col3=$1,col2=mod(5,3) where col1 > $2 and col1 < $3;
|
||||
execute p_update4('test_null',11,15);
|
||||
prepare p_update5 as update test_bypass_sql_partition set col3=$1,col2=col1-1 where col1 >= $2 and col1 <= $3;
|
||||
execute p_update5('test_null',1,10);
|
||||
|
||||
--bypass
|
||||
prepare p_delete1 as delete from test_bypass_sql_partition where col1=$1;
|
||||
execute p_delete1 (1);
|
||||
|
||||
--nobypass
|
||||
prepare p_delete3 as delete from test_bypass_sql_partition where col1 > $1 and col1 < $2;
|
||||
execute p_delete3(1,10);
|
||||
prepare p_delete4 as delete from test_bypass_sql_partition where col1 <= $1 and col1 >= $2;
|
||||
execute p_delete4(1,10);
|
||||
prepare p_delete2 as delete from test_bypass_sql_partition where true;
|
||||
execute p_delete2;
|
||||
reset enable_partition_opfusion;
|
||||
drop table test_bypass_sql_partition;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue