想找openGauss的参考信息,看这个就够了(526)

165 阅读12分钟

#openGauss #入门 #安装 #数据库 #开源

知识来源:docs-opengauss.osinfra.cn/zh/

behavior_compat_options

参数说明: 数据库兼容性行为配置项,该参数的值由若干个配置项用逗号隔开构成。

该参数属于USERSET类型参数,请参考表1中对应设置方法进行设置。

取值范围: 字符串

默认值: 空

说明:

  • 当前只支持表2 兼容性配置项

  • 配置多个兼容性配置项时,相邻配置项用逗号隔开,例如:set behavior_compat_options='end_month_calculate,display_leading_zero';

表 2 兼容性配置项

兼容性配置项

兼容性行为控制

display_leading_zero

浮点数显示配置项。控制数值类型中浮点类型、任意精度类型的小数点前零显示。并且length计算数字长度同步显示。

  • 不设置此配置项时,对于-10和01之间的小数,不显示小数点前的0。比如:

    openGauss=# select 0.1231243 as a, 0.1231243::numeric as b,0.1231243::integer(10,3) as c, length(0.1242343) as d;
        a     |    b     |  c   | d
    ----------+----------+------+---
     .1231243 | .1231243 | .123 | 8
    (1 row)
    
  • 设置此配置项时,对于-10和01之间的小数,显示小数点前的0。比如:

    openGauss=# select 0.1231243 as a, 0.1231243::numeric as b,0.1231243::integer(10,3) as c, length(0.1242343) as d;
         a     |     b     |   c   | d
    -----------+-----------+-------+---
     0.1231243 | 0.1231243 | 0.123 | 9
    (1 row)
    

end_month_calculate

add_months函数计算逻辑配置项。

假定函数add_months的两个参数分别为param1和param2,param1的月份和param2的和为月份result。

  • 不设置此配置项时,如果param1的日期(Day字段)为月末,并且param1的日期(Day字段)比result月份的月末日期小,计算结果中的日期字段(Day字段)和param1的日期字段保持一致。比如,

    openGauss=# select add_months('2018-02-28',3) from sys_dummy; add_months ---------------------
    2018-05-28 00:00:00 (1 row)

  • 设置此配置项时,如果param1的日期(Day字段)为月末,并且param1的日期(Day字段)比result月份的月末日期比小,计算结果中的日期字段(Day字段)和result的月末日期保持一致。比如,

    openGauss=# select add_months('2018-02-28',3) from sys_dummy; add_months ---------------------
    2018-05-31 00:00:00 (1 row)

compat_analyze_sample

analyze采样行为配置项。

设置此配置项时,会优化analyze的采样行为,主要体现在analyze时全局采样会更精确的控制在3万条左右,更好的控制analyze时DBnode端的内存消耗,保证analyze性能的稳定性。

bind_schema_tablespace

绑定模式与同名表空间配置项。

如果存在与模式名sche_name相同的表空间名,那么如果设置search_path为sche_name, default_tablespace也会同步切换到sche_name。

bind_procedure_searchpath

未指定模式名的数据库对象的搜索路径配置项。

在存储过程中如果不显示指定模式名,会优先在存储过程所属的模式下搜索。

如果找不到,则有两种情况:

  • 若不设置此参数,报错退出。
  • 若设置此参数,按照search_path中指定的顺序继续搜索。如果还是找不到,报错退出。

correct_to_number

控制to_number()结果兼容性的配置项。

若设置此配置项,则to_number()函数结果与pg11保持一致,否则默认与O db保持一致。

unbind_divide_bound

控制对整数除法的结果进行范围校验。

若设置此配置项,则不需要对除法结果做范围校验,例如,INT_MIN/(-1)可以得到输出结果为INT_MAX+1,反之,则会因为超过结果大于INT_MAX而报越界错误。

return_null_string

控制函数lpad()和rpad()结果为空字符串''的显示配置项。

  • 不设置此配置项时,空字符串显示为NULL。

    postgres=# select length(lpad('123',0,'*')) from sys_dummy; length --------
    (1 row)

  • 设置此配置项时,空字符串显示为''。

    postgres=# select length(lpad('123',0,'*')) from sys_dummy; length --------
    0 (1 row)

