diff --git a/src/common/backend/utils/adt/arrayfuncs.cpp b/src/common/backend/utils/adt/arrayfuncs.cpp index 50760746960818671b8e411e072ae17f11a9267e..6e6ceb3cd03c335c686903761b10a463c7657c41 100644 --- a/src/common/backend/utils/adt/arrayfuncs.cpp +++ b/src/common/backend/utils/adt/arrayfuncs.cpp @@ -1787,7 +1787,8 @@ Datum array_varchar_exists(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_exists must be call in procedure"))); } @@ -1821,7 +1822,8 @@ Datum array_integer_exists(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_exists must be call in procedure"))); } @@ -1966,7 +1968,8 @@ Datum array_varchar_next(PG_FUNCTION_ARGS) int index = 0; Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_next must be call in procedure"))); } @@ -2016,7 +2019,8 @@ Datum array_varchar_prior(PG_FUNCTION_ARGS) int index = 0; Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_prior must be call in procedure"))); } @@ -2061,7 +2065,8 @@ Datum array_varchar_first(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_first must be call in procedure"))); } @@ -2108,7 +2113,8 @@ Datum array_integer_next(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_next must be call in procedure"))); } @@ -2165,7 +2171,8 @@ Datum array_integer_prior(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_prior must be call in procedure"))); } @@ -2218,7 +2225,8 @@ Datum array_integer_first(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_first must be call in procedure"))); } @@ -2262,7 +2270,8 @@ Datum array_integer_last(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_last must be call in procedure"))); } @@ -2287,7 +2296,8 @@ Datum array_varchar_last(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_last must be call in procedure"))); } @@ -2343,7 +2353,8 @@ Datum array_integer_deleteidx(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_deleteidx must be call in procedure"))); } @@ -2368,7 +2379,8 @@ Datum array_varchar_deleteidx(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_deleteidx must be call in procedure"))); } @@ -2575,7 +2587,8 @@ Datum array_indexby_delete(PG_FUNCTION_ARGS) checkEnv(); ArrayType* v = PG_GETARG_ARRAYTYPE_P(0); ArrayType* array = construct_empty_array(ARR_ELEMTYPE(v)); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_indexby_delete must be call in procedure"))); } diff --git a/src/common/backend/utils/cache/relcache.cpp b/src/common/backend/utils/cache/relcache.cpp index 14eab549ed99afc0183296b0c887f45b3839c128..28c7e56f9787747f00262e797ec4783cb8f75a6a 100755 --- a/src/common/backend/utils/cache/relcache.cpp +++ b/src/common/backend/utils/cache/relcache.cpp @@ -5020,7 +5020,7 @@ RelFileNodeBackend CreateNewRelfilenodePart(Relation parent, Partition part) part->newcbi = true; } - partition_create_new_storage(parent, part, newrnode); + partition_create_new_storage(parent, part, newrnode, true); return newrnode; } diff --git a/src/gausskernel/storage/smgr/smgr.cpp b/src/gausskernel/storage/smgr/smgr.cpp index e4b3fba1de67e83258e160e2be5956b575263210..f4b4c60b3c14e519ae25c35b4ff940b147b23a2d 100755 --- a/src/gausskernel/storage/smgr/smgr.cpp +++ b/src/gausskernel/storage/smgr/smgr.cpp @@ -878,7 +878,8 @@ void smgrmovebuckets(SMgrRelation reln1, SMgrRelation reln2, List *bList) (*(smgrsw[reln1->smgr_which].smgr_move_buckets))(reln1->smgr_rnode, reln2->smgr_rnode, bList); } -void partition_create_new_storage(Relation rel, Partition part, const RelFileNodeBackend &filenode) +void partition_create_new_storage(Relation rel, Partition part, const RelFileNodeBackend &filenode, + bool keep_old_relfilenode) { if (RelationIsCrossBucketIndex(rel) || IsCreatingCrossBucketIndex(part)) { RelationData dummyrel; @@ -894,8 +895,7 @@ void partition_create_new_storage(Relation rel, Partition part, const RelFileNod /* * Schedule unlinking of the old storage at transaction commit. */ - if (!u_sess->attr.attr_storage.enable_recyclebin || - !RelationIsTableAccessMethodUStoreType(rel->rd_options)) { + if (!keep_old_relfilenode) { PartitionDropStorage(rel, part); } } diff --git a/src/include/storage/smgr/smgr.h b/src/include/storage/smgr/smgr.h index e7ace5e4e88931e90ca66374bc7d6b7a5cbdd8aa..9a68cb4be44c4099005d7d5819e1d6bec44b38db 100644 --- a/src/include/storage/smgr/smgr.h +++ b/src/include/storage/smgr/smgr.h @@ -245,7 +245,8 @@ extern Datum smgrin(PG_FUNCTION_ARGS); extern Datum smgreq(PG_FUNCTION_ARGS); extern Datum smgrne(PG_FUNCTION_ARGS); -extern void partition_create_new_storage(Relation rel, Partition part, const RelFileNodeBackend& filenode); +extern void partition_create_new_storage(Relation rel, Partition part, const RelFileNodeBackend& filenode, + bool keep_old_relfilenode = false); extern ScalarToDatum GetTransferFuncByTypeOid(Oid attTypeOid); extern bool check_unlink_rel_hashtbl(RelFileNode rnode, ForkNumber forknum); diff --git a/src/test/regress/expected/arrayinterface_indexby.out b/src/test/regress/expected/arrayinterface_indexby.out index bb4f290f88727771264c20035dcb4bb15af06869..9983004f2c6cc160abc221e47509a622b262d585 100644 --- a/src/test/regress/expected/arrayinterface_indexby.out +++ b/src/test/regress/expected/arrayinterface_indexby.out @@ -11,6 +11,10 @@ drop schema if exists plpgsql_array_interface_indexby; NOTICE: schema "plpgsql_array_interface_indexby" does not exist, skipping create schema plpgsql_array_interface_indexby; set current_schema = plpgsql_array_interface_indexby; +-- must be call in procedure -- +select array_indexby_delete(array[1, 2]); +ERROR: array_indexby_delete must be call in procedure +CONTEXT: referenced column: array_indexby_delete -- test array interface count -- create or replace procedure array_interface_p1() as declare diff --git a/src/test/regress/expected/arrayinterface_single.out b/src/test/regress/expected/arrayinterface_single.out index f06112f97f1d3865c09525bfbe14d81eab6330b2..f7954f60b7701616c82606d4864288ca46766681 100644 --- a/src/test/regress/expected/arrayinterface_single.out +++ b/src/test/regress/expected/arrayinterface_single.out @@ -11,6 +11,43 @@ drop schema if exists plpgsql_array_interface; NOTICE: schema "plpgsql_array_interface" does not exist, skipping create schema plpgsql_array_interface; set current_schema = plpgsql_array_interface; +-- must be call in procedure -- +select array_varchar_exists(array['1', '2'], '3'); +ERROR: array_varchar_exists must be call in procedure +CONTEXT: referenced column: array_varchar_exists +select array_varchar_next(array['1','2'], '3'); +ERROR: array_varchar_next must be call in procedure +CONTEXT: referenced column: array_varchar_next +select array_varchar_prior(array['1','2'], '3'); +ERROR: array_varchar_prior must be call in procedure +CONTEXT: referenced column: array_varchar_prior +select array_varchar_first(array['1','2']); +ERROR: array_varchar_first must be call in procedure +CONTEXT: referenced column: array_varchar_first +select array_varchar_last(array['1','2']); +ERROR: array_varchar_last must be call in procedure +CONTEXT: referenced column: array_varchar_last +select array_varchar_deleteidx(array['1','2'], '3'); +ERROR: array_varchar_deleteidx must be call in procedure +CONTEXT: referenced column: array_varchar_deleteidx +select array_integer_exists(array[1, 2], 3); +ERROR: array_integer_exists must be call in procedure +CONTEXT: referenced column: array_integer_exists +select array_integer_next(array[1, 2], 3); +ERROR: array_integer_next must be call in procedure +CONTEXT: referenced column: array_integer_next +select array_integer_prior(array[1, 2], 3); +ERROR: array_integer_prior must be call in procedure +CONTEXT: referenced column: array_integer_prior +select array_integer_first(array[1, 2]); +ERROR: array_integer_first must be call in procedure +CONTEXT: referenced column: array_integer_first +select array_integer_last(array[1, 2]); +ERROR: array_integer_last must be call in procedure +CONTEXT: referenced column: array_integer_last +select array_integer_deleteidx(array[1, 2], 3); +ERROR: array_integer_deleteidx must be call in procedure +CONTEXT: referenced column: array_integer_deleteidx -- test array interface count -- create or replace procedure array_interface_p1() as diff --git a/src/test/regress/sql/arrayinterface_indexby.sql b/src/test/regress/sql/arrayinterface_indexby.sql index f347aeae021d3c167f17dd3f006fed17c59920f7..b0c96121fa9e96c0997a60dc4695f500af226122 100644 --- a/src/test/regress/sql/arrayinterface_indexby.sql +++ b/src/test/regress/sql/arrayinterface_indexby.sql @@ -8,6 +8,10 @@ drop schema if exists plpgsql_array_interface_indexby; create schema plpgsql_array_interface_indexby; set current_schema = plpgsql_array_interface_indexby; +-- must be call in procedure -- +select array_indexby_delete(array[1, 2]); + + -- test array interface count -- create or replace procedure array_interface_p1() as declare diff --git a/src/test/regress/sql/arrayinterface_single.sql b/src/test/regress/sql/arrayinterface_single.sql index efa5a0468069c7112d0118f1a96966354778e2da..6ddb967f4725e6a22aa5915f827b33edcc038e29 100644 --- a/src/test/regress/sql/arrayinterface_single.sql +++ b/src/test/regress/sql/arrayinterface_single.sql @@ -8,6 +8,22 @@ drop schema if exists plpgsql_array_interface; create schema plpgsql_array_interface; set current_schema = plpgsql_array_interface; +-- must be call in procedure -- +select array_varchar_exists(array['1', '2'], '3'); +select array_varchar_next(array['1','2'], '3'); +select array_varchar_prior(array['1','2'], '3'); +select array_varchar_first(array['1','2']); +select array_varchar_last(array['1','2']); +select array_varchar_deleteidx(array['1','2'], '3'); + +select array_integer_exists(array[1, 2], 3); +select array_integer_next(array[1, 2], 3); +select array_integer_prior(array[1, 2], 3); +select array_integer_first(array[1, 2]); +select array_integer_last(array[1, 2]); +select array_integer_deleteidx(array[1, 2], 3); + + -- test array interface count -- create or replace procedure array_interface_p1() as