!4353 处理enable_segment参数放开后相关动作调整

Merge pull request !4353 from Lamaric/issue-I8B6BJ
This commit is contained in:
opengauss_bot
2023-11-29 10:55:13 +00:00
committed by Gitee
8 changed files with 180 additions and 2 deletions

View File

@ -998,7 +998,7 @@ static void InitStorageConfigureNamesBool()
PGC_SIGHUP,
NODE_ALL,
UNGROUPED,
gettext_noop("create segment table, only used in debug mode"),
gettext_noop("create segment table."),
NULL},
&u_sess->attr.attr_storage.enable_segment,
false,

View File

@ -2865,8 +2865,12 @@ ObjectAddress DefineRelation(CreateStmt* stmt, char relkind, Oid ownerId, Object
if (!IsInitdb && (relkind == RELKIND_RELATION) && !IsSystemNamespace(namespaceId) &&
!IsCStoreNamespace(namespaceId) && (pg_strcasecmp(storeChar, ORIENTATION_ROW) == 0) &&
(stmt->relation->relpersistence == RELPERSISTENCE_PERMANENT) && !u_sess->attr.attr_storage.enable_recyclebin) {
if (u_sess->attr.attr_storage.enable_segment || bucketinfo != NULL) {
bool isSegmentType = (storage_type == SEGMENT_PAGE);
if (!isSegmentType && (u_sess->attr.attr_storage.enable_segment || bucketinfo != NULL)) {
storage_type = SEGMENT_PAGE;
DefElem *storage_def = makeDefElem("segment", (Node *)makeString("on"));
stmt->options = lappend(stmt->options, storage_def);
reloptions = transformRelOptions((Datum)0, stmt->options, NULL, validnsps, true, false);
}
} else if (storage_type == SEGMENT_PAGE) {
if (u_sess->attr.attr_storage.enable_recyclebin) {
@ -2909,6 +2913,12 @@ ObjectAddress DefineRelation(CreateStmt* stmt, char relkind, Oid ownerId, Object
}
}
if (!IsInitdb && u_sess->attr.attr_storage.enable_segment && storage_type == SEGMENT_PAGE &&
!CheckSegmentStorageOption(stmt->options)) {
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("Only support segment storage type while parameter enable_segment is ON.")));
}
/*
* Create the relation. Inherited defaults and constraints are passed in
* for immediate handling --- since they don't need parsing, they can be

View File

@ -3109,6 +3109,34 @@ void CheckCompressOption(TableCreateSupport *tableCreateSupport)
}
}
bool CheckSegmentStorageOption(List *options)
{
if (options == NULL) {
return true;
}
ListCell *opt = NULL;
bool result = true;
foreach (opt, options) {
DefElem *def = (DefElem *)lfirst(opt);
if (pg_strcasecmp(def->defname, "segment") == 0) {
/*
* def->arg is NULL, that means it's a RESET action. ignore it.
* def->arg is not NULL, that means it's a SET action, so check it.
*/
if (def->arg) {
const char *valstr = defGetString(def);
if (pg_strcasecmp(valstr, "off") == 0)
result = false;
}
break;
}
}
return result;
}
#ifdef USE_SPQ
/*
* before check spq reloption, make sure guc params of spq_enable_btbuild is on

View File

@ -307,5 +307,6 @@ void ForbidUserToSetCompressedOptions(List *options);
void SetOneOfCompressOption(DefElem* defElem, TableCreateSupport *tableCreateSupport);
bool ReadBoolFromDefElem(DefElem* defElem);
void CheckCompressOption(TableCreateSupport *tableCreateSupport);
bool CheckSegmentStorageOption(List *options);
#endif /* RELOPTIONS_H */

View File

@ -0,0 +1,106 @@
-- modify enble_segment parameter
drop table if exists tab_segment;
NOTICE: table "tab_segment" does not exist, skipping
drop table if exists tab_segment_off;
NOTICE: table "tab_segment_off" does not exist, skipping
drop table if exists tab_segment_on;
NOTICE: table "tab_segment_on" does not exist, skipping
show enable_segment;
enable_segment
----------------
off
(1 row)
alter system set enable_segment = on;
select pg_sleep(1);
pg_sleep
----------
(1 row)
show enable_segment;
enable_segment
----------------
on
(1 row)
create table tab_segment(a int);
create table tab_segment_off(a int) with(segment=off);
ERROR: Only support segment storage type while parameter enable_segment is ON.
create table tab_segment_on(a int) with(segment=on);
\d+ tab_segment;
Table "public.tab_segment"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
Has OIDs: no
Options: orientation=row, compression=no, segment=on
\d+ tab_segment_off;
\d+ tab_segment_on;
Table "public.tab_segment_on"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
Has OIDs: no
Options: orientation=row, segment=on, compression=no
drop table tab_segment;
drop table if exists tab_segment_off;
NOTICE: table "tab_segment_off" does not exist, skipping
drop table if exists tab_segment_on;
select pg_sleep(1);
pg_sleep
----------
(1 row)
show enable_segment;
enable_segment
----------------
on
(1 row)
alter system set enable_segment = off;
select pg_sleep(1);
pg_sleep
----------
(1 row)
show enable_segment;
enable_segment
----------------
off
(1 row)
create table tab_segment(a int);
create table tab_segment_off(a int) with(segment=off);
create table tab_segment_on(a int) with(segment=on);
\d+ tab_segment;
Table "public.tab_segment"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
Has OIDs: no
Options: orientation=row, compression=no
\d+ tab_segment_off;
Table "public.tab_segment_off"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
Has OIDs: no
Options: orientation=row, segment=off, compression=no
\d+ tab_segment_on;
Table "public.tab_segment_on"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
Has OIDs: no
Options: orientation=row, segment=on, compression=no
drop table tab_segment;
drop table if exists tab_segment_off;
drop table if exists tab_segment_on;

View File

@ -408,6 +408,7 @@ test: partiton_pathkey_col_plan partiton_pathkey_col_randomexec partiton_pathkey
#test: create_function_1
test: create_table create_table_2 create_table_3
test: temp__4
test: create_seg_table
#test: copy#

View File

@ -400,6 +400,7 @@ test: partiton_pathkey_col_plan partiton_pathkey_col_randomexec partiton_pathkey
#test: create_function_1
test: create_table create_table_2 create_table_3
test: temp__4
test: create_seg_table
#test: copy#

View File

@ -0,0 +1,31 @@
-- modify enble_segment parameter
drop table if exists tab_segment;
drop table if exists tab_segment_off;
drop table if exists tab_segment_on;
show enable_segment;
alter system set enable_segment = on;
select pg_sleep(1);
show enable_segment;
create table tab_segment(a int);
create table tab_segment_off(a int) with(segment=off);
create table tab_segment_on(a int) with(segment=on);
\d+ tab_segment;
\d+ tab_segment_off;
\d+ tab_segment_on;
drop table tab_segment;
drop table if exists tab_segment_off;
drop table if exists tab_segment_on;
select pg_sleep(1);
show enable_segment;
alter system set enable_segment = off;
select pg_sleep(1);
show enable_segment;
create table tab_segment(a int);
create table tab_segment_off(a int) with(segment=off);
create table tab_segment_on(a int) with(segment=on);
\d+ tab_segment;
\d+ tab_segment_off;
\d+ tab_segment_on;
drop table tab_segment;
drop table if exists tab_segment_off;
drop table if exists tab_segment_on;