From 2beff64895e0b291e9fa30fa72d02c9ae97c9d1a Mon Sep 17 00:00:00 2001 From: gentle_hu Date: Tue, 20 Jun 2023 17:56:29 +0800 Subject: [PATCH 1/2] fix bug about recyclebin and truncate partation table --- src/common/backend/utils/cache/relcache.cpp | 2 +- src/gausskernel/storage/smgr/smgr.cpp | 6 +++--- src/include/storage/smgr/smgr.h | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/backend/utils/cache/relcache.cpp b/src/common/backend/utils/cache/relcache.cpp index 14eab549ed..28c7e56f97 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 e4b3fba1de..f4b4c60b3c 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 e7ace5e4e8..9a68cb4be4 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); -- Gitee From a2cc3692fea674c5dfc122c7ee486d9be5b67a33 Mon Sep 17 00:00:00 2001 From: gentle_hu Date: Wed, 21 Jun 2023 09:27:34 +0800 Subject: [PATCH 2/2] fix core in some array functions --- src/common/backend/utils/adt/arrayfuncs.cpp | 39 ++++++++++++------- .../expected/arrayinterface_indexby.out | 4 ++ .../expected/arrayinterface_single.out | 37 ++++++++++++++++++ .../regress/sql/arrayinterface_indexby.sql | 4 ++ .../regress/sql/arrayinterface_single.sql | 16 ++++++++ 5 files changed, 87 insertions(+), 13 deletions(-) diff --git a/src/common/backend/utils/adt/arrayfuncs.cpp b/src/common/backend/utils/adt/arrayfuncs.cpp index 5076074696..6e6ceb3cd0 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/test/regress/expected/arrayinterface_indexby.out b/src/test/regress/expected/arrayinterface_indexby.out index bb4f290f88..9983004f2c 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 f06112f97f..f7954f60b7 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 f347aeae02..b0c96121fa 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 efa5a04680..6ddb967f47 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 -- Gitee