From a6e8ede67d5035ffef4d96441e78de177ecbf1e9 Mon Sep 17 00:00:00 2001 From: TinyBag Date: Thu, 15 Aug 2024 14:45:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=B8=AD=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8F=98=E9=87=8F=E5=8D=A1=E4=BD=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runtime/executor/nodeIndexscan.cpp | 6 ++++- .../runtime/executor/nodeSubplan.cpp | 4 +++- .../set_user_defined_variables_test.source | 17 ++++++++++++++ .../set_user_defined_variables_test.source | 22 +++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/gausskernel/runtime/executor/nodeIndexscan.cpp b/src/gausskernel/runtime/executor/nodeIndexscan.cpp index 0d5684ea1..4ec3b22c1 100644 --- a/src/gausskernel/runtime/executor/nodeIndexscan.cpp +++ b/src/gausskernel/runtime/executor/nodeIndexscan.cpp @@ -168,7 +168,7 @@ static TupleTableSlot* ExecIndexScan(PlanState* state) /* * If we have runtime keys and they've not already been set up, do it now. */ - if (node->iss_NumRuntimeKeys != 0 && (!node->iss_RuntimeKeysReady || (u_sess->parser_cxt.has_set_uservar && DB_IS_CMPT(B_FORMAT)))) { + if (node->iss_NumRuntimeKeys != 0 && !node->iss_RuntimeKeysReady) { /* * set a flag for partitioned table, so we can deal with it specially * when we rescan the partitioned table @@ -181,6 +181,10 @@ static TupleTableSlot* ExecIndexScan(PlanState* state) } else { ExecReScan((PlanState*)node); } + } else if (DB_IS_CMPT(B_FORMAT) && node->iss_NumRuntimeKeys != 0 && u_sess->parser_cxt.has_set_uservar) { + ExprContext* econtext = node->iss_RuntimeContext; + ResetExprContext(econtext); + ExecIndexEvalRuntimeKeys(econtext, node->iss_RuntimeKeys, node->iss_NumRuntimeKeys); } return ExecScan(&node->ss, (ExecScanAccessMtd)IndexNext, (ExecScanRecheckMtd)IndexRecheck); diff --git a/src/gausskernel/runtime/executor/nodeSubplan.cpp b/src/gausskernel/runtime/executor/nodeSubplan.cpp index b57d0b584..5f78ba810 100644 --- a/src/gausskernel/runtime/executor/nodeSubplan.cpp +++ b/src/gausskernel/runtime/executor/nodeSubplan.cpp @@ -991,8 +991,10 @@ void ExecSetParamPlan(SubPlanState* node, ExprContext* econtext) MemoryContext oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory); if (u_sess->parser_cxt.has_set_uservar && DB_IS_CMPT(B_FORMAT)) { - if (nodeTag(planstate) == T_SeqScanState) { + if (IsA(planstate, SeqScanState)) { scan_handler_tbl_restrpos(castNode(SeqScanState, planstate)->ss_currentScanDesc); + } else if (IsA(planstate, IndexScanState)) { + ExecReScan(planstate); } } diff --git a/src/test/regress/input/set_user_defined_variables_test.source b/src/test/regress/input/set_user_defined_variables_test.source index f9f9e8075..544038e8c 100644 --- a/src/test/regress/input/set_user_defined_variables_test.source +++ b/src/test/regress/input/set_user_defined_variables_test.source @@ -774,6 +774,23 @@ END WHILE label_1; end; / SELECT TRIM(TRAILING ', ' FROM @sequence); + +-- index scan卡住问题 +\c test_set +set enable_set_variable_b_format = 1; +set enable_seqscan = false; +set enable_bitmapscan = false; +create table account_instance_stats(id int primary key, stat_id int); +insert into account_instance_stats values(1,1),(2,1),(3,1),(4,1); +set @pids = 1; + +SELECT stat_id, @pids := id FROM account_instance_stats where id >= @pids; + +drop table account_instance_stats; +set enable_seqscan = default; +set enable_bitmapscan = default; +set enable_set_variable_b_format = default; + \c regression drop database if exists test_set; diff --git a/src/test/regress/output/set_user_defined_variables_test.source b/src/test/regress/output/set_user_defined_variables_test.source index 032412d9c..19ab1926a 100644 --- a/src/test/regress/output/set_user_defined_variables_test.source +++ b/src/test/regress/output/set_user_defined_variables_test.source @@ -1520,6 +1520,28 @@ SELECT TRIM(TRAILING ', ' FROM @sequence); 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 (1 row) +-- index scan卡住问题 +\c test_set +set enable_set_variable_b_format = 1; +set enable_seqscan = false; +set enable_bitmapscan = false; +create table account_instance_stats(id int primary key, stat_id int); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "account_instance_stats_pkey" for table "account_instance_stats" +insert into account_instance_stats values(1,1),(2,1),(3,1),(4,1); +set @pids = 1; +SELECT stat_id, @pids := id FROM account_instance_stats where id >= @pids; + stat_id | ?column? +---------+---------- + 1 | 1 + 1 | 2 + 1 | 3 + 1 | 4 +(4 rows) + +drop table account_instance_stats; +set enable_seqscan = default; +set enable_bitmapscan = default; +set enable_set_variable_b_format = default; \c regression drop database if exists test_set; \! @abs_bindir@/gs_guc reload -Z datanode -D @abs_srcdir@/tmp_check/datanode1 -c "enable_set_variable_b_format=off" >/dev/null 2>&1