compat_concat_variadic

控制函数concat()和concat_ws()对variadic类型结果兼容性的配置项。

若设置此配置项,当concat函数参数为variadic类型时,保留a db和Teradata兼容模式下不同的结果形式;否则默认a db和Teradata兼容模式下结果相同,且与a db保持一致。由于MY无variadic类型,所以该选项对MY无影响。

merge_update_multi

控制在使用MERGE INTO ... WHEN MATCHED THEN UPDATE(参考MERGE INTO)和INSERT ... ON DUPLICATE KEY UPDATE(参考INSERT)时,当目标表中一条目标数据与多条源数据冲突时UPDATE行为。

若设置此配置项,当存在上述场景时,该冲突行将会多次执行UPDATE;否则(默认)报错,即MERGE或INSERT操作失败。

plstmt_implicit_savepoint

控制存储过程中更新语句的执行是否拥有独立的子事务。

若设置此配置项,存储过程中每条更新语句前开启隐式保存点,EXCEPTION块中默认回退到最近的保存点,从而保证只回退失败语句的修改。该选项是为了兼容O数据库的EXCEPTION行为。

hide_tailing_zero

numeric显示配置项。不设置此项时,numeric按照指定精度显示。设置此项时,所有输出numeric的场景均隐藏小数点后的末尾0,包括显示指定format精度情况。

openGauss=# set behavior_compat_options='hide_tailing_zero';
openGauss=# select cast(123.123 as numeric(15,10)) as a, to_char(cast(123.123 as numeric(15,10)), '999D999999');
    a    | to_char
---------+----------
 123.123 |  123.123
(1 row)
openGauss=# set behavior_compat_options='';
openGauss=# select cast(123.123 as numeric(15,10)) as a, to_char(cast(123.123 as numeric(15,10)), '999D999999');
       a        |   to_char
----------------+-------------
 123.1230000000 |  123.123000
(1 row)

rownum_type_compat

控制ROWNUM的类型,ROWNUM默认类型为INT8,设置此参数后,ROWNUM类型变更为NUMERIC类型。

aformat_null_test

控制rowtype类型判空逻辑,设置此项时,对于rowtype is not null判断,当一行数据有一列不为空的时候返回ture。

否则,对于rowtype is not null判断,当一行数据所有列不为空的时候返回ture.

aformat_regexp_match

控制正则表达式函数的匹配行为。

设置此项,且sql_compatibility参数的值为A或B时,正则表达式的 flags 参数支持的选项含义有变更:

  1. . 默认不能匹配 '\n' 字符。
  2. flags 中包含n选项时, . 能够匹配 '\n' 字符。
  3. regexp_replace(source, pattern replacement) 函数替换所有匹配的子串。
  4. regexp_replace(source, pattern, replacement, flags) 在 flags值为'' 或者null时,返回值为null。

否则,正则表达式的 flags 参数支持的选项含义:

  1. . 默认能匹配 '\n' 字符。
  2. flags 中的 n 选项表示按照多行模式匹配。
  3. regexp_replace(source, pattern replacement) 函数仅替换第一个匹配到的子串。
  4. regexp_replace(source, pattern, replacement, flags) 在 flags值为'' 或者null时,返回值为替换后的字符串。

compat_cursor

控制隐式游标状态兼容行为。设置此项,且兼容O,隐式游标状态(SQL%FOUND、SQL%NOTFOUND、SQL%ISOPNE、SQL%ROWCOUNT)由原先的仅在当前执行的函数有效,拓展到包括本函数调用的子函数有效。

proc_outparam_override

控制存储过程出参的重载行为,打开该参数后,对于存储过程只有out出参部分不同的情况下,也可以正常调用。

proc_implicit_for_loop_variable

控制存储过程中FOR_LOOP查询语句行为设置此项时,在FOR rec IN query LOOP语句中,若rec已经定义,不会复用已经定义的rec变量,而且重新建立一个新的变量。否则,会复用已经定义的rec变量,不会建立新的变量。

allow_procedure_compile_check

控制存储过程中select语句和open cursor语句的编译检查设置此项时,在存储过程中执行select语句、open cursor for语句、cursor%rowtype语句、for rec in语句时,若查询的表不存在,则无法创建创建存储过程,不支持trigger函数的编译检查,若查询的表存在,则成功创建存储过程。

