[Huawei] seqscan 优化

Offering: GaussDB Kernel

    More detail: seqscan 优化
This commit is contained in:
wuchenglin 2022-11-17 01:38:10 -08:00
parent 1ae5fbfc0e
commit fabd0159e4
9 changed files with 96 additions and 23 deletions

View File

@ -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|

View File

@ -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),

View File

@ -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);

View File

@ -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,

View File

@ -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();

View File

@ -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);

View File

@ -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 */

View File

@ -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)",

View File

@ -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;