GUC使用说明
数据库提供了许多GUC参数,配置这些参数可以影响数据库系统的行为。在修改这些参数时请确保用户理解了这些参数本身的规格限制与修改后对数据库的影响,否则可能会导致无法预料的结果:
- 数据库内部部分参数与环境有关,在数据库安装时便已指定,不建议进行修改。如果有一定要修改的场景,设置时必须确保内容、格式正确,否则会导致实例异常。例如:设置侦听地址的参数listen_addresses;设置端口的参数port;设置ip地址的参数local_bind_address;以及各类设置文件输出路径的参数。
- 受限于使用的硬件资源大小,需要谨慎修改的参数。例如:内存、连接数、影响磁盘空间占用的相关参数。用户修改前需确认使用的硬件规格,确保参数修改后,不会超出硬件本身的大小限制,否则可能会使数据库实例申请不到足够的资源,导致实例状态异常。
- 受限于参数之间的联动,修改参数时需要详细阅读参数对应规格限制。例如:max_wal_senders参数取值必须小于max_connections参数取值,数据库才能正常启动。
- 参数设置不能过于极端,设置过大过小都有使业务受损的可能,需要详细理解参数含义并谨慎修改。例如:session_timeout参数设置1秒,业务与服务器建立连接后,1秒不进行操作,便会断开连接,从而影响业务正常执行。log_min_messages控制打印日志的级别,设置级别过低,会导致记录日志量过大,影响性能。
注意事项
- 参数中如果取值范围为字符串,此字符串应遵循操作系统的路径和文件名命名规则。
- 取值范围最大值为INT_MAX的参数,此选项最大值跟所在的操作系统有关。其值为数据类型INT的最大值,值为2147483647。
- 取值范围最大值为DBL_MAX的参数,此选项最大值跟所在的操作系统有关。其值为数据类型FLOAT的最大值。
- 部分GUC参数会影响函数/操作符的选择、存储过程的编译以及执行计划的生成,从而会影响到视图、函数参数默认值、存储过程编译产物以及计划缓存的行为。由于这些机制原因,后续GUC参数变更可能不会再影响这些行为。
- 视图:数据库在视图定义时会根据当前GUC参数状态生成重写规则,后续对视图操作时直接使用对应重写规则而不再受GUC参数(会影响重写规则生成的参数)的影响。
- 函数参数默认值:如果函数参数默认值使用了函数,数据库在创建该函数时会根据当前GUC参数状态为默认值参数选择对应的函数并记录选中的函数oid到对应系统表中(pg_proc),后续执行该函数时会使用系统表中记录的函数oid给默认值参数赋值而不再受GUC参数的影响。
- 存储过程编译产物:数据库对存储过程进行编译时会根据当前GUC参数状态生成编译产物,执行存储过程时直接使用编译产物而不再受GUC参数(会影响编译产物生成的参数)的影响。
- 计划缓存:数据库在执行SQL时会根据当前GUC参数状态生成对应的执行计划,如果将该计划缓存起来后,后续再执行该SQL将直接使用该计划而不再受GUC参数(会影响执行计划生成的参数)的影响。
有影响GUC参数如下表(GUC参数具体功能详见对应GUC参数):
GUC参数
打开参数
关闭参数
影响点
示例
convert_string_to_digit
优先将字符串转为数字
不支持打开参数时优先将字符串转为数字的行为。
视图、函数参数默认值、存储过程编译产物、计划缓存
CREATE or REPLACE FUNCTION test(c numeric) RETURN text package AS BEGIN RETURN 'test(c numeric)'; END; / CREATE or REPLACE FUNCTION test(c varchar2) RETURN text package AS BEGIN RETURN 'test(c varchar2)'; END; / SET convert_string_to_digit=on; CREATE or REPLACE VIEW test_view AS SELECT test('123'::text); SELECT test('123'::text); test ----------------- test(c numeric) (1 row) SELECT * FROM test_view; test ----------------- test(c numeric) (1 row) --关闭参数 SET convert_string_to_digit=off; SELECT test('123'::text); test ------------------ test(c varchar2) (1 row) --视图行为和直接调用函数行为不一致 SELECT * FROM test_view; test ----------------- test(c numeric) (1 row))set behavior_compat_options = 'current_sysdate';
SYSDATE函数获取当前操作系统时间(底层使用current_sysdate函数)
SYSDATE函数获取当前数据库时间(底层使用sysdate函数)。
视图、函数参数默认值、存储过程编译产物、计划缓存
SET behavior_compat_options = 'current_sysdate'; CREATE or REPLACE VIEW test_view_SYSDATE AS SELECT SYSDATE AS test; SELECT * FROM test_view_SYSDATE;--返回当前操作系统时间 SELECT SYSDATE;--返回当前操作系统时间 --关闭参数 SET behavior_compat_options = ''; --视图行为和直接调用函数行为不一致 SELECT * FROM test_view_SYSDATE;--返回当前操作系统时间 SELECT SYSDATE;--返回当前数据库时间
set a_format_version='10c';
set a_format_dev_version='s1';
- 新增支持NVL2。
- 新增部分系统函数。
- case when返回类型有变更。
- 集合类型构造器优先级高于函数。
- 支持timestamp到timestamptz的隐式转换。
不支持打开参数时功能。
视图、函数参数默认值、存储过程编译产物、计划缓存
SET a_format_version='10c'; SET a_format_dev_version='s1'; CREATE OR REPLACE VIEW test_view_nvl2 AS SELECT nvl2(1,2,3) AS test; SELECT * FROM test_view_nvl2; test ------ 2 (1 row) RESET a_format_dev_version; SELECT * FROM test_view_nvl2; test ------ 2 (1 row)
set a_format_version='10c';
set a_format_dev_version='s2';
- 新增支持CURRENT_TIMESTAMP '(' FCONST ')'。
- 新增支持DBTIMEZONE。
- 新增支持LNNVL。
- CURRENT_DATE
a_format_date_timestamp=off且mapping_date_to_datea=off情况下,返回值列名为timestamp;a_format_date_timestamp=on且mapping_date_to_datea=off情况下,返回值列名为current_date;mapping_date_to_datea=on情况下,a_format_date_timestamp不影响列名,返回值列名为current_date。
- 新增部分系统函数。
不支持打开参数时功能。
视图、函数参数默认值、存储过程编译产物、计划缓存
SET a_format_version='10c'; SET a_format_dev_version='s2'; CREATE or REPLACE VIEW test_view_LNNVL AS SELECT LNNVL(123=123) AS test; SELECT * FROM test_view_LNNVL; RESET a_format_dev_version; SELECT * FROM test_view_LNNVL;
set a_format_version='10c';
set a_format_dev_version='s4';
新增部分系统函数。
不支持打开参数时功能。
视图、函数参数默认值、存储过程编译产物、计划缓存
-
set a_format_version='10c';
set a_format_dev_version='s5';
- 新增部分系统函数。
- 复合类型构造器优先级高于函数。
不支持打开参数时功能。
视图、函数参数默认值、存储过程编译产物、计划缓存
--复合类型构造器优先级高于函数: CREATE TYPE tt AS ( val1 int, val2 int ); CREATE OR REPLACE FUNCTION tt(va int, vb int) RETURN int IS ret int; BEGIN ret := va; RETURN ret; END; / SET a_format_version='10c'; SET a_format_dev_version='s5'; --赋值给tt变量 CREATE OR REPLACE FUNCTION test0 RETURN int IS va tt; ret int; BEGIN va := tt(1,2); RAISE INFO 'tt: %' ,va; ret := 9; RETURN ret; END; / SELECT test0(); INFO: tt: (1,2) test0 ------- 9 (1 row) SET a_format_version=''; SET a_format_dev_version=''; SELECT test0(); INFO: tt: (1,2) test0 ------- 9 (1 row) --赋值给tt变量 CREATE OR REPLACE FUNCTION test0 RETURN int IS va tt; ret int; BEGIN va := tt(1,2); RAISE INFO 'tt: %' ,va; ret := 9; RETURN ret; END; / select test0(); ERROR: cannot assign non-composite value to a row variable
set behavior_compat_options = 'enable_bpcharlikebpchar_compare';
启用bpcharlikebpchar和bpcharnlikebpchar操作符。
关闭bpcharlikebpchar和bpcharnlikebpchar操作符。
视图、存储过程编译产物、计划缓存
CREATE TABLE op_test ( col BPCHAR(2) DEFAULT NULL ); CREATE INDEX op_index ON op_test(col); INSERT INTO op_test VALUES ('a'); INSERT INTO op_test VALUES ('1'); INSERT INTO op_test VALUES ('11'); INSERT INTO op_test VALUES ('12'); INSERT INTO op_test VALUES ('sd'); INSERT INTO op_test VALUES ('aa'); SET behavior_compat_options = 'enable_bpcharlikebpchar_compare'; EXPLAIN (COSTS OFF) SELECT * FROM op_test WHERE col LIKE col::BPCHAR ORDER BY col; QUERY PLAN ------------------------------ Sort Sort Key: col -> Seq Scan on op_test Filter: (col ~~ col) (4 rows) CREATE OR REPLACE VIEW test_view_bpchar AS SELECT * FROM op_test WHERE col LIKE col::BPCHAR ORDER BY col; EXPLAIN SELECT * FROM test_view_bpchar; QUERY PLAN ---------------------------------------------------------------- Sort (cost=34.48..34.50 rows=10 width=12) Sort Key: op_test.col -> Seq Scan on op_test (cost=0.00..34.31 rows=10 width=12) Filter: (col OPERATOR(pg_catalog.~~) col) (4 rows) SET behavior_compat_options = ''; EXPLAIN (COSTS OFF) SELECT * FROM op_test WHERE col LIKE col::BPCHAR ORDER BY col; QUERY PLAN -------------------------------------- Sort Sort Key: col -> Seq Scan on op_test Filter: (col ~~ (col)::text) (4 rows) EXPLAIN SELECT * FROM test_view_bpchar; QUERY PLAN ---------------------------------------------------------------- Sort (cost=34.48..34.50 rows=10 width=12) Sort Key: op_test.col -> Seq Scan on op_test (cost=0.00..34.31 rows=10 width=12) Filter: (col OPERATOR(pg_catalog.~~) col) (4 rows) --关闭开关的情况下重新创建视图: CREATE OR REPLACE VIEW test_view_bpchar AS SELECT * FROM op_test WHERE col LIKE col::BPCHAR ORDER BY col; explain select * from test_view_bpchar; QUERY PLAN ---------------------------------------------------------------- Sort (cost=39.34..39.37 rows=10 width=12) Sort Key: op_test.col -> Seq Scan on op_test (cost=0.00..39.17 rows=10 width=12) Filter: (col ~~ (col)::text) (4 rows)set b_format_version='5.7';set b_format_dev_version='s1';
- CURDATE、CURRENT_TIME、CURRENT_TIMESTAMP、LOCALTIME、LOCALTIMESTAMP NOW返回语句执行时刻时间戳。
- SYSDATE返回函数执行时刻时间戳。
- DB_JSOBJ、LAST_DAY_FUNC、EXTRACT、TIMESTAMPDIFF、SUBSTRING函数行为变更为与MYSQL一致。
- CURDATE、CURRENT_TIME、CURRENT_TIMESTAMP、LOCALTIME、LOCALTIMESTAMP NOW、SYSDATE函数返回事务开始时刻时间戳。
- DB_JSOBJ、LAST_DAY_FUNC、EXTRACT、TIMESTAMPDIFF、SUBSTRING函数恢复默认行为。
视图、函数参数默认值、存储过程编译产物、计划缓存
-
set behavior_compat_options = 'bind_procedure_searchpath';
- 未指定模式名的存储过程中的数据库对象的搜索路径配置项。
- 在存储过程中如果不显式指定模式名,会优先在存储过程所属的模式下搜索。
恢复默认行为。
存储过程编译产物
-
set behavior_compat_options='skip_insert_gs_source';
恢复默认行为。
创建PL/SQL对象(存储过程、函数以及package)时,不允许向gs_source中插入PL/SQL对象创建信息。
PL/SQL对象(存储过程、函数以及package)产物
CREATE OR REPLACE PROCEDURE proc_no_parameter AS ret1 int; BEGIN ret1 := 0; dbe_output.print_line( 'procedure has no parameter is 1w111.'); END; / SELECT * FROM DBE_PLDEVELOPER.gs_source; id | owner | nspid | name | type | status | src -------+-------+-------+-------------------+-----------+--------+----------------------------------------------------------------- 24593 | 10 | 2200 | proc_no_parameter | procedure | t | CREATE OR REPLACE PROCEDURE proc_no_parameter + | | | | | | AS + | | | | | | ret1 int; + | | | | | | BEGIN + | | | | | | ret1 := 0; + | | | | | | dbe_output.print_line( 'procedure has no parameter is 1w111.');+ | | | | | | END; (1 row)
set behavior_compat_options = 'enable_out_param_override';
控制存储过程出参的重载行为。
恢复默认行为。
存储过程编译产物
-
enable_bitmapscan
scan算子选择bitmapscan。
scan算子不选择bitmapscan。
计划缓存
SET enable_auto_explain=true; SET auto_explain_level=notice; CREATE TABLE t1( a int, b int, c int,d varchar)WITH(storage_type=ustore); CREATE TABLE t2( a int, b int, c int,d varchar)WITH(storage_type=ustore); INSERT INTO t1 SELECT i,10*random()*i,i%20,'atr'||i from generate_series(1,1000) i; CREATE INDEX index1 ON t1(a); SET enable_bitmapscan=on; SET enable_seqscan=off; SET enable_indexscan=off; CREATE OR REPLACE PROCEDURE proc_while_loop() AS DECLARE i int :=1; BEGIN WHILE i < 5 LOOP INSERT INTO t2 SELECT * FROM t1 WHERE a = i ; i:=i+1; END LOOP; END; / CALL proc_while_loop(); SET enable_bitmapscan=off; CALL proc_while_loop(); SET enable_bitmapscan=on; CALL proc_while_loop();
enable_indexscan
scan算子选择indexscan。
scan算子不选择indexscan。
计划缓存
SET enable_auto_explain=true; SET auto_explain_level=notice; CREATE TABLE t1( a int, b int, c int,d varchar)WITH(storage_type=ustore); CREATE TABLE t2( a int, b int, c int,d varchar)WITH(storage_type=ustore); INSERT INTO t1 SELECT i,10*random()*i,i%20,'atr'||i from generate_series(1,1000) i; CREATE INDEX index1 on t1(a); SET enable_bitmapscan=off; SET enable_seqscan=off; CREATE OR REPLACE PROCEDURE proc_while_loop() AS DECLARE i int :=1; BEGIN WHILE i < 5 LOOP insert into t2 select * from t1 where a = i ; i:=i+1; END LOOP; END; / CALL proc_while_loop(); SET enable_indexscan=off; CALL proc_while_loop();
query_Dop
用户自定义的查询并行度。开启SMP功能,系统会使用设定的并行度执行。
默认值为1,1表示关闭并行查询。
计划缓存
SET enable_auto_explain=true; SET auto_explain_level=notice; CREATE TABLE t1( a int, b int, c int,d varchar)WITH(storage_type=ustore); CREATE TABLE t2( a int, b int, c int,d varchar)WITH(storage_type=ustore); INSERT INTO t1 SELECT i,10*random()*i,i%20,'atr'||i from generate_series(1,1000) i; CREATE INDEX index1 ON t1(a); SET enable_bitmapscan=f; CREATE OR REPLACE PROCEDURE proc_while_loop() AS DECLARE i int :=1; BEGIN WHILE i < 5 LOOP INSERT INTO t2 SELECT /*+ indexscan(t1 index1) */* FROM t1 WHERE a = i ; i:=i+1; END LOOP; END; / SET enable_auto_explain=true; SET auto_explain_level=notice; SET client_min_messages=log; SET enable_stream_operator=on; SET query_dop=4; CALL proc_while_loop(); SET query_Dop=6; CALL proc_while_loop();
set plan_cache_mode = force_generic_plan
pbe情况下,强制执行gplan。
pbe情况下,不强制执行gplan。
计划缓存
SET enable_auto_explain=true; SET auto_explain_level=notice; CREATE TABLE t1( a int, b int, c int,d varchar)WITH(storage_type=ustore); CREATE TABLE t2( a int, b int, c int,d varchar)WITH(storage_type=ustore); INSERT INTO t1 SELECT i,10*random()*i,i%20,'atr'||i from generate_series(1,1000) i; CREATE INDEX index1 ON t1(a); SET enable_bitmapscan=on; SET enable_seqscan=off; SET enable_indexscan=off; CREATE OR REPLACE PROCEDURE proc_while_loop() AS DECLARE i int :=1; BEGIN WHILE i < 5 LOOP insert into t2 select * from t1 where a = i ; i:=i+1; END LOOP; END; / CALL proc_while_loop(); SET plan_cache_mode = force_generic_plan; PREPARE aa AS SELECT proc_while_loop(); EXECUTE aa; SET enable_bitmapscan=off; EXECUTE aa;
a_format_date_timestamp
CURRENT_DATE返回当前SQL启动的时间戳。
CURRENT_DATE返回事务开启的日期或日期及时间。
视图、函数参数默认值、存储过程编译产物、计划缓存
SET a_format_date_timestamp=on; CREATE OR REPLACE PROCEDURE proc_while_loop() AS DECLARE i date; BEGIN i:=current_date; raise info 'step2:%',TO_CHAR(current_date, 'MM-DD-YYYY HH24:MI:SS'); END; / CALL proc_while_loop(); PREPARE p1 AS SELECT current_timestamp; EXECUTE p1; SET a_format_date_timestamp=off; CALL proc_while_loop(); EXECUTE p1;
adjust_systemview_priority
同名视图优先访问用户自定义视图。
同名视图优先访问系统视图。
视图参数默认值
CREATE DATABASE database_test DBCOMPATIBILITY = 'ORA'; SELECT datname,datcompatibility,dattimezone FROM pg_database; \c database_test CREATE TABLE t1(c int); CREATE TABLE CREATE VIEW dual AS SELECT * FROM t1; CREATE VIEW SET adjust_systemview_priority = off; SET SELECT * FROM dual; dummy ------- X (1 row) PREPARE p1 as SELECT * FROM dual; PREPARE EXECUTE p1; dummy ------- X (1 row) SET adjust_systemview_priority = on; SET SELECT * FROM dual; c --- (0 rows) EXECUTE p1; dummy ------- X (1 row)
mapping_date_to_datea
在ORA兼容模式下,用datea类型替换date类型。
恢复默认行为。
视图、函数参数默认值、存储过程编译产物、计划缓存。
--新安装数据库中默认开关处于打开状态 SHOW mapping_date_to_datea; mapping_date_to_datea ----------------------- on (1 row) CREATE TABLE t1(c1 date); CREATE TABLE \d+ t1; Table "public.t1" Column | Type | Modifiers | Storage | Stats target | Description --------+-------+-----------+---------+--------------+------------- c1 | datea | | plain | | Has OIDs: no Options: orientation=row, compression=no, storage_type=USTORE, segment=off --在gaussdb.conf中设置开关为off,重启数据库后开关变为关闭 SHOW mapping_date_to_datea; mapping_date_to_datea ----------------------- off (1 row) CREATE TABLE t2(c1 date); CREATE TABLE \d+ t2; Table "public.t2" Column | Type | Modifiers | Storage | Stats target | Description --------+--------------------------------+-----------+---------+--------------+------------- c1 | timestamp(0) without time zone | | plain | | Has OIDs: no Options: orientation=row, compression=no, storage_type=USTORE, segment=offnls_date_format
在ORA兼容模式下,用于datea类型和字符类型转换时的格式控制:
1. 字符类型转换为date类型时,必须满足nls_date_format中设置的时间格式;
2. date类型转换为字符类型时,会按照nls_date_format的格式转换;
3. to_char和to_date默认按照nls_date_format格式转换。
不进行设置时,nls_date_format的默认值为"DD-MON-RR"。
视图、函数参数默认值、计划缓存
-- 默认值为'DD-MON-RR' SHOW nls_date_format; nls_date_format ----------------- DD-MON-RR (1 row) -- 输入date类型不符合nls_date_format格式时校验报错 SELECT '2020-10-10'::date; ERROR: invalid value "20-10-10" for "MON" LINE 1: select '2020-10-10'::date; ^ DETAIL: The given value did not match any of the allowed values for this field. CONTEXT: referenced column: datea SET nls_date_format='YYYY-MM-DD'; SET SELECT '2020-10-10'::date; datea ------------------------ 2020-10-10 00:00:00 AD (1 row) -- to_date函数的输入必须符合nls_date_format格式,否则报错 SELECT to_date('10-10-2020'); ERROR: Invalid data exists in a string for matching date. CONTEXT: referenced column: to_date SELECT to_date('2020-10-10'); to_date ------------------------ 2020-10-10 00:00:00 AD (1 row) -- to_char函数将date类型转为字符串时,字符串结果为nls_date_format设置的格式 SELECT to_char(to_date('05-2020-10', 'MM-YYYY-DD')); to_char ------------ 2020-05-10 (1 row)fixed_date
在ORA兼容模式下,固定sysdate的值,sysdate返回fixed_date所表示的时间。
sysdate返回系统时间。
sysdate的值。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
-- 开启fixed_date时返回的结果。 gaussdb=# SET fixed_date='2024-05-15 11:47:02'; SET gaussdb=# SELECT sysdate; timestamp --------------------- 2024-05-15 11:47:02 (1 row) gaussdb=# PREPARE p1 AS SELECT sysdate; PREPARE gaussdb=# EXECUTE p1; datea ------------------------ 2024-05-15 11:47:02 AD (1 row) gaussdb=# SET fixed_date='2024-05-16 11:47:02'; SET gaussdb=# SELECT sysdate; datea ------------------------ 2024-05-16 11:47:02 AD (1 row) gaussdb=# EXECUTE p1; datea ------------------------ 2024-05-15 11:47:02 AD (1 row)
a_format_func_col_name
在ORA兼容模式下,将select user返回的投影列名从current_user改为user。
在ORA兼容模式下,select user返回的投影列名为current_user。
计划缓存。
gaussdb=# PREPARE p1 AS SELECT user FROM dual; PREPARE gaussdb=# EXECUTE p1; current_user -------------- omm (1 row) gaussdb=# SET a_format_func_col_name = 'user'; SET gaussdb=# EXECUTE p1; current_user -------------- omm (1 row)
disable_keyword_options
影响各兼容模式关键字的行为,具体内容可参考表10
影响各兼容模式关键字的行为,具体内容可参考表10
计划缓存
gaussdb=# set disable_keyword_options = 'dbtimezone'; SET gaussdb=# prepare p1 as select 1 dbtimezone; PREPARE gaussdb=# execute p1; dbtimezone ------------ 1 (1 row) gaussdb=# set disable_keyword_options = ''; SET gaussdb=# execute p1; dbtimezone ------------ 1 (1 row) gaussdb=# deallocate p1; DEALLOCATE
backslash_quote
打开参数允许字符串文本中的单引号使用\'表示
关闭参数不允许字符串文本中的单引号使用\'表示
计划缓存
gaussdb=# set backslash_quote = 'safe_encoding'; SET gaussdb=# prepare p1 as select text E'Don \'t do that.'; PREPARE gaussdb=# execute p1; text ----------------- Don 't do that. (1 row) gaussdb=# set backslash_quote = off; SET gaussdb=# execute p1; text ----------------- Don 't do that. (1 row) gaussdb=# deallocate p1; DEALLOCATE
set sql_mode='ansi_quotes'
M-Compatibility模式下标识符同时支持反引号(``)和双引号("")
M-Compatibility模式下标识符仅支持反引号(``)
计划缓存
-- sql_mode选项变化,不会让计划重新生成。 m_db=# CREATE TABLE t1(a int); NOTICE: The 'DISTRIBUTE BY' clause is not specified. Using 'a' as the distribution column by default. HINT: Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column. CREATE TABLE m_db=# SET sql_mode = 'ansi_quotes'; SET m_db=# PREPARE p1 FROM 'INSERT INTO "t1" VALUES(1)'; PREPARE m_db=# EXECUTE p1; INSERT 0 1 m_db=# SET sql_mode=''; SET m_db=# EXECUTE p1; INSERT 0 1 m_db=# DROP TABLE t1; DROP TABLE
standard_conforming_strings
按照SQL标准把反斜杠当做普通文本
反斜杠在字符串字面值中被解释为转义字符
计划缓存
gaussdb=# SET standard_conforming_strings = on; SET gaussdb=# PREPARE p1 AS SELECT u&'d\0061t\+000061' AS u&"d\0061t\+000061"; PREPARE gaussdb=# SELECT u&'d\0061t\+000061' AS u&"d\0061t\+000061"; data ------ data (1 row) gaussdb=# EXECUTE p1; data ------ data (1 row) gaussdb=# SET standard_conforming_strings = off; SET gaussdb=# SELECT u&'d\0061t\+000061' AS u&"d\0061t\+000061"; ERROR: unsafe use of string constant with Unicode escapes LINE 1: select u&'d\0061t\+000061' as u&"d\0061t\+000061"; ^ DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off. gaussdb=# EXECUTE p1; data ------ data (1 row) gaussdb=# DEALLOCATE p1; DEALLOCATE
set behavior_compat_options = 'ignore_like_default_escape';
standard_conforming_strings为on时可以开启该选项,开启后支持在LIKE模糊匹配中将模式串的反斜杠字符视为普通字符进行匹配。
LIKE模糊匹配中模式串的反斜杠字符作为转义字符,用于消除通配符的特殊含义。
计划缓存
gaussdb=# SET standard_conforming_strings = on; SET gaussdb=# SET behavior_compat_options = 'ignore_like_default_escape'; SET gaussdb=# CREATE TABLE test(c1 text); CREATE TABLE gaussdb=# INSERT INTO test values('aa\a'); INSERT 0 1 gaussdb=# PREPARE p1 AS SELECT * FROM test WHERE c1 LIKE 'aa\a'; PREPARE gaussdb=# EXECUTE p1; c1 ------ aa\a (1 row) gaussdb=# SELECT * FROM test WHERE c1 LIKE 'aa\a'; c1 ------ aa\a (1 row) gaussdb=# SET behavior_compat_options = ''; SET gaussdb=# EXECUTE p1; c1 ------ aa\a (1 row) gaussdb=# SELECT * FROM test WHERE c1 LIKE 'aa\a'; c1 ---- (0 rows) gaussdb=# DEALLOCATE p1; DEALLOCATE