char_coerce_compat

控制char(n)类型向其它变长字符串类型转换时的行为,以及char(n)和varchar操作时的行为。默认情况下char(n)类型转换其它变长字符串类型时会省略尾部的空格,开启该参数后,转换时不再省略尾部的空格,并且在转换时如果char(n)类型的长度超过其它变长字符串类型时将会报错;开启该参数后,char(n)和varchar操作时,例如比较操作符,首先各自转换为text类型再进行操作,具体表现为在操作时不会忽略尾部空格,如' '::char(5)和' '::varchar(5)不相等。该参数仅在sql_compatibility参数的值为A时生效。

truncate_numeric_tail_zero

numeric显示配置项。不设置此项时,numeric按照默认精度显示。设置此项时,除去to_char(numeric, format)这种显示设置精度的情况,所有输出numeric的场景均会隐藏小数点后的末尾0。例如:

openGauss=# set behavior_compat_options='truncate_numeric_tail_zero';
openGauss=# select cast(123.123 as numeric(15,10)) as a, to_char(cast(123.123 as numeric(15,10)), '999D999999');
    a    |   to_char
---------+-------------
 123.123 |  123.123000
(1 row)
openGauss=# set behavior_compat_options='';
openGauss=# select cast(123.123 as numeric(15,10)) as a, to_char(cast(123.123 as numeric(15,10)), '999D999999');
       a        |   to_char
----------------+-------------
 123.1230000000 |  123.123000
(1 row)

pgformat_substr

控制substr(str, from, for)在不同场景下的表现。默认情况下,当from小于0时,substr将从字符串尾部开始计数;当for小于1时,substr将返回NULL。开启该参数后,当from小于0时,将从字符串的第一位的前(-from + 1)位开始计数;当for小于0时,substr将报错。该参数仅在sql_compatibility参数的值为PG时生效。

plpgsql_dependency

开启此参数后,创建函数,存储过程,包支持未定义的对象。可以新建成功。可以在GS_DEPENDENCIES和GS_DEPENDENCIES_OBJ查询对应的依赖关系。

开启此参数后,创建PLSQL对象时,会主动维护依赖于该PLSQL对象的OID,不再需要用户手动更新。

注意: 1.在并发创建PLSQL对象时,如果需要维护的对象间存在竞争关系,可能会造成死锁。 2.在调用失效的PLSQL对象时,自动执行一个自治事务对PLSQL对象重编译,重编译有效时会修改pg_object表的valid字段为true,回滚调用PLSQL对象的事务不会回滚自治事务中的重编译语句,包括对pg_object表的valid字段的修改。 3.当修改对象在gs_dependencies和gs_dependencies_obj中存在时,不允许进行rename操作。

allow_orderby_undistinct_column

SQL语法兼容B的情况下,开启此参数后,select语句支持order by后面的列不在distinct中。如: select distinct a from test order by b;

注意:该参数只支持distinct,不支持distinct on,且当 DOLPHIN 插件存在时不生效,转由 dolphin.sql_mode 参数控制。dolphin.sql_mode 未设置 sql_mode_full_group 选项时相当于打开此选项。

select_into_return_null

在B或PG兼容模式下,开启此参数后,存储过程语句SELECT select_expressions INTO [STRICT] target FROM ... 允许在不指定STRICT并且查询结果为空时给变量赋NULL值。

accept_empty_str

在A兼容模式下,关闭此参数后,openGauss处理空字符串时会当做NULL处理;反之则正常接受空字符串。例如:

openGauss=# set behavior_compat_options='accept_empty_str';
openGauss=# select '' is null;
 ?column? 
----------
 f
(1 row)
openGauss=# set behavior_compat_options='';
openGauss=# select '' is null;
 ?column? 
----------
 t
(1 row)

proc_uncheck_default_param

此参数打开时,调用带有默认参数的函数,入参从左到右排入函数,且允许缺省默认参数个数个入参,如果存在非默认参数的入参缺失,则会用错位的默认值填充缺失参数;参数关闭时,调用函数报错。

convert_string_digit_to_numeric

控制是否将表中以字符串形式表示的numeric常量和数字类型作比较时统一都转换为numeric类型再进行比较。

