diff --git a/src/gausskernel/process/tcop/dest.cpp b/src/gausskernel/process/tcop/dest.cpp index 49586e9bbdb31ca52cb03130a0be448cc47479a3..da5524ee7b4f1955fc5f24c06d5e0380ac4cb820 100644 --- a/src/gausskernel/process/tcop/dest.cpp +++ b/src/gausskernel/process/tcop/dest.cpp @@ -67,8 +67,14 @@ static DestReceiver donothingDR = {donothingReceive, donothingStartup, donothing static DestReceiver debugtupDR = {debugtup, debugStartup, donothingCleanup, donothingCleanup, DestDebug}; -static DestReceiver spi_printtupDR = {spi_printtup, spi_dest_startup, donothingCleanup, donothingCleanup, DestSPI}; - +void InitSpiPrinttupDR(DestReceiver* dr) +{ + dr->receiveSlot = spi_printtup; + dr->rStartup = spi_dest_startup; + dr->rShutdown = donothingCleanup; + dr->rDestroy = donothingCleanup; + dr->mydest = DestSPI; +} /* Globally available receiver for DestNone */ DestReceiver* None_Receiver = &donothingDR; @@ -118,7 +124,8 @@ DestReceiver* CreateDestReceiver(CommandDest dest) return &debugtupDR; case DestSPI: - return &spi_printtupDR; + u_sess->utils_cxt.spi_printtupDR->mydest = DestSPI; + return u_sess->utils_cxt.spi_printtupDR; case DestSPITupleAnalyze: return createAnalyzeSPIDestReceiver(dest); diff --git a/src/gausskernel/process/threadpool/knl_session.cpp b/src/gausskernel/process/threadpool/knl_session.cpp index 5d16a69d354e752886187da44ec8ff111eccb543..e2e23bb541e01e4ab152a2e24d25e881927948ef 100755 --- a/src/gausskernel/process/threadpool/knl_session.cpp +++ b/src/gausskernel/process/threadpool/knl_session.cpp @@ -463,6 +463,9 @@ static void knl_u_utils_init(knl_u_utils_context* utils_cxt) utils_cxt->enable_memory_context_control = false; utils_cxt->sql_ignore_strategy_val = 0; (void)syscalllockInit(&utils_cxt->deleMemContextMutex); + + utils_cxt->spi_printtupDR = (DestReceiver*)palloc0(sizeof(DestReceiver)); + InitSpiPrinttupDR(utils_cxt->spi_printtupDR); } static void knl_u_security_init(knl_u_security_context* sec_cxt) { diff --git a/src/include/knl/knl_session.h b/src/include/knl/knl_session.h index 9f6116f4d4e65033ac5ffc756f80b1f1f1bdaad4..bea14384a34898c16d0001885b22f2b71f667902 100644 --- a/src/include/knl/knl_session.h +++ b/src/include/knl/knl_session.h @@ -67,6 +67,7 @@ #include "utils/memgroup.h" #include "storage/lock/lock.h" #include "utils/elog.h" +#include "tcop/dest.h" typedef void (*pg_on_exit_callback)(int code, Datum arg); @@ -665,6 +666,7 @@ typedef struct knl_u_utils_context { unsigned int sql_ignore_strategy_val; HTAB* set_user_params_htab; + DestReceiver* spi_printtupDR; } knl_u_utils_context; typedef struct knl_u_security_context { diff --git a/src/include/tcop/dest.h b/src/include/tcop/dest.h index 0d3fe01283a9a202ea59690207988c6c5f1efc2f..72e8c3c314675edbcda3b0c85298f9622f9f8de3 100644 --- a/src/include/tcop/dest.h +++ b/src/include/tcop/dest.h @@ -169,5 +169,7 @@ extern void NullCommand(CommandDest dest); extern void ReadyForQuery(CommandDest dest); extern void ReadyForQuery_noblock(CommandDest dest, int timeout); +extern void InitSpiPrinttupDR(DestReceiver* dr); + #endif /* !FRONTEND_PARSER */ #endif /* DEST_H */ diff --git a/src/test/regress/expected/plan_table_for_anonymous_block.out b/src/test/regress/expected/plan_table_for_anonymous_block.out new file mode 100644 index 0000000000000000000000000000000000000000..4801ff8c82ee97b314e1c04a50bed53827b27694 --- /dev/null +++ b/src/test/regress/expected/plan_table_for_anonymous_block.out @@ -0,0 +1,56 @@ +drop table if exists t_s_condition_0011_1 cascade; +NOTICE: table "t_s_condition_0011_1" does not exist, skipping +drop table if exists t_s_condition_0011_2; +NOTICE: table "t_s_condition_0011_2" does not exist, skipping +create table t_s_condition_0011_2(id int) with (storage_type=ustore); +insert into t_s_condition_0011_2 values(1); +create table t_s_condition_0011_1(staff_id int not null, highest_degree char(8), graduate_school varchar(64), graduate_date smalldatetime, t_education_note varchar(70)) with (storage_type=ustore); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(10,'博士','西安电子科技大学','2017-07-06 12:00:00','211'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(11,'博士','西北农林科技大学','2017-07-06 12:00:00','211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(12,'硕士','西北工业大学','2017-07-06 12:00:00','211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(15,'学士','西安建筑科技大学','2017-07-06 12:00:00','非211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(18,'硕士','西安理工大学','2017-07-06 12:00:00','非211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(20,'学士','北京师范大学','2017-07-06 12:00:00','211和985'); +create or replace function f_s_condition_0011(a int) return int +as +c int; +d int; +begin +c := a; +select id into d from t_s_condition_0011_2 where rownum = c; +return d; +end ; +/ +drop procedure if exists p_s_condition_0011_1; +NOTICE: function p_s_condition_0011_1() does not exist, skipping +create or replace procedure p_s_condition_0011_1 +as +begin +explain plan for select * from (select highest_degree,graduate_date from t_s_condition_0011_2 right join t_s_condition_0011_1 on staff_id = id where f_s_condition_0011(1) = 1) where graduate_date < to_date('2018-06-28 13:14:15', 'yyyy-mm-dd hh24:mi:ss:ff') order by highest_degree asc; +explain plan for select * from (select highest_degree,graduate_date from t_s_condition_0011_2 right join t_s_condition_0011_1 on staff_id = id where f_s_condition_0011(1) = 1) where graduate_date < to_date('2018-06-28 13:14:15', 'yyyy-mm-dd hh24:mi:ss:ff') order by highest_degree desc; +end; +/ +select p_s_condition_0011_1(); + p_s_condition_0011_1 +---------------------- + +(1 row) + +create or replace procedure t_ustore_Proc_temp_table_0008(v_name varchar2) as +v_num int; +begin +execute immediate 'drop table if exists t_ustore_Proc_temp_table_'||v_name; +execute immediate 'create local temporary table t_ustore_Proc_temp_table_'||v_name||'(id int,name varchar2(200)) with (storage_type=ustore)'; +end; +/ +declare +v_name varchar2:= '0008'; +begin +t_ustore_Proc_temp_table_0008(v_name); +end; +/ +NOTICE: table "t_ustore_proc_temp_table_0008" does not exist, skipping +CONTEXT: SQL statement "drop table if exists t_ustore_Proc_temp_table_0008" +PL/pgSQL function t_ustore_proc_temp_table_0008(character varying) line 4 at EXECUTE statement +SQL statement "CALL t_ustore_proc_temp_table_0008(v_name)" +PL/pgSQL function inline_code_block line 4 at PERFORM diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index f99a456b97d881f99cd074cd57c45df6fe1f0cc5..72217506c203939d05a6e0bb825c2e400e1ca94b 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -275,7 +275,7 @@ test: single_node_produce_commit_rollback test: single_node_function_commit_rollback test: instr_unique_sql -test: auto_explain +test: auto_explain plan_table_for_anonymous_block test: shutdown # List/Hash table exchange @@ -1048,4 +1048,3 @@ test: show_warnings test: partition_expr_key test: alter_foreign_schema - diff --git a/src/test/regress/sql/plan_table_for_anonymous_block.sql b/src/test/regress/sql/plan_table_for_anonymous_block.sql new file mode 100644 index 0000000000000000000000000000000000000000..f77ac6261210155ea3e07151c7adb3068b7838f5 --- /dev/null +++ b/src/test/regress/sql/plan_table_for_anonymous_block.sql @@ -0,0 +1,48 @@ +drop table if exists t_s_condition_0011_1 cascade; +drop table if exists t_s_condition_0011_2; +create table t_s_condition_0011_2(id int) with (storage_type=ustore); +insert into t_s_condition_0011_2 values(1); + +create table t_s_condition_0011_1(staff_id int not null, highest_degree char(8), graduate_school varchar(64), graduate_date smalldatetime, t_education_note varchar(70)) with (storage_type=ustore); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(10,'博士','西安电子科技大学','2017-07-06 12:00:00','211'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(11,'博士','西北农林科技大学','2017-07-06 12:00:00','211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(12,'硕士','西北工业大学','2017-07-06 12:00:00','211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(15,'学士','西安建筑科技大学','2017-07-06 12:00:00','非211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(18,'硕士','西安理工大学','2017-07-06 12:00:00','非211和985'); +insert into t_s_condition_0011_1(staff_id,highest_degree,graduate_school,graduate_date,t_education_note) values(20,'学士','北京师范大学','2017-07-06 12:00:00','211和985'); + +create or replace function f_s_condition_0011(a int) return int +as +c int; +d int; +begin +c := a; +select id into d from t_s_condition_0011_2 where rownum = c; +return d; +end ; +/ + +drop procedure if exists p_s_condition_0011_1; +create or replace procedure p_s_condition_0011_1 +as +begin +explain plan for select * from (select highest_degree,graduate_date from t_s_condition_0011_2 right join t_s_condition_0011_1 on staff_id = id where f_s_condition_0011(1) = 1) where graduate_date < to_date('2018-06-28 13:14:15', 'yyyy-mm-dd hh24:mi:ss:ff') order by highest_degree asc; +explain plan for select * from (select highest_degree,graduate_date from t_s_condition_0011_2 right join t_s_condition_0011_1 on staff_id = id where f_s_condition_0011(1) = 1) where graduate_date < to_date('2018-06-28 13:14:15', 'yyyy-mm-dd hh24:mi:ss:ff') order by highest_degree desc; +end; +/ +select p_s_condition_0011_1(); + +create or replace procedure t_ustore_Proc_temp_table_0008(v_name varchar2) as +v_num int; +begin +execute immediate 'drop table if exists t_ustore_Proc_temp_table_'||v_name; +execute immediate 'create local temporary table t_ustore_Proc_temp_table_'||v_name||'(id int,name varchar2(200)) with (storage_type=ustore)'; +end; +/ + +declare +v_name varchar2:= '0008'; +begin +t_ustore_Proc_temp_table_0008(v_name); +end; +/