From fabd0159e470b1d87c32b26b11e460d58268697b Mon Sep 17 00:00:00 2001 From: wuchenglin Date: Thu, 17 Nov 2022 01:38:10 -0800 Subject: [PATCH] =?UTF-8?q?=20=20=20=20[Huawei]=20seqscan=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Offering: GaussDB Kernel More detail: seqscan 优化 --- src/bin/gs_guc/cluster_guc.conf | 2 ++ src/common/backend/parser/analyze.cpp | 20 ++++++++++--- src/common/backend/parser/parser.cpp | 19 +++++++----- src/common/backend/utils/misc/guc.cpp | 24 +++++++++++++++ .../process/postmaster/postmaster.cpp | 5 +++- src/gausskernel/runtime/executor/execMain.cpp | 16 +++++++--- .../runtime/executor/instrument.cpp | 29 +++++++++++++++---- .../storage/access/heap/heapam.cpp | 2 +- .../knl/knl_guc/knl_session_attr_common.h | 2 ++ 9 files changed, 96 insertions(+), 23 deletions(-) diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index a19a76d86..faf56eb61 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -203,6 +203,8 @@ enable_partitionwise|bool|0,0|NULL|NULL| enable_pbe_optimization|bool|0,0|NULL|NULL| enable_prevent_job_task_startup|bool|0,0|NULL|It is not recommended to enable this parameter except for scaling out.| enable_security_policy|bool|0,0|NULL|NULL| +enable_seqscan_fusion|bool|0,0|NULL|NULL| +enable_parser_fusion|bool|0,0|NULL|NULL| use_elastic_search|bool|0,0|NULL|NULL| elastic_search_ip_addr|string|0,0|NULL|NULL enable_resource_track|bool|0,0|NULL|NULL| diff --git a/src/common/backend/parser/analyze.cpp b/src/common/backend/parser/analyze.cpp index 3c6445118..5d84c25b8 100644 --- a/src/common/backend/parser/analyze.cpp +++ b/src/common/backend/parser/analyze.cpp @@ -1422,7 +1422,11 @@ static Query* transformInsertStmt(ParseState* pstate, InsertStmt* stmt) } qry->resultRelation = setTargetTable(pstate, stmt->relation, false, false, targetPerms); - if (pstate->p_target_relation != NULL && + if ( +#ifndef ENABLE_MULTIPLE_NODES + !u_sess->attr.attr_common.enable_parser_fusion && +#endif + pstate->p_target_relation != NULL && ((unsigned int)RelationGetInternalMask(pstate->p_target_relation) & INTERNAL_MASK_DINSERT)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -1432,7 +1436,7 @@ static Query* transformInsertStmt(ParseState* pstate, InsertStmt* stmt) #ifdef ENABLE_MULTIPLE_NODES if (IS_PGXC_COORDINATOR && !IsConnFromCoord()) { #endif - if (pstate->p_target_relation != NULL + if (!u_sess->attr.attr_common.enable_parser_fusion && pstate->p_target_relation != NULL && RelationIsMatview(pstate->p_target_relation) && !stmt->isRewritten) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -1443,7 +1447,11 @@ static Query* transformInsertStmt(ParseState* pstate, InsertStmt* stmt) } #endif - if (pstate->p_target_relation != NULL && stmt->upsertClause != NULL) { + if ( +#ifndef ENABLE_MULTIPLE_NODES + !u_sess->attr.attr_common.enable_parser_fusion && +#endif + pstate->p_target_relation != NULL && stmt->upsertClause != NULL) { /* non-supported upsert cases */ if (!u_sess->attr.attr_sql.enable_upsert_to_merge && RelationIsColumnFormat(pstate->p_target_relation)) { ereport(ERROR, ((errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -1475,7 +1483,11 @@ static Query* transformInsertStmt(ParseState* pstate, InsertStmt* stmt) * We reply on gs_redis to ganurantee DFS table to be read only during online expansion * so we don't need to double check if target table is DFS table here anymore. */ - if (!u_sess->attr.attr_sql.enable_cluster_resize && pstate->p_target_relation != NULL && + if ( +#ifndef ENABLE_MULTIPLE_NODES + !u_sess->attr.attr_common.enable_parser_fusion && +#endif + !u_sess->attr.attr_sql.enable_cluster_resize && pstate->p_target_relation != NULL && RelationInClusterResizingWriteErrorMode(pstate->p_target_relation)) { ereport(ERROR, (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION), diff --git a/src/common/backend/parser/parser.cpp b/src/common/backend/parser/parser.cpp index 61d8c2dee..77edf2f01 100644 --- a/src/common/backend/parser/parser.cpp +++ b/src/common/backend/parser/parser.cpp @@ -49,15 +49,20 @@ List* raw_parser(const char* str, List** query_string_locationlist) core_yyscan_t yyscanner; base_yy_extra_type yyextra; int yyresult; +#ifndef ENABLE_MULTIPLE_NODES + if (!u_sess->attr.attr_common.enable_parser_fusion) { +#endif + /* reset u_sess->parser_cxt.stmt_contains_operator_plus */ + resetOperatorPlusFlag(); - /* reset u_sess->parser_cxt.stmt_contains_operator_plus */ - resetOperatorPlusFlag(); + /* reset u_sess->parser_cxt.isTimeCapsule */ + resetIsTimeCapsuleFlag(); - /* reset u_sess->parser_cxt.isTimeCapsule */ - resetIsTimeCapsuleFlag(); - - /* reset u_sess->parser_cxt.isCreateFuncOrProc */ - resetCreateFuncFlag(); + /* reset u_sess->parser_cxt.isCreateFuncOrProc */ + resetCreateFuncFlag(); +#ifndef ENABLE_MULTIPLE_NODES + } +#endif /* initialize the flex scanner */ yyscanner = scanner_init(str, &yyextra.core_yy_extra, &ScanKeywords, ScanKeywordTokens); diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index ca896168d..68062e001 100755 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -1753,6 +1753,30 @@ static void InitConfigureNamesBool() NULL, NULL, NULL}, +#ifndef ENABLE_MULTIPLE_NODES + {{"enable_seqscan_fusion", + PGC_USERSET, + NODE_SINGLENODE, + QUERY_TUNING, + gettext_noop("Enable seqScan fusion"), + NULL}, + &u_sess->attr.attr_common.enable_seqscan_fusion, + false, + NULL, + NULL, + NULL}, + {{"enable_parser_fusion", + PGC_USERSET, + NODE_SINGLENODE, + QUERY_TUNING, + gettext_noop("Enable parser fusion"), + NULL}, + &u_sess->attr.attr_common.enable_parser_fusion, + false, + NULL, + NULL, + NULL}, +#endif {{"ts_adaptive_threads", PGC_SIGHUP, NODE_DISTRIBUTE, diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index 8412eb67d..3e219b0ac 100644 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -12144,7 +12144,10 @@ int GaussDbThreadMain(knl_thread_arg* arg) ledger_hook_init(); /* unique sql hooks */ - instr_unique_sql_register_hook(); +#ifndef ENABLE_MULTIPLE_NODES + if (!u_sess->attr.attr_common.enable_parser_fusion) +#endif + instr_unique_sql_register_hook(); /* hypopg index hooks */ hypopg_register_hook(); diff --git a/src/gausskernel/runtime/executor/execMain.cpp b/src/gausskernel/runtime/executor/execMain.cpp index 6fa426e99..c35fc9725 100755 --- a/src/gausskernel/runtime/executor/execMain.cpp +++ b/src/gausskernel/runtime/executor/execMain.cpp @@ -619,8 +619,12 @@ void standard_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long co /* * if current plan is working for expression, no need to collect instrumentation. */ - if (estate->es_instrument != INSTRUMENT_NONE && StreamTopConsumerAmI() && u_sess->instr_cxt.global_instr && - u_sess->instr_cxt.thread_instr) { + if ( +#ifndef ENABLE_MULTIPLE_NODES + !u_sess->attr.attr_common.enable_seqscan_fusion && +#endif + estate->es_instrument != INSTRUMENT_NONE + && StreamTopConsumerAmI() && u_sess->instr_cxt.global_instr && u_sess->instr_cxt.thread_instr) { int node_id = queryDesc->plannedstmt->planTree->plan_node_id - 1; int* m_instrArrayMap = u_sess->instr_cxt.thread_instr->m_instrArrayMap; @@ -2260,8 +2264,12 @@ static void ExecutePlan(EState *estate, PlanState *planstate, CmdType operation, /* * if current plan is working for expression, no need to collect instrumentation. */ - if (estate->es_instrument != INSTRUMENT_NONE && u_sess->instr_cxt.global_instr && StreamTopConsumerAmI() && - u_sess->instr_cxt.thread_instr) { + if ( +#ifndef ENABLE_MULTIPLE_NODES + !u_sess->attr.attr_common.enable_seqscan_fusion && +#endif + estate->es_instrument != INSTRUMENT_NONE && + u_sess->instr_cxt.global_instr && StreamTopConsumerAmI() && u_sess->instr_cxt.thread_instr) { int64 peak_memory = (uint64)(t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->peakChunksQuery - t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->initMemInChunks) << (chunkSizeInBits - BITS_IN_MB); diff --git a/src/gausskernel/runtime/executor/instrument.cpp b/src/gausskernel/runtime/executor/instrument.cpp index 1850883f1..7161451d6 100644 --- a/src/gausskernel/runtime/executor/instrument.cpp +++ b/src/gausskernel/runtime/executor/instrument.cpp @@ -476,12 +476,20 @@ Instrumentation* InstrAlloc(int n, int instrument_options) /* Entry to a plan node */ void InstrStartNode(Instrumentation* instr) { - if (!instr->first_time) { + if ( +#ifndef ENABLE_MULTIPLE_NODES + !u_sess->attr.attr_common.enable_seqscan_fusion && +#endif + !instr->first_time) { instr->enter_time = GetCurrentTimestamp(); instr->first_time = true; } - CPUUsageGetCurrent(&instr->cpuusage_start); +#ifndef ENABLE_MULTIPLE_NODES + if (!u_sess->attr.attr_common.enable_seqscan_fusion) +#endif + CPUUsageGetCurrent(&instr->cpuusage_start); + if (instr->need_timer) { if (INSTR_TIME_IS_ZERO(instr->starttime)) { @@ -546,22 +554,31 @@ void InstrStopNode(Instrumentation* instr, double n_tuples, bool containMemory) INSTR_TIME_SET_ZERO(instr->starttime); } - CPUUsageGetCurrent(&cpu_usage); +#ifndef ENABLE_MULTIPLE_NODES + if (!u_sess->attr.attr_common.enable_seqscan_fusion) +#endif + CPUUsageGetCurrent(&cpu_usage); /* Add delta of buffer usage since entry to node's totals */ if (instr->need_bufusage) { BufferUsageAccumDiff(&instr->bufusage, u_sess->instr_cxt.pg_buffer_usage, &instr->bufusage_start); } - CPUUsageAccumDiff(&instr->cpuusage, &cpu_usage, &instr->cpuusage_start); +#ifndef ENABLE_MULTIPLE_NODES + if (!u_sess->attr.attr_common.enable_seqscan_fusion) +#endif + CPUUsageAccumDiff(&instr->cpuusage, &cpu_usage, &instr->cpuusage_start); /* Is this the first tuple of this cycle? */ if (!instr->running) { instr->running = true; instr->firsttuple = INSTR_TIME_GET_DOUBLE(instr->counter); } - - if (containMemory) { + if ( +#ifndef ENABLE_MULTIPLE_NODES + !u_sess->attr.attr_common.enable_seqscan_fusion && +#endif + containMemory) { int64 memory_size = 0; int64 control_memory_size = 0; /* calculate the memory context size of this Node */ diff --git a/src/gausskernel/storage/access/heap/heapam.cpp b/src/gausskernel/storage/access/heap/heapam.cpp index f1447f8b5..03b9c4060 100755 --- a/src/gausskernel/storage/access/heap/heapam.cpp +++ b/src/gausskernel/storage/access/heap/heapam.cpp @@ -2499,7 +2499,7 @@ bool heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, S HeapTupleCopyBaseFromPage(heap_tuple, dp); CheckForSerializableConflictOut(valid, relation, (void*)heap_tuple, buffer, snapshot); - if (SHOW_DEBUG_MESSAGE()) { + if (unlikely(SHOW_DEBUG_MESSAGE())) { ereport(DEBUG1, (errmsg("heap_hot_search_buffer xid %lu self(%u,%hu) ctid(%u,%hu) valid %d " "pointer(%u,%hu)", diff --git a/src/include/knl/knl_guc/knl_session_attr_common.h b/src/include/knl/knl_guc/knl_session_attr_common.h index 461581e3b..02fd3faea 100644 --- a/src/include/knl/knl_guc/knl_session_attr_common.h +++ b/src/include/knl/knl_guc/knl_session_attr_common.h @@ -219,6 +219,8 @@ typedef struct knl_session_attr_common { char* node_name; #ifndef ENABLE_MULTIPLE_NODES bool plsql_show_all_error; + bool enable_seqscan_fusion; + bool enable_parser_fusion; #endif uint32 extension_session_vars_array_size; void** extension_session_vars_array;