openGauss=# create table test1(c1 int, c2 varchar);
openGauss=# insert into test1 values(2, '1.1');
openGauss=# set behavior_compat_options = '';
openGauss=# select * from test1 where c2 > 1;
ERROR:  invalid input syntax for type bigint: "1.1"
openGauss=# set behavior_compat_options = 'convert_string_digit_to_numeric';
openGauss=# select * test1 from where c2 > 1;
 c1 | c2  
----+-----
  2 | 1.1
(1 row)

plsql_security_definer

开启此参数后,创建存储过程时默认为定义者权限。

skip_insert_gs_source

开启此参数后,创建PL/SQL对象时不再插入DBE_PLDEVELOPER.gs_source表中。

update_unusable_unique_index_on_iud

开启此参数后,在数据insert、update、delete时候会同时对unusable unique索引的数据也进行更新,非unique索引不受影响。此参数默认关闭,关闭后如果有重复数据inser或者update到unique index列,rebuild unique index的时候会失败。

prefer_parse_cursor_parentheses_as_expr

默认情况下openGuass只会把cursor(select xxx)和cursor(with xxx)两种场景的查询语句当成游标表达式执行,其他场景当成cursor function执行。如果开启此参数且系统中没注册cursor function,openGuass将所有的cursor()都当成表达式执行。比如cursor((select xxx))默认情况下会当成cursor function执行,打开其参数后将当成cursor表达式执行

update_global_index_on_partition_change

此参数关闭时,分区变更(比如drop、merge、split、truncate分区等操作)时不会对全局索引进行数据更新而是将全局索引设置为UNUSABLE状态。打开此开关时,在分区变更时自动对全局索引进行数据更新操作,因此也会导致执行DDL时间变长和阻塞其他DML并发执行。默认此开关为关闭状态。

prior_function_first

控制是否将prior(arg)当做函数进行使用。

openGauss=# create table t1(father int, son int);
CREATE TABLE
openGauss=# insert into t1 values(0,1),(1, 2), (2, 3);
INSERT 0 3
openGauss=# create or replace function prior(id int) returns int
openGauss-#         LANGUAGE plpgsql AS $$
openGauss$#         begin
openGauss$#         raise info 'invoke prior function';
openGauss$#         return id*3;
openGauss$#         end;
openGauss$#         $$;
CREATE FUNCTION
openGauss=# select prior son as father, son from t1 where prior(son) = 6 start with son = 1 connect by prior son = father;
 father | son
--------+-----
(0 rows)
openGauss=# set behavior_compat_options = 'prior_function_first';
SET
openGauss=# select prior son as father, son from t1 where prior(son) = 6 start with son = 1 connect by prior son = father;
INFO:  invoke prior function
INFO:  invoke prior function
INFO:  invoke prior function
father | son
——--+—--
1 |   2
(1 row)

float_as_numeric

在A兼容模式下,开启此参数后,FLOAT[(p)]映射至numeric,此时精度p为二进制精度,p取值范围为[1,126]。

disable_record_type_in_dml

禁止虚拟列插入配置项。开启此项后禁止在insert语句中使用record类型变量作为插入值。

create table t1(col1 varchar(10),col varchar(10));
create table t2(col1 varchar(10),col varchar(10));
set behavior_compat_options='disable_record_type_in_dml';
insert into t1 values('one','two');
declare
  cursor cur1 is select * from t1;
  source cur1%rowtype:=('ten','wtu');
begin
  for source in cur1
  loop
    raise notice '%',source;
    insert into t2 values(source);
  end loop; 
end;
/
ERROR:  The record type variable cannot be used as an insertion value.
CONTEXT:  SQL statement "insert into t2 values(source)"
PL/pgSQL function inline_code_block line 7 at SQL statement
set behavior_compat_options='';
insert into t1 values('one','two');
declare
cursor cur1 is select * from t1;
source cur1%rowtype:=('ten','wtu');
begin
for source in cur1
loop
raise notice '%',source;
insert into t2 values(source);
end loop;
end;
/
NOTICE:  (one,two)
NOTICE:  (one,two)

#openGauss #入门 #安装 #数据库 #开源

知识来源:docs-opengauss.osinfra.cn/zh/