From 112023186b0136a1e0a8af6ec5e5f8b0ad247d1e Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Tue, 21 Dec 2021 16:44:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E3=80=81=E5=88=9B=E5=BB=BA=E5=BD=92=E6=A1=A3?= =?UTF-8?q?=E6=A7=BD=E5=AF=BC=E8=87=B4=E5=BD=92=E6=A1=A3=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=9C=AA=E6=AD=A3=E7=A1=AE=E9=87=8D=E5=90=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/process/postmaster/pgarch.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/process/postmaster/pgarch.cpp b/src/gausskernel/process/postmaster/pgarch.cpp index 93032cfef..4bfab6893 100644 --- a/src/gausskernel/process/postmaster/pgarch.cpp +++ b/src/gausskernel/process/postmaster/pgarch.cpp @@ -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; From a2faea7d966eb257604a0e1a85a79515572deda5 Mon Sep 17 00:00:00 2001 From: zhangzhijingMY <2235036288@qq.com> Date: Wed, 22 Dec 2021 09:38:40 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9B=9E=E5=90=882.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/optimizer/plan/subselect.cpp | 2 +- .../runtime/executor/execUtils.cpp | 2 +- .../runtime/executor/nodeLockRows.cpp | 24 ++++++++++++++++++- .../storage/replication/logical/decode.cpp | 6 ++++- .../replication/logical/reorderbuffer.cpp | 9 ++++++- .../storage/replication/slotfuncs.cpp | 4 +++- 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/gausskernel/optimizer/plan/subselect.cpp b/src/gausskernel/optimizer/plan/subselect.cpp index 1494177eb..bfb8f8aa8 100644 --- a/src/gausskernel/optimizer/plan/subselect.cpp +++ b/src/gausskernel/optimizer/plan/subselect.cpp @@ -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); diff --git a/src/gausskernel/runtime/executor/execUtils.cpp b/src/gausskernel/runtime/executor/execUtils.cpp index 3cfb5421a..23c7f98b0 100644 --- a/src/gausskernel/runtime/executor/execUtils.cpp +++ b/src/gausskernel/runtime/executor/execUtils.cpp @@ -1980,4 +1980,4 @@ int PthreadMutexUnlock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace) RESUME_INTERRUPTS(); return ret; -} +} \ No newline at end of file diff --git a/src/gausskernel/runtime/executor/nodeLockRows.cpp b/src/gausskernel/runtime/executor/nodeLockRows.cpp index 2bd862567..5e47d4ff7 100644 --- a/src/gausskernel/runtime/executor/nodeLockRows.cpp +++ b/src/gausskernel/runtime/executor/nodeLockRows.cpp @@ -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: diff --git a/src/gausskernel/storage/replication/logical/decode.cpp b/src/gausskernel/storage/replication/logical/decode.cpp index 8507c7413..16aeec57e 100644 --- a/src/gausskernel/storage/replication/logical/decode.cpp +++ b/src/gausskernel/storage/replication/logical/decode.cpp @@ -839,7 +839,11 @@ static void DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf */ if (xlrec->flags & XLH_INSERT_CONTAINS_NEW_TUPLE) { HeapTupleHeader header; - xlhdr = (xl_multi_insert_tuple *)SHORTALIGN(data); + if ((data - tupledata) % ALIGNOF_SHORT == 0) { + xlhdr = (xl_multi_insert_tuple *)data; + } else { + xlhdr = (xl_multi_insert_tuple *)(data + ALIGNOF_SHORT - (data - tupledata) % ALIGNOF_SHORT); + } data = ((char *)xlhdr) + SizeOfMultiInsertTuple; datalen = xlhdr->datalen; if (datalen != 0 && AllocSizeIsValid((uint)datalen)) { diff --git a/src/gausskernel/storage/replication/logical/reorderbuffer.cpp b/src/gausskernel/storage/replication/logical/reorderbuffer.cpp index 590b93ab3..cf96e247a 100644 --- a/src/gausskernel/storage/replication/logical/reorderbuffer.cpp +++ b/src/gausskernel/storage/replication/logical/reorderbuffer.cpp @@ -1308,6 +1308,7 @@ void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit Relation relation = NULL; Oid reloid; Oid partitionReltoastrelid = InvalidOid; + bool stopDecoding = false; switch (change->action) { case REORDER_BUFFER_CHANGE_INSERT: @@ -1408,7 +1409,10 @@ void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit case REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID: Assert(change->data.command_id != InvalidCommandId); - + if (change->data.command_id != FirstCommandId) { + stopDecoding = true; + break; + } if (command_id < change->data.command_id) { command_id = change->data.command_id; @@ -1436,6 +1440,9 @@ void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("tuplecid value in changequeue"))); break; } + if (stopDecoding) { + break; + } } ReorderBufferIterTXNFinish(rb, iterstate); diff --git a/src/gausskernel/storage/replication/slotfuncs.cpp b/src/gausskernel/storage/replication/slotfuncs.cpp index 3a8e6e00b..c68e033e7 100644 --- a/src/gausskernel/storage/replication/slotfuncs.cpp +++ b/src/gausskernel/storage/replication/slotfuncs.cpp @@ -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(); From a2c22701a8931f0f7de3b1eb1ae3cf31b1b43be1 Mon Sep 17 00:00:00 2001 From: zhangzhijingMY <2235036288@qq.com> Date: Wed, 22 Dec 2021 17:45:21 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=9B=9E=E9=80=80=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/storage/replication/logical/decode.cpp | 6 +----- .../storage/replication/logical/reorderbuffer.cpp | 9 +-------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/gausskernel/storage/replication/logical/decode.cpp b/src/gausskernel/storage/replication/logical/decode.cpp index 16aeec57e..8507c7413 100644 --- a/src/gausskernel/storage/replication/logical/decode.cpp +++ b/src/gausskernel/storage/replication/logical/decode.cpp @@ -839,11 +839,7 @@ static void DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf */ if (xlrec->flags & XLH_INSERT_CONTAINS_NEW_TUPLE) { HeapTupleHeader header; - if ((data - tupledata) % ALIGNOF_SHORT == 0) { - xlhdr = (xl_multi_insert_tuple *)data; - } else { - xlhdr = (xl_multi_insert_tuple *)(data + ALIGNOF_SHORT - (data - tupledata) % ALIGNOF_SHORT); - } + xlhdr = (xl_multi_insert_tuple *)SHORTALIGN(data); data = ((char *)xlhdr) + SizeOfMultiInsertTuple; datalen = xlhdr->datalen; if (datalen != 0 && AllocSizeIsValid((uint)datalen)) { diff --git a/src/gausskernel/storage/replication/logical/reorderbuffer.cpp b/src/gausskernel/storage/replication/logical/reorderbuffer.cpp index cf96e247a..590b93ab3 100644 --- a/src/gausskernel/storage/replication/logical/reorderbuffer.cpp +++ b/src/gausskernel/storage/replication/logical/reorderbuffer.cpp @@ -1308,7 +1308,6 @@ void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit Relation relation = NULL; Oid reloid; Oid partitionReltoastrelid = InvalidOid; - bool stopDecoding = false; switch (change->action) { case REORDER_BUFFER_CHANGE_INSERT: @@ -1409,10 +1408,7 @@ void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit case REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID: Assert(change->data.command_id != InvalidCommandId); - if (change->data.command_id != FirstCommandId) { - stopDecoding = true; - break; - } + if (command_id < change->data.command_id) { command_id = change->data.command_id; @@ -1440,9 +1436,6 @@ void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("tuplecid value in changequeue"))); break; } - if (stopDecoding) { - break; - } } ReorderBufferIterTXNFinish(rb, iterstate); From e642f9d5f8333818e80d0ae0efd67c028e987e78 Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Thu, 23 Dec 2021 11:59:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0join=E8=A1=8C=E6=95=B0?= =?UTF-8?q?=E4=BC=B0=E7=AE=97=E6=97=B6=E5=80=99=E5=AF=B9=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=87=BD=E6=95=B0=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/gs_guc/cluster_guc.conf | 2 +- src/common/backend/utils/adt/Makefile | 2 +- .../backend/utils/adt/expr_distinct.cpp | 434 ++++++++++++++++++ src/common/backend/utils/adt/selfuncs.cpp | 34 +- src/common/backend/utils/misc/guc.cpp | 2 + src/include/catalog/pg_proc.h | 95 +++- src/include/utils/expr_distinct.h | 27 ++ src/include/utils/guc.h | 4 +- src/include/utils/selfuncs.h | 11 +- 9 files changed, 597 insertions(+), 14 deletions(-) create mode 100644 src/common/backend/utils/adt/expr_distinct.cpp create mode 100644 src/include/utils/expr_distinct.h diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 0a249d265..388612a77 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -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|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| diff --git a/src/common/backend/utils/adt/Makefile b/src/common/backend/utils/adt/Makefile index ca63c5782..f0a42b6c6 100755 --- a/src/common/backend/utils/adt/Makefile +++ b/src/common/backend/utils/adt/Makefile @@ -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 diff --git a/src/common/backend/utils/adt/expr_distinct.cpp b/src/common/backend/utils/adt/expr_distinct.cpp new file mode 100644 index 000000000..c236f2f03 --- /dev/null +++ b/src/common/backend/utils/adt/expr_distinct.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 +#include + +#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]: -------- : 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]: -------- : 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; +} \ No newline at end of file diff --git a/src/common/backend/utils/adt/selfuncs.cpp b/src/common/backend/utils/adt/selfuncs.cpp index d130ee9de..b2a63bce0 100644 --- a/src/common/backend/utils/adt/selfuncs.cpp +++ b/src/common/backend/utils/adt/selfuncs.cpp @@ -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. */ @@ -8697,7 +8713,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; diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index cefe68296..0df24d6a1 100644 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -993,6 +993,8 @@ static const struct config_enum_entry sql_beta_options[] = { {"rand_cost_opt", RAND_COST_OPT, false}, {"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}, {NULL, 0, false} }; diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index c0b350b9d..e80297774 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -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 */ diff --git a/src/include/utils/expr_distinct.h b/src/include/utils/expr_distinct.h new file mode 100644 index 000000000..a81633a03 --- /dev/null +++ b/src/include/utils/expr_distinct.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 */ diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index b63b5d43b..eee2cb014 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -356,7 +356,9 @@ typedef enum { PARAM_PATH_GEN = 4, /* Parametrized Path Generation */ 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 */ + PAGE_EST_OPT = 32, /* More accurate (rowstored) index pages estimation */ + 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 */ } sql_beta_param; #define ENABLE_PRED_PUSH(root) \ diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h index a94eda8ac..5e2404167 100644 --- a/src/include/utils/selfuncs.h +++ b/src/include/utils/selfuncs.h @@ -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, From f615b8d514156aed9b33744fbf3ae2793933158d Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Thu, 23 Dec 2021 17:43:01 +0800 Subject: [PATCH 5/5] =?UTF-8?q?index=E4=BB=A3=E4=BB=B7=E9=AB=98=E4=BC=B0?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=B5=B0bitmapscan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/selfuncs.cpp | 3 +- src/common/backend/utils/misc/guc.cpp | 2 + src/include/utils/guc.h | 4 +- .../bypass_preparedexecute_support.out | 1 + .../expected/bypass_simplequery_support.out | 1 + src/test/regress/expected/gpi_build_index.out | 6 +- src/test/regress/expected/gpi_clean_wait.out | 12 +- src/test/regress/expected/gpi_index.out | 11 +- .../regress/expected/sqlbypass_partition.out | 491 ++++++++--------- .../expected/sqlbypass_partition_prepare.out | 491 ++++++++--------- .../sql/bypass_preparedexecute_support.sql | 1 + .../sql/bypass_simplequery_support.sql | 1 + src/test/regress/sql/sqlbypass_partition.sql | 509 +++++++++--------- .../sql/sqlbypass_partition_prepare.sql | 491 ++++++++--------- 14 files changed, 1009 insertions(+), 1015 deletions(-) diff --git a/src/common/backend/utils/adt/selfuncs.cpp b/src/common/backend/utils/adt/selfuncs.cpp index b2a63bce0..205d22915 100644 --- a/src/common/backend/utils/adt/selfuncs.cpp +++ b/src/common/backend/utils/adt/selfuncs.cpp @@ -6518,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 diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index 0df24d6a1..56602ddd6 100644 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -995,6 +995,8 @@ static const struct config_enum_entry sql_beta_options[] = { {"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} }; diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index eee2cb014..071d7eece 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -358,7 +358,9 @@ typedef enum { 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 */ - JOIN_SEL_WITH_CAST_FUNC = 128 /* support cast function while calculating join selectivity */ + 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) \ diff --git a/src/test/regress/expected/bypass_preparedexecute_support.out b/src/test/regress/expected/bypass_preparedexecute_support.out index a4e9e3b76..371f098ec 100644 --- a/src/test/regress/expected/bypass_preparedexecute_support.out +++ b/src/test/regress/expected/bypass_preparedexecute_support.out @@ -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); diff --git a/src/test/regress/expected/bypass_simplequery_support.out b/src/test/regress/expected/bypass_simplequery_support.out index 8a5b0771e..50203eb9e 100644 --- a/src/test/regress/expected/bypass_simplequery_support.out +++ b/src/test/regress/expected/bypass_simplequery_support.out @@ -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 diff --git a/src/test/regress/expected/gpi_build_index.out b/src/test/regress/expected/gpi_build_index.out index 1ecb18677..509d1ec71 100644 --- a/src/test/regress/expected/gpi_build_index.out +++ b/src/test/regress/expected/gpi_build_index.out @@ -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) diff --git a/src/test/regress/expected/gpi_clean_wait.out b/src/test/regress/expected/gpi_clean_wait.out index 93e775eef..a7ac796a2 100644 --- a/src/test/regress/expected/gpi_clean_wait.out +++ b/src/test/regress/expected/gpi_clean_wait.out @@ -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) diff --git a/src/test/regress/expected/gpi_index.out b/src/test/regress/expected/gpi_index.out index da2967b93..a16c2607d 100644 --- a/src/test/regress/expected/gpi_index.out +++ b/src/test/regress/expected/gpi_index.out @@ -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 diff --git a/src/test/regress/expected/sqlbypass_partition.out b/src/test/regress/expected/sqlbypass_partition.out index 3377a2759..1cf996d12 100644 --- a/src/test/regress/expected/sqlbypass_partition.out +++ b/src/test/regress/expected/sqlbypass_partition.out @@ -1,28 +1,29 @@ -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 -explain insert into test_bypass_sql_partition values (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 +explain insert into test_bypass_sql_partition values (0,0,'test_insert'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -30,8 +31,8 @@ explain insert into test_bypass_sql_partition values (0,0,'test_insert'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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,0,'test_insert'); +explain insert into test_bypass_sql_partition values (0,1,'test_insert'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -39,8 +40,8 @@ explain insert into test_bypass_sql_partition values (0,1,'test_insert'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 (0,1,'test_insert'); +explain insert into test_bypass_sql_partition values (11,1,'test_insert'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -48,8 +49,8 @@ explain insert into test_bypass_sql_partition values (11,1,'test_insert'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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,1,'test_insert'); +explain insert into test_bypass_sql_partition values (11,2,'test_insert'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -57,8 +58,8 @@ explain insert into test_bypass_sql_partition values (11,2,'test_insert'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 (11,2,'test_insert'); +explain insert into test_bypass_sql_partition values (0,10,'test_insert2'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -66,8 +67,8 @@ explain insert into test_bypass_sql_partition values (0,10,'test_insert2'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 (0,10,'test_insert2'); +explain insert into test_bypass_sql_partition values (2,12,'test_insert2'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -75,8 +76,8 @@ explain insert into test_bypass_sql_partition values (2,12,'test_insert2'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 (2,12,'test_insert2'); +explain insert into test_bypass_sql_partition values (30,0,'test_insert3'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -84,8 +85,8 @@ explain insert into test_bypass_sql_partition values (30,0,'test_insert3'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 (30,0,'test_insert3'); +explain insert into test_bypass_sql_partition values (3,3,'test_insert3'); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -93,8 +94,8 @@ explain insert into test_bypass_sql_partition values (3,3,'test_insert3'); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 values (3,3,'test_insert3'); +explain insert into test_bypass_sql_partition(col1,col2) values (1,1); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -102,8 +103,8 @@ explain insert into test_bypass_sql_partition(col1,col2) values (1,1); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 (1,1); +explain insert into test_bypass_sql_partition(col1,col2) values (22,2); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -111,8 +112,8 @@ explain insert into test_bypass_sql_partition(col1,col2) values (22,2); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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 (22,2); +explain insert into test_bypass_sql_partition(col1,col2) values (33,3); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -120,9 +121,9 @@ explain insert into test_bypass_sql_partition(col1,col2) values (33,3); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -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(col1,col2) values (33,3); +--error +explain insert into test_bypass_sql_partition values (null,null,null); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -130,10 +131,10 @@ explain insert into test_bypass_sql_partition values (null,null,null); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -insert into test_bypass_sql_partition values (null,null,null); +insert into test_bypass_sql_partition values (null,null,null); ERROR: inserted partition key does not map to any table partition ---nobypass -explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test'); +--nobypass +explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'test'); QUERY PLAN ---------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because the expression of query is not support. @@ -141,26 +142,26 @@ explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'t -> Result (cost=0.00..5.01 rows=1000 width=0) (3 rows) -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; +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; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -171,13 +172,13 @@ explain select * from test_bypass_sql_partition where col1=0 and col2=0; Selected Partitions: 1 (6 rows) -select * from test_bypass_sql_partition where col1=0 and col2=0; +select * from test_bypass_sql_partition where col1=0 and col2=0; col1 | col2 | col3 ------+------+--------- 0 | 0 | aaaaaaa (1 row) -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; +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; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ [Bypass] @@ -188,7 +189,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<2 Selected Partitions: 2 (6 rows) -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; col1 | col2 ------+------ 11 | 10 @@ -211,7 +212,7 @@ select col1,col2 from test_bypass_sql_partition where col1>10 and col1<20 and co 19 | 20 (18 rows) -explain 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 limit 1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -223,13 +224,13 @@ explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<2 Selected Partitions: 2 (7 rows) -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; col1 | col2 ------+------ 11 | 10 (1 row) -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; +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; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -242,13 +243,13 @@ explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<2 Selected Partitions: 2 (8 rows) -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; col1 | col2 ------+------ 11 | 10 (1 row) -explain 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 col1<20 and col2>0 order by col1,col2 limit 0; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -260,12 +261,12 @@ explain select col1,col2 from test_bypass_sql_partition where col1>10 and col1<2 Selected Partitions: 2 (7 rows) -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; col1 | col2 ------+------ (0 rows) -explain 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=10 and col2=0 order by col1,col2 for update limit 0; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -278,13 +279,12 @@ explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=0 Selected Partitions: 2 (8 rows) -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; col1 | col2 ------+------ (0 rows) - -explain select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2; +explain select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 is not null order by col1,col2; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -295,7 +295,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1 is not null a Selected Partitions: 1..8 (6 rows) -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; col1 | col2 ------+------ 0 | 0 @@ -1180,7 +1180,7 @@ select col1,col2 from test_bypass_sql_partition where col1 is not null and col2 79 | 100 (880 rows) -explain 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 is not null and col2 = 0 order by col1; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1191,7 +1191,7 @@ explain select * from test_bypass_sql_partition where col1 is not null and col2 Selected Partitions: 1..8 (6 rows) -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; col1 | col2 | col3 ------+------+--------- 0 | 0 | aaaaaaa @@ -1276,7 +1276,7 @@ select * from test_bypass_sql_partition where col1 is not null and col2 = 0 orde 79 | 0 | aaaaaaa (80 rows) -explain select * from test_bypass_sql_partition where col1=0 and col2=-1; +explain select * from test_bypass_sql_partition where col1=0 and col2=-1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1287,15 +1287,15 @@ explain select * from test_bypass_sql_partition where col1=0 and col2=-1; Selected Partitions: 1 (6 rows) -select * from test_bypass_sql_partition where col1=0 and col2=-1; +select * from test_bypass_sql_partition where col1=0 and col2=-1; col1 | col2 | col3 ------+------+------ (0 rows) -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; +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; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1306,13 +1306,13 @@ explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=1 Selected Partitions: 2 (6 rows) -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; col1 | col2 ------+------ 10 | 10 (1 row) -explain 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 1; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1324,13 +1324,13 @@ explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=1 Selected Partitions: 2 (7 rows) -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; col1 | col2 ------+------ 10 | 10 (1 row) -explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0; +explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=10 order by col1 limit 0; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1342,14 +1342,14 @@ explain select col1,col2 from test_bypass_sql_partition where col1=10 and col2=1 Selected Partitions: 2 (7 rows) -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; col1 | col2 ------+------ (0 rows) -reset enable_indexscan; ---error -explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1; +reset enable_indexscan; +--error +explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 limit -1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because query used limit count grammar with const less than zero. @@ -1361,9 +1361,9 @@ explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by Selected Partitions: 1 (7 rows) -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; ERROR: LIMIT must not be negative -explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1; +explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by col1 for update limit -1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because query used limit count grammar with const less than zero. @@ -1376,10 +1376,10 @@ explain select * from test_bypass_sql_partition where col1=0 and col2=0 order by Selected Partitions: 1 (8 rows) -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; ERROR: LIMIT must not be negative ---nobypass -explain select * from test_bypass_sql_partition where col1 is null and col2 is null; +--nobypass +explain select * from test_bypass_sql_partition where col1 is null and col2 is null; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in zero partition. @@ -1390,12 +1390,12 @@ explain select * from test_bypass_sql_partition where col1 is null and col2 is n Selected Partitions: NONE (6 rows) -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; col1 | col2 | col3 ------+------+------ (0 rows) -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 where col1 <= 30 and col1 >= 10 order by col1 limit 10; col1 | col2 ------+------ 10 | 0 @@ -1410,7 +1410,7 @@ select col1, col2 from test_bypass_sql_partition where col1 <= 30 and col1 >= 10 10 | 90 (10 rows) -explain 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; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------ [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1422,7 +1422,7 @@ explain select col1, col2 from test_bypass_sql_partition where col1 <= 30 and co Selected Partitions: 2..4 (7 rows) -select col1, col2 from test_bypass_sql_partition order by col1 limit 10; +select col1, col2 from test_bypass_sql_partition order by col1 limit 10; col1 | col2 ------+------ 0 | 0 @@ -1437,7 +1437,7 @@ select col1, col2 from test_bypass_sql_partition order by col1 limit 10; 0 | 90 (10 rows) -explain 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; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1448,7 +1448,7 @@ explain select col1, col2 from test_bypass_sql_partition order by col1 limit 10; Selected Partitions: 1..8 (6 rows) -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; col1 | col2 ------+------ 1 | 0 @@ -1463,7 +1463,7 @@ select col1, col2 from test_bypass_sql_partition where col1 > 0 order by col1 li 1 | 90 (10 rows) -explain 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; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1475,7 +1475,7 @@ explain select col1, col2 from test_bypass_sql_partition where col1 > 0 order by Selected Partitions: 1..8 (7 rows) -select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10; +select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 limit 10; col1 | col2 ------+------ 0 | 0 @@ -1490,7 +1490,7 @@ select col1, col2 from test_bypass_sql_partition where col1 < 20 order by col1 l 0 | 90 (10 rows) -explain 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; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1502,11 +1502,9 @@ explain select col1, col2 from test_bypass_sql_partition where col1 < 20 order b Selected Partitions: 1..2 (7 rows) - ---update ---bypass - -explain update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=0 and col2=0; +--update +--bypass +explain update test_bypass_sql_partition set col2=col2-1,col3='test_update' where col1=0 and col2=0; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1518,8 +1516,8 @@ explain update test_bypass_sql_partition set col2=col2-1,col3='test_update' wher Selected Partitions: 1 (7 rows) -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=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; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1531,8 +1529,8 @@ explain update test_bypass_sql_partition set col2=col1-1,col3='test_update' wher Selected Partitions: 3 (7 rows) -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=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; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1544,9 +1542,9 @@ explain update test_bypass_sql_partition set col2=mod(5,3) where col1=1 and col Selected Partitions: 1 (7 rows) -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'); +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'); QUERY PLAN ---------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because the expression of query is not support. @@ -1554,7 +1552,7 @@ explain insert into test_bypass_sql_partition values(0,generate_series(1,100),'t -> Result (cost=0.00..5.01 rows=1000 width=0) (3 rows) -explain select * from test_bypass_sql_partition where col3 is not null; +explain select * from test_bypass_sql_partition where col3 is not null; QUERY PLAN --------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because query's scan operator is not index. @@ -1565,7 +1563,7 @@ explain select * from test_bypass_sql_partition where col3 is not null; Selected Partitions: 1..8 (6 rows) -explain update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null; +explain update test_bypass_sql_partition set col3='test_null' where col1 is null and col2 is null; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in zero partition. @@ -1577,11 +1575,9 @@ explain update test_bypass_sql_partition set col3='test_null' where col1 is null Selected Partitions: NONE (7 rows) -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 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; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1593,8 +1589,8 @@ explain update test_bypass_sql_partition set col2=111,col3='test_update2' where Selected Partitions: 1 (7 rows) -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; +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; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1605,7 +1601,7 @@ explain select * from test_bypass_sql_partition where col1=0 order by col1; Selected Partitions: 1 (6 rows) -select * from test_bypass_sql_partition where col1=0 order by col1; +select * from test_bypass_sql_partition where col1=0 order by col1; col1 | col2 | col3 ------+------+-------------- 0 | 111 | test_update2 @@ -1621,7 +1617,7 @@ select * from test_bypass_sql_partition where col1=0 order by col1; 0 | 111 | test_update2 (11 rows) -explain 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=0 order by col1 for update limit 2; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1634,14 +1630,14 @@ explain select * from test_bypass_sql_partition where col1=0 order by col1 for u Selected Partitions: 1 (8 rows) -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; col1 | col2 | col3 ------+------+-------------- 0 | 111 | test_update2 0 | 111 | test_update2 (2 rows) -explain select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1; +explain select * from test_bypass_sql_partition where col1=1 and col2=20 order by col1 for update limit 1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1654,15 +1650,14 @@ explain select * from test_bypass_sql_partition where col1=1 and col2=20 order b Selected Partitions: 1 (8 rows) -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; col1 | col2 | col3 ------+------+--------- 1 | 20 | aaaaaaa (1 row) - ---nobypass -explain select * from test_bypass_sql_partition where col2=20 order by col1; +--nobypass +explain select * from test_bypass_sql_partition where col2=20 order by col1; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1673,7 +1668,7 @@ explain select * from test_bypass_sql_partition where col2=20 order by col1; Selected Partitions: 1..8 (6 rows) -select * from test_bypass_sql_partition where col2=20 order by col1; +select * from test_bypass_sql_partition where col2=20 order by col1; col1 | col2 | col3 ------+------+--------- 1 | 20 | aaaaaaa @@ -1757,7 +1752,7 @@ select * from test_bypass_sql_partition where col2=20 order by col1; 79 | 20 | aaaaaaa (79 rows) -explain 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; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1769,7 +1764,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>0 order by co Selected Partitions: 1..8 (7 rows) -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; col1 | col2 ------+------ 1 | 0 @@ -1784,7 +1779,7 @@ select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1 | 90 (10 rows) -explain 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 col1>0 order by col1 limit 3; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1796,7 +1791,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>0 order by co Selected Partitions: 1..8 (7 rows) -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; col1 | col2 ------+------ 1 | 0 @@ -1804,7 +1799,7 @@ select col1,col2 from test_bypass_sql_partition where col1>0 order by col1 limit 1 | 20 (3 rows) -explain 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 col2<50 order by col1 limit 10; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1816,7 +1811,7 @@ explain select col1,col2 from test_bypass_sql_partition where col2<50 order by c Selected Partitions: 1..8 (7 rows) -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; col1 | col2 ------+------ 1 | 0 @@ -1831,7 +1826,7 @@ select col1,col2 from test_bypass_sql_partition where col2<50 order by col1 limi 2 | 40 (10 rows) -explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 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; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1843,7 +1838,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 Selected Partitions: 1..8 (7 rows) -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; col1 | col2 ------+------ 0 | 111 @@ -1858,7 +1853,7 @@ select col1,col2 from test_bypass_sql_partition where col1>=0 and col2>0 order b 0 | 111 (10 rows) -explain select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3; +explain select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 limit 3; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -1870,7 +1865,7 @@ explain select * from test_bypass_sql_partition where col1>=0 and col2>0 order b Selected Partitions: 1..8 (7 rows) -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; col1 | col2 | col3 ------+------+-------------- 0 | 111 | test_update2 @@ -1878,27 +1873,24 @@ select * from test_bypass_sql_partition where col1>=0 and col2>0 order by col1 l 0 | 111 | test_update2 (3 rows) - - -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; +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; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1909,7 +1901,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1=0 order by c Selected Partitions: 1 (6 rows) -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; col1 | col2 ------+------ 0 | 0 @@ -1925,7 +1917,7 @@ select col1,col2 from test_bypass_sql_partition where col1=0 order by col2; 0 | 100 (11 rows) -explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10; +explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 10; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1937,7 +1929,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 Selected Partitions: 1 (7 rows) -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; col1 | col2 ------+------ 1 | 0 @@ -1952,7 +1944,7 @@ select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order b 1 | 90 (10 rows) -explain select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3; +explain select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 limit 3; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1964,7 +1956,7 @@ explain select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 Selected Partitions: 1 (7 rows) -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; col2 | col1 ------+------ 0 | 1 @@ -1972,7 +1964,7 @@ select col2,col1 from test_bypass_sql_partition where col1>0 and col1<10 order b 20 | 1 (3 rows) -explain 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 3; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -1984,7 +1976,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<1 Selected Partitions: 1 (7 rows) -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; col1 | col2 ------+------ 0 | 10 @@ -1992,7 +1984,7 @@ select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and co 0 | 30 (3 rows) -explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null; +explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and col2>0 order by col1 limit null; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2004,7 +1996,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<1 Selected Partitions: 1 (7 rows) -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; col1 | col2 ------+------ 0 | 10 @@ -2109,8 +2101,8 @@ select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<10 and co 9 | 100 (100 rows) ---nobypass -explain select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10; +--nobypass +explain select col2,col1 from test_bypass_sql_partition where col2=2 order by col1 limit 10; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -2122,13 +2114,12 @@ explain select col2,col1 from test_bypass_sql_partition where col2=2 order by co Selected Partitions: 1..8 (7 rows) -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; col2 | col1 ------+------ (0 rows) - -explain 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 col1 is null and col2 is null limit 10; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in zero partition. @@ -2140,13 +2131,12 @@ explain select col1,col2 from test_bypass_sql_partition where col1 is null and c Selected Partitions: NONE (7 rows) -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; col1 | col2 ------+------ (0 rows) - -explain 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 col2<5 order by col1 limit 10; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -2158,7 +2148,7 @@ explain select col1,col2 from test_bypass_sql_partition where col2<5 order by co Selected Partitions: 1..8 (7 rows) -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; col1 | col2 ------+------ 0 | 0 @@ -2173,7 +2163,7 @@ select col1,col2 from test_bypass_sql_partition where col2<5 order by col1 limit 9 | 0 (10 rows) -explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and col2>0 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; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -2185,7 +2175,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<= Selected Partitions: 1..2 (7 rows) -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; col1 | col2 ------+------ 0 | 10 @@ -2200,11 +2190,9 @@ select col1,col2 from test_bypass_sql_partition where col1>=0 and col1<=10 and c 0 | 100 (10 rows) - -reset enable_indexscan; - ---nobypass -explain select * from test_bypass_sql_partition where col1>col2 limit 10; +reset enable_indexscan; +--nobypass +explain select * from test_bypass_sql_partition where col1>col2 limit 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because query's scan operator is not index. @@ -2216,7 +2204,7 @@ explain select * from test_bypass_sql_partition where col1>col2 limit 10; Selected Partitions: 1..8 (7 rows) -explain select * from test_bypass_sql_partition where col1=3 and col2=3 for update; +explain select * from test_bypass_sql_partition where col1=3 and col2=3 for update; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2228,12 +2216,12 @@ explain select * from test_bypass_sql_partition where col1=3 and col2=3 for upda Selected Partitions: 1 (7 rows) -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; col1 | col2 | col3 ------+------+------ (0 rows) -explain select * from test_bypass_sql_partition where col3='test_update2'; +explain select * from test_bypass_sql_partition where col3='test_update2'; QUERY PLAN ------------------------------------------------------------------------------------------------------------------ [No Bypass]reason: Bypass not executed because query's scan operator is not index. @@ -2244,8 +2232,7 @@ explain select * from test_bypass_sql_partition where col3='test_update2'; Selected Partitions: 1..8 (6 rows) - -explain 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 and col2>0 order by col1 limit 3 offset 3; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2257,7 +2244,7 @@ explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col Selected Partitions: 1 (7 rows) -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; col1 | col2 | col3 ------+------+--------- 1 | 40 | aaaaaaa @@ -2265,7 +2252,7 @@ select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 orde 1 | 60 | aaaaaaa (3 rows) -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 3; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2278,7 +2265,7 @@ explain select * from test_bypass_sql_partition where col1>0 and col1<10 order b Selected Partitions: 1 (8 rows) -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 order by col1 for update limit 3 offset null; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2291,7 +2278,7 @@ explain select * from test_bypass_sql_partition where col1>0 and col1<10 order b Selected Partitions: 1 (8 rows) -explain 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 and col2>0 order by col1 offset 3; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2303,7 +2290,7 @@ explain select * from test_bypass_sql_partition where col1>0 and col1<10 and col Selected Partitions: 1 (7 rows) -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; col1 | col2 | col3 ------+------+--------- 1 | 40 | aaaaaaa @@ -2395,7 +2382,7 @@ select * from test_bypass_sql_partition where col1>0 and col1<10 and col2>0 orde 9 | 100 | aaaaaaa (87 rows) -explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update offset 3; +explain select * from test_bypass_sql_partition where col1>0 and col1<10 order by col1 for update offset 3; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2408,7 +2395,7 @@ explain select * from test_bypass_sql_partition where col1>0 and col1<10 order b Selected Partitions: 1 (8 rows) -explain update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2; +explain update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2420,8 +2407,8 @@ explain update test_bypass_sql_partition set col2=3*7 where col1=3 and col2=2; Selected Partitions: 1 (7 rows) -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; +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; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2433,9 +2420,9 @@ explain delete from test_bypass_sql_partition where col1=1 and col2=1; Selected Partitions: 1 (7 rows) -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=1 and col2=1; +--error +explain delete from test_bypass_sql_partition where col1 is null and col2 is null; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in zero partition. @@ -2447,8 +2434,8 @@ explain delete from test_bypass_sql_partition where col1 is null and col2 is nul Selected Partitions: NONE (7 rows) -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); +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); QUERY PLAN ----------------------------------------------------------------------- [Bypass] @@ -2456,10 +2443,10 @@ explain insert into test_bypass_sql_partition values (null,null,null); -> Result (cost=0.00..0.01 rows=1 width=0) (3 rows) -insert into test_bypass_sql_partition values (null,null,null); +insert into test_bypass_sql_partition values (null,null,null); ERROR: inserted partition key does not map to any table partition ---bypass / set enable_bitmapscan=off; -select * from test_bypass_sql_partition where col1=3; +--bypass / set enable_bitmapscan=off; +select * from test_bypass_sql_partition where col1=3; col1 | col2 | col3 ------+------+--------- 3 | 0 | aaaaaaa @@ -2475,7 +2462,7 @@ select * from test_bypass_sql_partition where col1=3; 3 | 100 | aaaaaaa (11 rows) -explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc; +explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- [Bypass] @@ -2486,20 +2473,20 @@ explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 Selected Partitions: 1 (6 rows) -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 +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 ERROR: syntax error at or near "desc" LINE 1: ...tition where col1>0 and col1<10 order by col1 limit 10 desc; ^ -explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1; +explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 limit 10 order by col1; ERROR: syntax error at or near "order" LINE 1: ...s_sql_partition where col1>0 and col1<10 limit 10 order by c... ^ -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; ERROR: syntax error at or near "order" LINE 1: ...s_sql_partition where col1>0 and col1<10 limit 10 order by c... ^ ---not bypass -explain select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10; +--not bypass +explain select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -2510,7 +2497,7 @@ explain select col1,col2 from test_bypass_sql_partition order by col1,col2 limit Selected Partitions: 1..8 (6 rows) -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; col1 | col2 ------+------ 0 | 0 @@ -2525,7 +2512,7 @@ select col1,col2 from test_bypass_sql_partition order by col1,col2 limit 10; 0 | 90 (10 rows) -explain select * from test_bypass_sql_partition where col1 > 0 order by col1,col2 desc limit 10; +explain select * from test_bypass_sql_partition where col1 > 0 order by col1,col2 desc limit 10; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because query's scan operator is not index. @@ -2539,8 +2526,8 @@ explain select * from test_bypass_sql_partition where col1 > 0 order by col1,col Selected Partitions: 1..8 (9 rows) ---bypass -explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10 ; +--bypass +explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1,col2 limit 10 ; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------ [Bypass] @@ -2552,7 +2539,7 @@ explain select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 Selected Partitions: 1 (7 rows) -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; col1 | col2 ------+------ 1 | 0 @@ -2567,8 +2554,8 @@ select col1,col2 from test_bypass_sql_partition where col1>0 and col1<10 order b 1 | 90 (10 rows) ---not bypass -explain select * from test_bypass_sql_partition where true; +--not bypass +explain select * from test_bypass_sql_partition where true; QUERY PLAN --------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because query's scan operator is not index. @@ -2578,7 +2565,7 @@ explain select * from test_bypass_sql_partition where true; Selected Partitions: 1..8 (5 rows) -explain select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10; +explain select col1, col2 from test_bypass_sql_partition where true order by col1 limit 10; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not support query in multiple partitions. @@ -2589,7 +2576,7 @@ explain select col1, col2 from test_bypass_sql_partition where true order by col Selected Partitions: 1..8 (6 rows) -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; col1 | col2 ------+------ 0 | 0 @@ -2604,9 +2591,8 @@ select col1, col2 from test_bypass_sql_partition where true order by col1 limit 0 | 90 (10 rows) ---bypass - -select col2, col1 from test_bypass_sql_partition where col1>0 and col1<10 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; col2 | col1 ------+------ 0 | 1 @@ -2621,7 +2607,7 @@ select col2, col1 from test_bypass_sql_partition where col1>0 and col1<10 order 90 | 1 (10 rows) -select col1, col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc limit 10; +select col1, col2 from test_bypass_sql_partition where col1>0 and col1<10 order by col1 desc limit 10; col1 | col2 ------+------ 9 | 100 @@ -2636,7 +2622,7 @@ select col1, col2 from test_bypass_sql_partition where col1>0 and col1<10 order 9 | 10 (10 rows) -explain insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1=0; +explain insert into test_bypass_sql_partition select * from test_bypass_sql_partition where col1=0; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- [No Bypass]reason: Bypass not executed because query combines insert operator with others. @@ -2648,15 +2634,12 @@ explain insert into test_bypass_sql_partition select * from test_bypass_sql_part Selected Partitions: 1 (7 rows) - -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; - +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; diff --git a/src/test/regress/expected/sqlbypass_partition_prepare.out b/src/test/regress/expected/sqlbypass_partition_prepare.out index 88f5985aa..628083833 100644 --- a/src/test/regress/expected/sqlbypass_partition_prepare.out +++ b/src/test/regress/expected/sqlbypass_partition_prepare.out @@ -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; + diff --git a/src/test/regress/sql/bypass_preparedexecute_support.sql b/src/test/regress/sql/bypass_preparedexecute_support.sql index 1cbeab61a..011ae1c88 100644 --- a/src/test/regress/sql/bypass_preparedexecute_support.sql +++ b/src/test/regress/sql/bypass_preparedexecute_support.sql @@ -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); diff --git a/src/test/regress/sql/bypass_simplequery_support.sql b/src/test/regress/sql/bypass_simplequery_support.sql index d3d3937f9..5e9bf0b72 100644 --- a/src/test/regress/sql/bypass_simplequery_support.sql +++ b/src/test/regress/sql/bypass_simplequery_support.sql @@ -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; diff --git a/src/test/regress/sql/sqlbypass_partition.sql b/src/test/regress/sql/sqlbypass_partition.sql index 756be8b82..d929e76b3 100644 --- a/src/test/regress/sql/sqlbypass_partition.sql +++ b/src/test/regress/sql/sqlbypass_partition.sql @@ -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; + diff --git a/src/test/regress/sql/sqlbypass_partition_prepare.sql b/src/test/regress/sql/sqlbypass_partition_prepare.sql index 7f7748633..f30289f41 100644 --- a/src/test/regress/sql/sqlbypass_partition_prepare.sql +++ b/src/test/regress/sql/sqlbypass_partition_prepare.sql @@ -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; +