华为云用户手册

  • 现象描述 查询与销售部所有员工的信息: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 --建表 CREATE TABLE staffs (staff_id NUMBER(6) NOT NULL, first_name VARCHAR2(20), last_name VARCHAR2(25), employment_id VARCHAR2(10), section_id NUMBER(4), state_name VARCHAR2(10), city VARCHAR2(10)); CREATE TABLE sections(section_id NUMBER(4), place_id NUMBER(4), section_name VARCHAR2(20)); CREATE TABLE states(state_id NUMBER(4)); CREATE TABLE places(place_id NUMBER(4), state_id NUMBER(4)); --优化前查询 EXPLAIN SELECT staff_id,first_name,last_name,employment_id,state_name,city FROM staffs,sections,states,places WHERE sections.section_name='Sales' AND staffs.section_id = sections.section_id AND sections.place_id = places.place_id AND places.state_id = states.state_id ORDER BY staff_id; --创建索引 CREATE INDEX loc_id_pk ON places(place_id); CREATE INDEX state_c_id_pk ON states(state_id); --优化后查询 EXPLAIN SELECT staff_id,first_name,last_name,employment_id,state_name,city FROM staffs,sections,states,places WHERE sections.section_name='Sales' AND staffs.section_id = sections.section_id AND sections.place_id = places.place_id AND places.state_id = states.state_id ORDER BY staff_id;
  • PG_NAMESPACE PG_NAMESPACE系统表存储名称空间,即存储schema相关的信息。 表1 PG_NAMESPACE字段 名称 类型 描述 oid oid 行标识符(隐含属性,必须明确选择)。 nspname name 名称空间的名称。 nspowner oid 名称空间的所有者。 nsptimeline bigint 在数据库节点上创建此命名空间时的时间线。此字段为内部使用,仅在数据库节点上有效。 nspacl aclitem[] 访问权限。 in_redistribution "char" 是否处于重发布状态。 nspblockchain boolean 如果为真,则该模式为防篡改模式。 如果为假,则此模式为非防篡改模式。 父主题: 系统表
  • PGXC_CLASS PGXC_CLASS系统表存储每张表的复制或分布信息。PGXC_CLASS系统表在集中式场景下只能查询表定义。 表1 PGXC_CLASS字段 名称 类型 描述 pcrelid oid 表的OID。 pclocatortype "char" 定位器类型。 H:hash G:Range L:List M:Modulo N:Round Robin R:Replication pchashalgorithm smallint 使用哈希算法分布元组。 pchashbuckets smallint 哈希容器的值。 pgroup name 节点群的名称。 redistributed "char" 表已经完成重分布。 redis_order integer 重分布的顺序。该值等于0的表在本轮重分布过程中不进行重分布。 pcattnum int2vector 用作分布键的列标号。 nodeoids oidvector_extend 表分布的节点OID列表。 options text 系统内部保留字段,存储扩展状态信息。 父主题: 系统表
  • javax.sql.ConnectionPoolDataSource javax.sql.ConnectionPoolDataSource是数据源连接池接口。 表1 对javax.sql.ConnectionPoolDataSource的支持情况 方法名 返回值类型 支持JDBC 4 getPooledConnection() PooledConnection Yes getPooledConnection(String user,String password) PooledConnection Yes 父主题: JDBC接口参考
  • 注意事项 只有行存B-tree索引支持CLUSTER操作。 如果用户只是随机访问表中的行,那么表中数据的实际存储顺序是无关紧要的。但是,如果对某些特定数据的访问次数较多,而且有一个索引将这些数据分组,那么使用CLUSTER索引对性能会有所提升。 如果一个请求从表中查找的索引是一个范围,或者是一个索引值对应多行,CLUSTER也会有助于应用,因为如果索引标识出了第一匹配行所在的存储页,所有其它行也可能也已经在同一个存储页里了,这样便节省了磁盘访问的时间,加速了查询。 在聚簇过程中,系统会先创建一个按照索引顺序建立的表的临时备份,同时也建立表上的每个索引的临时备份。因此,聚簇过程中需要保证磁盘上有足够的剩余空间,至少是表大小与全部索引大小之和。 因为CLUSTER记录着哪些索引曾被用于聚簇,所以用户可以在第一次手动指定索引,对指定表进行聚簇,然后设置一个周期化执行的维护脚本,只需执行不带参数的CLUSTER命令,就可以实现对想要周期性聚簇的表进行自动更新。 因为优化器记录着有关表的排序的统计,在表上执行聚簇操作后,需运行ANALYZE操作以确保优化器具备最新的排序信息,否则,优化器可能会选择非最优的查询规划。 CLUSTER不允许在事务中执行。 如果没有将GUC参数xc_maintenance_mode设置为on,那么CLUSTER操作将跳过所有系统表。
  • 功能描述 根据一个索引对表进行聚簇排序。 CLUSTER指定 GaussDB 通过索引名指定的索引聚簇由表名指定的表。表名上必须已经定义该索引。 当对一个表聚簇后,该表将基于索引信息进行物理存储。聚簇是一次性操作:当表被更新之后,更改的内容不会被聚簇。也就是说,系统不会试图按照索引顺序对新的存储内容及更新记录进行重新聚簇。 在对一个表聚簇之后,GaussDB会记录该表在哪一个索引上建立了聚簇。CLUSTER table_name将在该表之前记录过的聚簇索引上重新聚簇。用户也可以用ALTER TABLE table_name CLUSTER on index_name来设置指定表用于后续聚簇操作的索引,或使用ALTER TABLE table_name SET WITHOUT CLUSTER来清除指定表之前设置的聚簇索引。 不含参数的CLUSTER命令会将当前用户所拥有的数据库中的先前做过聚簇的所有表重新处理。如果系统管理员调用这个命令,则对所有进行过聚簇的表重新聚簇。 在对一个表进行聚簇的时候,会在其上请求一个AC CES S EXCLUSIVE锁。这样就避免了在CLUSTER完成之前对此表执行其它的操作(包括读写)。
  • 示例 --创建SCHEMA。 openGauss=# CREATE SCHEMA tpcds; -- 创建一个分区表。 openGauss=# CREATE TABLE tpcds.inventory_p1 ( INV_DATE_SK INTEGER NOT NULL, INV_ITEM_SK INTEGER NOT NULL, INV_WAREHOUSE_SK INTEGER NOT NULL, INV_QUANTITY_ON_HAND INTEGER ) PARTITION BY RANGE(INV_DATE_SK) ( PARTITION P1 VALUES LESS THAN(2451179), PARTITION P2 VALUES LESS THAN(2451544), PARTITION P3 VALUES LESS THAN(2451910), PARTITION P4 VALUES LESS THAN(2452275), PARTITION P5 VALUES LESS THAN(2452640), PARTITION P6 VALUES LESS THAN(2453005), PARTITION P7 VALUES LESS THAN(MAXVALUE) ); -- 创建索引ds_inventory_p1_index1。 openGauss=# CREATE INDEX ds_inventory_p1_index1 ON tpcds.inventory_p1 (INV_ITEM_SK) LOCAL; -- 对表tpcds.inventory_p1进行聚簇。 openGauss=# CLUSTER tpcds.inventory_p1 USING ds_inventory_p1_index1; -- 对分区p3进行聚簇。 openGauss=# CLUSTER tpcds.inventory_p1 PARTITION (p3) USING ds_inventory_p1_index1; -- 对已做过聚簇的表重新进行聚簇。 openGauss=# CLUSTER; --删除索引。 openGauss=# DROP INDEX tpcds.ds_inventory_p1_index1; --删除分区表。 openGauss=# DROP TABLE tpcds.inventory_p1; --删除SCHEMA。 openGauss=# DROP SCHEMA tpcds CASCADE;
  • 语法格式 对一个表进行聚簇排序。 CLUSTER [ VERBOSE ] table_name [ USING index_name ]; 对一个分区进行聚簇排序。 CLUSTER [ VERBOSE ] table_name PARTITION ( partition_name ) [ USING index_name ]; 对已做过聚簇的表重新进行聚簇。 CLUSTER [ VERBOSE ];
  • 语法格式 CREATE GROUP group_name [ [ WITH ] option [ ... ] ] [ ENCRYPTED | UNENCRYPTED ] { PASSWORD | IDENTIFIED BY } { 'password' [ EXPIRED ] | DISABLE }; 其中可选项option子句语法为: {SYSADMIN | NOSYSADMIN} | {MONADMIN | NOMONADMIN} | {OPRADMIN | NOOPRADMIN} | {POLADMIN | NOPOLADMIN} | {AUDITADMIN | NOAUDITADMIN} | {CREATEDB | NOCREATEDB} | {USEFT | NOUSEFT} | {CREATEROLE | NOCREATEROLE} | {INHERIT | NOINHERIT} | { LOG IN | NOLOGIN} | {REPLICATION | NOREPLICATION} | {VCADMIN | NOVCADMIN} | {PERSISTENCE | NOPERSISTENCE} | CONNECTION LIMIT connlimit | VALID BEGIN 'timestamp' | VALID UNTIL 'timestamp' | PERM SPACE 'spacelimit' | TEMP SPACE 'tmpspacelimit' | SPILL SPACE 'spillspacelimit' | IN ROLE role_name [, ...] | IN GROUP role_name [, ...] | ROLE role_name [, ...] | ADMIN rol e_name [, ...] | USER role_name [, ...] | SYSID uid | DEFAULT TABLESPACE tablespace_name | PROFILE DEFAULT | PROFILE profile_name | PGUSER
  • 参数说明 IF EXISTS IF EXISTS表示,如果函数存在则执行删除操作,函数不存在也不会报错,只是发出一个notice。 function_name 要删除的函数名称。 取值范围:已存在的函数名。 argmode 函数参数的模式。 argname 函数参数的名称。 argtype 函数参数的类型 CASCADE | RESTRICT CASCADE:级联删除依赖于函数的对象 。 RESTRICT:如果有任何依赖对象存在,则拒绝删除该函数(缺省行为)。
  • 功能描述 SET CONSTRAINTS设置当前事务检查行为的约束条件。 IMMEDIATE约束是在每条语句后面进行检查。DEFERRED约束一直到事务提交时才检查。每个约束都有自己的模式。 从创建约束条件开始,一个约束总是设定为DEFERRABLE INITIALLY DEFERRED,DEFERRABLE INITIALLY IMMEDIATE,NOT DEFERRABLE三个特性之一。第三种总是IMMEDIATE,并且不会受SET CONSTRAINTS影响。前两种以指定的方式启动每个事务,但是其行为可以在事务里用SET CONSTRAINTS改变。 带着一个约束名列表的SET CONSTRAINTS改变这些约束的模式(都必须是可推迟的)。如果有多个约束匹配某个名称,则所有都会被影响。SET CONSTRAINTS ALL改变所有可推迟约束的模式。 当SET CONSTRAINTS把一个约束从DEFERRED改成IMMEDIATE的时候,新模式反作用式地起作用:任何将在事务结束准备进行的数据修改都将在SET CONSTRAINTS的时候执行检查。如果违反了任何约束,SET CONSTRAINTS都会失败(并且不会修改约束模式)。因此,SET CONSTRAINTS可以用于强制在事务中某一点进行约束检查。 检查约束总是不可推迟的。
  • PG_COMM_RECV_STREAM PG_COMM_RECV_STREAM视图展示单个DN上所有的通信库接收流状态。 表1 PG_COMM_RECV_STREAM字段 名称 类型 描述 node_name text 节点名称。 local_tid bigint 使用此通信流的线程ID。 remote_name text 连接对端节点名称。 remote_tid bigint 连接对端线程ID。 idx integer 通信对端DN在本DN内的标识编号。 sid integer 通信流在物理连接中的标识编号。 tcp_sock integer 通信流所使用的tcp通信socket。 state text 通信流当前的状态。 UNKNOWN:表示当前逻辑连接状态未知。 READY:表示逻辑连接已就绪。 RUN:表示逻辑连接发送报文正常。 HOLD:表示逻辑连接发送报文等待中。 CLOSED:表示关闭逻辑连接。 TO_CLOSED:表示将会关闭逻辑连接。 query_id bigint 通信流对应的debug_query_id编号。 pn_id integer 通信流所执行查询的plan_node_id编号。 send_smp integer 通信流所执行查询send端的smpid编号。 recv_smp integer 通信流所执行查询recv端的smpid编号。 recv_bytes bigint 通信流接收的数据总量,单位Byte。 time bigint 通信流当前生命周期使用时长,单位ms。 speed bigint 通信流的平均接收速率,单位Byte/s。 quota bigint 通信流当前的通信配额值,单位Byte。 buff_usize bigint 通信流当前缓存的数据大小,单位Byte。 父主题: 系统视图
  • PG_STAT_DATABASE PG_STAT_DATABASE视图将包含GaussDB中每个数据库的数据库统计信息。 表1 PG_STAT_DATABASE字段 名称 类型 描述 datid oid 数据库的OID。 datname name 数据库的名称。 numbackends integer 当前连接到该数据库的后端数。 这是该视图中唯一一个返回当前状态值的字段,其他字段返回的都是自上次重置之后的累计值。 xact_commit bigint 该数据库中已经提交的事务数。 xact_rollback bigint 该数据库中已经回滚的事务数。 blks_read bigint 在该数据库中读取的磁盘块的数量。 blks_hit bigint 已在缓冲区缓存中找到磁盘块的次数,因此不需要读取(只统计在缓冲区缓存找到的,不包括在操作系统的文件系统缓存中找到的)。 tup_returned bigint 通过数据库查询返回的行数。 tup_fetched bigint 通过数据库查询抓取的行数。 tup_inserted bigint 通过数据库查询插入的行数。 tup_updated bigint 通过数据库查询更新的行数。 tup_deleted bigint 通过数据库查询删除的行数。 conflicts bigint 由于数据库恢复冲突取消的查询数量(只在备用服务器发生的冲突)。请参见PG_STAT_DATABASE_CONFLI CTS 获取更多信息。 temp_files bigint 通过数据库查询创建的临时文件数量。计算所有临时文件, 无论该临时文件为什么创建(比如排序或者哈希),也不管log_temp_files参数如何设置。 temp_bytes bigint 通过数据库查询写入临时文件的数据总量。计算所有临时文件,无论该临时文件为什么创建,而且不管log_temp_files设置。 deadlocks bigint 该数据库中检测到的自上次重置统计信息以来所有的死锁数。 blk_read_time double precision 通过数据库后端读取数据文件块花费的时间,以毫秒计算。 blk_write_time double precision 通过数据库后端写入数据文件块花费的时间,以毫秒计算。 stats_reset timestamp with time zone 当前状态统计被重置的时间。 父主题: 系统视图
  • SUMMARY_STAT_USER_INDEXES 数据库内汇聚所有数据库中用户自定义普通表的索引状态信息。 表1 SUMMARY_STAT_USER_INDEXES字段 名称 类型 描述 schemaname name 索引的模式名。 relname name 索引的表名。 indexrelname name 索引名。 idx_scan numeric 索引上开始的索引扫描数。 idx_tup_read numeric 通过索引上扫描返回的索引项数。 idx_tup_fetch numeric 通过使用索引的简单索引扫描抓取的活表行数。 父主题: Object
  • GS_JOB_ATTRIBUTE GS_JOB_ATTRIBUTE系统表提供了DBE_SCHEDULER定时任务的相关属性信息,其中包括定时任务,定时任务类,证书,授权,程序和调度的基本属性。 表1 GS_JOB_ATTRIBUTE字段 名称 类型 描述 oid oid 行标识符(隐含字段)。 job_name text 定时任务,定时任务类,证书,程序和调度的名字,授权的用户名。 attribute_name text 定时任务,定时任务类,证书,程序和调度的属性名,授权的内容。 attribute_value text 定时任务,定时任务类,证书,程序和调度的属性值。 父主题: 系统表
  • PG_REPLICATION_ORIGIN PG_REPLICATION_ORIGIN系统表包含所有已创建的复制源,该表在数据库实例的所有数据库之间共享,即每个实例只有一份,而不是每个数据库一份。 表1 PG_REPLICATION_ORIGIN字段 名称 类型 描述 roident oid 一个数据库实例范围内唯一的复制源标识符。 roname text 外部的由用户定义的复制源名称。 父主题: 系统表
  • 兼容PostgreSQL的函数和操作符 下述列表为GaussDB的内建函数和操作符兼容PostgreSQL。 _pg_char_max_length _pg_char_octet_length _pg_datetime_precision _pg_expandarray _pg_index_position _pg_interval_type _pg_numeric_precision _pg_numeric_precision_radix _pg_numeric_scale _pg_truetypid _pg_truetypmod abbrev abs abstime abstimeeq abstimege abstimegt abstimein abstimele abstimelt abstimene abstimeout abstimerecv abstimesend aclcontains acldefault aclexplode aclinsert aclitemeq aclitemin aclitemout aclremove acos age akeys any_in any_out anyarray_in anyarray_out anyarray_recv anyarray_send anyelement_in anyelement_out anyenum_in anyenum_out anynonarray_in anynonarray_out anyrange_in anyrange_out anytextcat area areajoinsel areasel array_agg array_agg_finalfn array_agg_transfn array_append array_cat array_dims array_eq array_fill array_ge array_gt array_in array_larger array_le array_length array_lower array_lt array_ndims array_ne array_out array_prepend array_recv array_send array_smaller array_to_json array_to_string array_typanalyze array_upper arraycontained arraycontains arraycontjoinsel arraycontsel arrayoverlap ascii asin atan atan2 avals avg big5_to_euc_tw big5_to_mic big5_to_utf8 bit bit_and bit_in bit_length bit_or bit_out bit_recv bit_send bitand bitcat bitcmp biteq bitge bitgt bitle bitlt bitne bitnot bitor bitshiftleft bitshiftright bittypmodin bittypmodout bitxor bool bool_and bool_or booland_statefunc booleq boolge boolgt boolin boolle boollt boolne boolor_statefunc boolout boolrecv boolsend box box_above box_above_eq box_add box_below box_below_eq box_center box_contain box_contain_pt box_contained box_distance box_div box_eq box_ge box_gt box_in box_intersect box_le box_left box_lt box_mul box_out box_overabove box_overbelow box_overlap box_overleft box_overright box_recv box_right box_same box_send box_sub bpchar bpchar_larger bpchar_pattern_ge bpchar_pattern_gt bpchar_pattern_le bpchar_pattern_lt bpchar_smaller bpchar_sortsupport bpcharcmp bpchareq bpcharge bpchargt bpchariclike bpcharicnlike bpcharicregexeq bpcharicregexne bpcharin bpcharle bpcharlike bpcharlt bpcharne bpcharnlike bpcharout bpcharrecv bpcharregexeq bpcharregexne bpcharsend bpchartypmodin bpchartypmodout broadcast btabstimecmp btarraycmp btbeginscan btboolcmp btbpchar_pattern_cmp btbuild btbuildempty btbulkdelete btcanreturn btcharcmp btcostestimate btendscan btfloat48cmp btfloat4cmp btfloat4sortsupport btfloat84cmp btfloat8cmp btfloat8sortsupport btgetbitmap btgettuple btinsert btint24cmp btint28cmp btint2cmp btint2sortsupport btint42cmp btint48cmp btint4cmp btint4sortsupport btint82cmp btint84cmp btint8cmp btint8sortsupport btmarkpos btnamecmp btnamesortsupport btoidcmp btoidsortsupport btoidvectorcmp btoptions btrecordcmp btreltimecmp btrescan btrestrpos btrim bttext_pattern_cmp bttextcmp bttextsortsupport bttidcmp bttintervalcmp btvacuumcleanup bytea_sortsupport bytea_string_agg_finalfn bytea_string_agg_transfn byteacat byteacmp byteaeq byteage byteagt byteain byteale bytealike bytealt byteane byteanlike byteaout bytearecv byteasend cash_cmp cash_div_cash cash_div_flt4 cash_div_flt8 cash_div_int2 cash_div_int4 cash_div_int8 cash_eq cash_ge cash_gt cash_in cash_le cash_lt cash_mi cash_mul_flt4 cash_mul_flt8 cash_mul_int2 cash_mul_int4 cash_mul_int8 cash_ne cash_out cash_pl cash_recv cash_send cashlarger cashsmaller cbrt ceil ceiling center char char_length character_length chareq charge chargt charin charle charlt charne charout charrecv charsend chr cideq cidin cidout cidr cidr_in cidr_out cidr_recv cidr_send cidrecv cidsend circle circle_above circle_add_pt circle_below circle_center circle_contain circle_contain_pt circle_contained circle_distance circle_div_pt circle_eq circle_ge circle_gt circle_in circle_le circle_left circle_lt circle_mul_pt circle_ne circle_out circle_overabove circle_overbelow circle_overlap circle_overleft circle_overright circle_recv circle_right circle_same circle_send circle_sub_pt clock_timestamp close_lb close_ls close_lseg close_pb close_pl close_ps close_sb close_sl col_description concat concat_ws contjoinsel contsel convert convert_from convert_to corr cos cot count covar_pop covar_samp cstring_in cstring_out cstring_recv cstring_send cume_dist current_database current_query current_schema xpath_exists current_setting current_user currtid currtid2 currval cursor_to_xml cursor_to_xmlschema database_to_xml database_to_xml_and_xmlschema database_to_xmlschema date date_cmp date_cmp_timestamp date_cmp_timestamptz date_eq date_eq_timestamp date_eq_timestamptz date_ge date_ge_timestamp date_ge_timestamptz date_gt date_gt_timestamp date_gt_timestamptz date_in date_larger date_le date_le_timestamp date_le_timestamptz date_lt date_lt_timestamp date_lt_timestamptz date_mi date_mi_interval date_mii date_ne date_ne_timestamp date_ne_timestamptz date_out date_pl_interval date_pli date_recv date_send date_smaller date_sortsupport daterange_canonical daterange_subdiff datetime_pl datetimetz_pl dcbrt decode defined degrees delete dense_rank dexp diagonal diameter dispell_init dispell_lexize dist_cpoly dist_lb dist_pb dist_pc dist_pl dist_ppath dist_ps dist_sb dist_sl div dlog1 dlog10 domain_in domain_recv dpow dround dsimple_init dsimple_lexize dsnowball_init dsnowball_lexize dsqrt dsynonym_init dsynonym_lexize dtrunc each enum_ne enum_out enum_range enum_recv enum_send enum_smaller eqjoinsel eqsel euc_cn_to_mic euc_cn_to_utf8 euc_jis_2004_to_shift_jis_2004 euc_jis_2004_to_utf8 euc_jp_to_mic euc_jp_to_sjis euc_jp_to_utf8 euc_kr_to_mic euc_kr_to_utf8 euc_tw_to_big5 euc_tw_to_mic euc_tw_to_utf8 every exist exists_all exists_any exp factorial family fdw_handler_in fdw_handler_out fetchval first_value float4 float4_accum float48div float48eq float48ge float48gt float48le float48lt float48mi float48mul float48ne float48pl float4abs float4div float4eq float4ge float4gt float4in float4larger float4le float4lt float4mi float4mul float4ne float4out float4pl float4recv float4send float4smaller float4um float4up float8 float8_accum float8_avg float8_collect float8_corr float8_covar_pop float8_covar_samp float8_regr_accum float8_regr_avgx float8_regr_avgy float8_regr_collect float8_regr_intercept float8_regr_r2 float8_regr_slope float8_regr_sxx float8_regr_sxy float8_regr_syy float8_stddev_pop float8_stddev_samp float8_var_pop float8_var_samp float84div float84eq float84ge float84gt float84le float84lt float84mi float84mul float84ne float84pl float8abs float8div float8eq float8ge float8gt float8in float8larger float8le float8lt float8mi float8mul float8ne float8out float8pl float8recv float8send float8smaller float8um float8up floor flt4_mul_cash flt8_mul_cash fmgr_c_validator fmgr_internal_validator fmgr_sql_validator format format_type gb18030_to_utf8 gbk_to_utf8 generate_series generate_subscripts get_bit get_byte get_current_ts_config - - gin_clean_pending_list gin_cmp_prefix gin_cmp_tslexeme gin_extract_tsquery gin_extract_tsvector gin_tsquery_consistent gin_tsquery_triconsistent ginarrayconsistent ginarrayextract ginarraytriconsistent ginbeginscan ginbuild ginbuildempty ginbulkdelete gincostestimate ginendscan gingetbitmap gininsert ginmarkpos ginoptions ginqueryarrayextract ginrescan ginrestrpos ginvacuumcleanup gist_box_compress gist_box_consistent gist_box_decompress gist_box_penalty gist_box_picksplit gist_box_same gist_box_union gist_circle_compress gist_circle_consistent gist_point_compress gist_point_consistent gist_point_distance gist_poly_compress gist_poly_consistent gistbeginscan gistbuild gistbuildempty gistbulkdelete gistcostestimate gistendscan gistgetbitmap gistgettuple gistinsert gistmarkpos gistoptions gistrescan gistrestrpos gistvacuumcleanup gtsquery_compress gtsquery_consistent gtsquery_decompress gtsquery_penalty gtsquery_picksplit gtsquery_same gtsquery_union gtsvector_compress gtsvector_consistent gtsvector_decompress gtsvector_penalty gtsvector_picksplit gtsvector_same gtsvector_union gtsvectorin gtsvectorout has_tablespace_privilege has_type_privilege hash_aclitem hashbeginscan hashbuild hashbuildempty hashbulkdelete hashcostestimate hashendscan hashgetbitmap hashgettuple hashinsert hashint2vector hashint4 hashint8 hashmacaddr hashmarkpos hashname hashoid hashoidvector hashoptions hashrescan hashrestrpos hashtext hashvacuumcleanup hashvarlena host hostmask iclikejoinsel iclikesel icnlikejoinsel icnlikesel icregexeqjoinsel icregexeqsel icregexnejoinsel icregexnesel inet_client_addr inet_client_port inet_in inet_out inet_recv inet_send inet_server_addr inet_server_port inetand inetmi inetmi_int8 inetnot inetor inetpl initcap int2_accum int2_avg_accum int2_mul_cash int2_sum int24div int24eq int24ge int24gt int24le int24lt int24mi int24mul int24ne int24pl int28div int28eq int28ge int28gt int28le int28lt int28mi int28mul int28ne int28pl int2abs int2and int2div int2eq int2ge int2gt int2in int2larger int2le int2lt int2mi int2mod int2mul int2ne int2not int2or int2out int2pl int2recv int2send int2shl int2shr int2smaller int2um int2up int2vectoreq int2vectorin int2vectorout int2vectorrecv int2vectorsend int2xor int4_accum int4_avg_accum int4_mul_cash int4_sum int42div int42eq int42ge int42gt int42le int42lt int42mi int42mul int42ne int42pl int48div int48eq int48ge int48gt int48le int48lt int48mi int48mul int48ne int48pl int4abs int4and int4div int4eq int4ge int4gt int4in int4inc int4larger int4le int4lt int4mi int4mod int4mul int4ne int4not int4or int4out int4pl int4range int4range_canonical int4range_subdiff int4recv int4send int4shl int4shr int4smaller int4um int4up int4xor int8 int8_avg int8_avg_accum int8_avg_collect int8_mul_cash int8_sum int8_sum_to_int8 int8_accum int82div int82eq int82ge int82gt int82le int82lt int82mi int82mul int82ne int82pl int84div int84eq int84ge int84gt int84le int84lt int84mi int84mul int84ne int84pl int8abs int8and int8div int8eq int8ge int8gt int8in int8inc int8inc_any int8inc_float8_float8 int8larger int8le int8lt int8mi int8mod int8mul int8ne int8not int8or int8out int8pl int8pl_inet int8range int8range_canonical int8range_subdiff int8recv int8send int8shl int8shr int8smaller int8um int8up int8xor integer_pl_date inter_lb inter_sb inter_sl internal_in internal_out interval interval_accum interval_avg interval_cmp interval_collect interval_div interval_eq interval_ge interval_gt interval_hash interval_in interval_larger interval_le interval_lt interval_mi interval_mul interval_ne interval_out interval_pl interval_pl_date interval_pl_time interval_pl_timestamp interval_pl_timestamptz interval_pl_timetz interval_recv interval_send interval_smaller interval_transform interval_um intervaltypmodin intervaltypmodout intinterval isexists ishorizontal iso_to_koi8r iso_to_mic iso_to_win1251 iso_to_win866 iso8859_1_to_utf8 iso8859_to_utf8 isparallel isperp isvertical johab_to_utf8 jsonb_in jsonb_out jsonb_recv jsonb_send - - - json_in json_out json_recv json_send justify_days justify_hours justify_interval koi8r_to_iso koi8r_to_mic koi8r_to_utf8 koi8r_to_win1251 koi8r_to_win866 koi8u_to_utf8 language_handler_in language_handler_out latin1_to_mic latin2_to_mic latin2_to_win1250 latin3_to_mic latin4_to_mic like_escape likejoinsel likesel line line_distance line_eq line_horizontal line_in line_interpt line_intersect line_out line_parallel line_perp line_recv line_send line_vertical ln lo_close lo_creat lo_create lo_export lo_import lo_lseek lo_open lo_tell lo_truncate lo_unlink log loread lower lower_inc lower_inf lowrite lpad lseg lseg_center lseg_distance lseg_eq lseg_ge lseg_gt lseg_horizontal lseg_in lseg_interpt lseg_intersect lseg_le lseg_length lseg_lt lseg_ne lseg_out lseg_parallel lseg_perp lseg_recv lseg_send lseg_vertical ltrim macaddr_and macaddr_cmp macaddr_eq macaddr_ge macaddr_gt macaddr_in macaddr_le macaddr_lt macaddr_ne macaddr_not macaddr_or macaddr_out macaddr_recv macaddr_send makeaclitem masklen max md5(MD5加密算法安全性低,存在安全风险,建议使用更安全的加密算法) mic_to_big5 mic_to_euc_cn mic_to_euc_jp mic_to_euc_kr mic_to_euc_tw mic_to_iso mic_to_koi8r mic_to_latin1 mic_to_latin2 mic_to_latin3 mic_to_latin4 mic_to_sjis mic_to_win1250 mic_to_win1251 mic_to_win866 min mktinterval money mul_d_interval name nameeq namege namegt nameiclike nameicnlike nameicregexeq nameicregexne namein namele namelike namelt namene namenlike nameout namerecv nameregexeq nameregexne namesend neqjoinsel neqsel network_cmp network_eq network_ge network_gt network_le network_lt network_ne network_sub network_subeq network_sup network_supeq nlikejoinsel nlikesel numeric numeric_abs numeric_accum numeric_add numeric_avg numeric_avg_accum numeric_avg_collect numeric_cmp numeric_collect numeric_div numeric_div_trunc numeric_eq numeric_exp numeric_fac numeric_ge numeric_gt numeric_in numeric_inc numeric_larger numeric_le numeric_ln numeric_log numeric_lt numeric_mod numeric_mul numeric_ne numeric_out numeric_power numeric_recv numeric_send numeric_smaller numeric_sortsupport numeric_sqrt numeric_stddev_pop numeric_stddev_samp numeric_sub numeric_transform numeric_uminus numeric_uplus numeric_var_pop numeric_var_samp numerictypmodin numerictypmodout numrange_subdiff oid oideq oidge oidgt oidin oidlarger oidle oidlt oidne oidout oidrecv oidsend oidsmaller oidvectoreq oidvectorge oidvectorgt oidvectorin oidvectorle oidvectorlt oidvectorne oidvectorout oidvectorrecv oidvectorsend oidvectortypes on_pb on_pl on_ppath on_ps on_sb on_sl opaque_in opaque_out ordered_set_transition overlaps overlay path path_add path_add_pt path_center path_contain_pt path_distance path_div_pt path_in path_inter path_length path_mul_pt path_n_eq path_n_ge path_n_gt path_n_le path_n_lt path_npoints path_out path_recv path_send path_sub_pt percentile_cont percentile_cont_float8_final percentile_cont_interval_final pg_char_to_encoding pg_cursor pg_encoding_max_length pg_encoding_to_char - - - pg_node_tree_in pg_node_tree_out pg_node_tree_recv pg_node_tree_send pg_prepared_statement pg_prepared_xact - - pg_show_all_settings pg_stat_get_bgwriter_stat_reset_time pg_stat_get_buf_fsync_backend pg_stat_get_checkpoint_sync_time pg_stat_get_checkpoint_write_time pg_stat_get_db_blk_read_time pg_stat_get_db_blk_write_time pg_stat_get_db_conflict_all pg_stat_get_db_conflict_bufferpin pg_stat_get_db_conflict_snapshot pg_stat_get_db_conflict_startup_deadlock pg_switch_xlog xpath pg_timezone_abbrevs pg_timezone_names pg_stat_get_wal_receiver plpgsql_call_handler plpgsql_inline_handler plpgsql_validator point_above point_add point_below point_distance point_div point_eq point_horiz point_in point_left point_mul point_ne point_out point_recv point_right point_send point_sub point_vert poly_above poly_below poly_center poly_contain poly_contain_pt poly_contained poly_distance poly_in poly_left poly_npoints poly_out poly_overabove poly_overbelow poly_overlap poly_overleft poly_overright poly_recv poly_right poly_same poly_send polygon position positionjoinsel positionsel postgresql_fdw_validator pow power prsd_end prsd_headline prsd_lextype prsd_nexttoken prsd_start pt_contained_circle pt_contained_poly query_to_xml query_to_xml_and_xmlschema query_to_xmlschema quote_ident quote_literal quote_nullable radians radius random range_adjacent range_after range_before range_cmp range_contained_by range_contains range_contains_elem range_eq range_ge range_gist_compress range_gist_consistent range_gist_decompress range_gist_penalty range_gist_picksplit range_gist_same range_gist_union range_gt range_in range_intersect range_le range_lt range_minus range_ne range_out range_overlaps range_overleft range_overright range_recv range_send range_typanalyze range_union rank record_eq record_ge record_gt record_in record_le record_lt record_ne record_out record_recv record_send regclass regclassin regclassout regclassrecv regclasssend regconfigin regconfigout regconfigrecv regconfigsend regdictionaryin regdictionaryout regdictionaryrecv regdictionarysend regexeqjoinsel regexeqsel regexnejoinsel regexnesel regexp_matches regexp_replace regexp_split_to_array regexp_split_to_table regoperatorin regoperatorout regoperatorrecv regoperatorsend regoperin regoperout regoperrecv regopersend regprocedurein regprocedureout regprocedurerecv regproceduresend regprocin regprocout regprocrecv regprocsend regr_avgx regr_avgy regr_count regr_intercept regr_r2 regr_slope regr_sxx regr_sxy regr_syy regtypein regtypeout regtyperecv regtypesend reltime reltimeeq reltimege reltimegt reltimein reltimele reltimelt reltimene reltimeout reltimerecv reltimesend repeat replace reverse RI_FKey_cascade_del RI_FKey_cascade_upd RI_FKey_check_ins RI_FKey_check_upd RI_FKey_noaction_del RI_FKey_noaction_upd RI_FKey_restrict_del RI_FKey_restrict_upd RI_FKey_setdefault_del RI_FKey_setdefault_upd RI_FKey_setnull_del RI_FKey_setnull_upd right round row_number row_to_json rpad rtrim scalargtjoinsel scalargtsel scalarltjoinsel scalarltsel schema_to_xml schema_to_xml_and_xmlschema schema_to_xmlschema session_user set_bit set_byte set_config set_masklen shift_jis_2004_to_euc_jis_2004 shift_jis_2004_to_utf8 sjis_to_euc_jp sjis_to_mic sjis_to_utf8 smgrin smgrout spg_kd_choose spg_kd_config spg_kd_inner_consistent spg_kd_picksplit spg_quad_choose spg_quad_config spg_quad_inner_consistent spg_quad_leaf_consistent spg_quad_picksplit spg_text_choose spg_text_config spg_text_inner_consistent spg_text_leaf_consistent spg_text_picksplit spgbeginscan spgbuild spgbuildempty spgbulkdelete spgcanreturn spgcostestimate spgendscan spggetbitmap spggettuple spginsert spgmarkpos spgoptions spgrescan spgrestrpos spgvacuumcleanup stddev stddev_pop stddev_samp string_agg string_agg_finalfn string_agg_transfn strip sum suppress_redundant_updates_trigger table_to_xml table_to_xml_and_xmlschema table_to_xmlschema tan text text_ge text_gt text_larger text_le text_lt text_pattern_ge text_pattern_gt text_pattern_le text_pattern_lt text_smaller textanycat textcat texteq texticlike texticnlike texticregexeq texticregexne textin textlike textne textnlike textout textrecv textregexeq textregexne textsend thesaurus_init thesaurus_lexize tideq tidge tidgt tidin tidlarger tidle tidlt tidne tidout tidrecv tidsend tidsmaller time time_cmp time_eq time_ge time_gt time_hash time_in time_larger time_le time_lt time_mi_interval time_mi_time time_ne time_out time_pl_interval time_recv time_send time_smaller time_transform timedate_pl timemi timepl timestamp timestamp_cmp timestamp_cmp_date timestamp_cmp_timestamptz timestamp_eq timestamp_eq_date timestamp_eq_timestamptz timestamp_ge timestamp_ge_date timestamp_ge_timestamptz timestamp_gt timestamp_gt_date timestamp_gt_timestamptz timestamp_hash timestamp_in timestamp_larger timestamp_le timestamp_le_date timestamp_le_timestamptz timestamp_lt timestamp_lt_date timestamp_lt_timestamptz timestamp_mi timestamp_mi_interval timestamp_ne timestamp_ne_date timestamp_ne_timestamptz timestamp_out timestamp_pl_interval timestamp_recv timestamp_send timestamp_smaller timestamp_sortsupport timestamp_transform timestamptypmodin timestamptypmodout timestamptz timestamptz_cmp timestamptz_cmp_date timestamptz_cmp_timestamp timestamptz_eq timestamptz_eq_date timestamptz_eq_timestamp timestamptz_ge timestamptz_ge_date timestamptz_ge_timestamp timestamptz_gt timestamptz_gt_date timestamptz_gt_timestamp timestamptz_in timestamptz_larger timestamptz_le timestamptz_le_date timestamptz_le_timestamp timestamptz_lt timestamptz_lt_date timestamptz_lt_timestamp timestamptz_mi timestamptz_mi_interval timestamptz_ne timestamptz_ne_date timestamptz_ne_timestamp timestamptz_out timestamptz_pl_interval timestamptz_recv timestamptz_send timestamptz_smaller timestamptztypmodin timestamptztypmodout timetypmodin timetypmodout timetz timetz_cmp timetz_eq timetz_ge timetz_gt timetz_hash timetz_in timetz_larger timetz_le timetz_lt timetz_mi_interval timetz_ne timetz_out timetz_pl_interval timetz_recv timetz_send timetz_smaller timetzdate_pl timetztypmodin timetztypmodout timezone(2069) timezone(1159) timezone(2037) timezone (2070) timezone (1026) timezone (2038) tintervalct tintervaleq tintervalge tintervalgt tintervalin tintervalle tintervalleneq tintervallenge tintervallengt tintervallenle tintervallenlt tintervallenne tintervallt tintervalne tintervalout tintervalov tintervalrecv tintervalsame tintervalsend tintervalstart to_ascii(1845) to_ascii(1847) to_ascii(1846) trigger_in trigger_out ts_match_qv ts_match_tq ts_match_tt ts_match_vq ts_rank ts_rank_cd ts_rewrite ts_stat ts_token_type ts_typanalyze tsmatchjoinsel tsmatchsel tsq_mcontained tsq_mcontains tsquery_and tsquery_cmp tsquery_eq tsquery_ge tsquery_gt tsquery_le tsquery_lt tsquery_ne tsquery_not tsquery_or tsqueryin tsqueryout tsqueryrecv tsquerysend tsrange tsrange_subdiff tstzrange tstzrange_subdiff tsvector_cmp tsvector_concat tsvector_eq tsvector_ge tsvector_gt tsvector_le tsvector_lt tsvector_ne tsvector_update_trigger tsvector_update_trigger_column tsvectorin tsvectorout tsvectorrecv tsvectorsend txid_current txid_current_snapshot txid_snapshot_in txid_snapshot_out txid_snapshot_recv txid_snapshot_send txid_snapshot_xip txid_snapshot_xmax txid_snapshot_xmin txid_visible_in_snapshot uhc_to_utf8 unique_key_recheck unknownin unknownout unknownrecv unknownsend unnest utf8_to_big5 utf8_to_euc_cn utf8_to_euc_jis_2004 utf8_to_euc_jp utf8_to_euc_kr utf8_to_euc_tw utf8_to_gb18030 utf8_to_gbk utf8_to_iso8859 utf8_to_iso8859_1 utf8_to_johab utf8_to_koi8r utf8_to_koi8u utf8_to_shift_jis_2004 utf8_to_sjis utf8_to_uhc utf8_to_win uuid_cmp uuid_eq uuid_ge uuid_gt uuid_hash uuid_in uuid_le uuid_lt uuid_ne uuid_out uuid_recv uuid_send var_pop var_samp varbit varbit_in varbit_out varbit_recv varbit_send varbit_transform varbitcmp varbiteq varbitge varbitgt varbitle varbitlt varbitne varbittypmodin varbittypmodout varchar varchar_transform varcharin varcharout varcharrecv varcharsend varchartypmodin varchartypmodout variance void_in void_out void_recv void_send win_to_utf8 win1250_to_latin2 win1250_to_mic win1251_to_iso win1251_to_koi8r win1251_to_mic win1251_to_win866 win866_to_iso win866_to_koi8r win866_to_mic win866_to_win1251 xideq xideqint4 xidin xidout xidrecv xidsend xml xml_in xml_is_well_formed xml_is_well_formed_content xml_is_well_formed_document xml_out xml_recv xml_send xmlagg xmlcomment xmlconcat2 xmlexists xmlvalidate pg_notify - -
  • OPERATOR_HISTORY_TABLE OPERATOR_HISTORY_TABLE系统视图显示执行作业结束后的算子相关的记录。此数据是从内核中转储到系统视图中的数据。 表1 OPERATOR_HISTORY_TABLE的字段 名称 类型 描述 queryid bigint 语句执行使用的内部query_id。 pid bigint 后端线程id。 plan_node_id integer 查询对应的执行计划的plan node id。 plan_node_name text 对应于plan_node_id的算子的名称。 start_time timestamp with time zone 该算子处理第一条数据的开始时间。 duration bigint 该算子到结束时候总的执行时间(ms)。 query_dop integer 当前算子执行时的并行度。 estimated_rows bigint 优化器估算的行数信息。 tuple_processed bigint 当前算子返回的元素个数。 min_peak_memory integer 当前算子在数据库节点上的最小内存峰值(MB)。 max_peak_memory integer 当前算子在数据库节点上的最大内存峰值(MB)。 average_peak_memory integer 当前算子在数据库节点上的平均内存峰值(MB)。 memory_skew_percent integer 当前算子在数据库节点间的内存使用倾斜率。 min_spill_size integer 若发生下盘,数据库节点上下盘的最小数据量(MB),默认为0。 max_spill_size integer 若发生下盘,数据库节点上下盘的最大数据量(MB),默认为0。 average_spill_size integer 若发生下盘,数据库节点上下盘的平均数据量(MB),默认为0。 spill_skew_percent integer 若发生下盘,数据库节点间下盘倾斜率。 min_cpu_time bigint 该算子在数据库节点上的最小执行时间(ms)。 max_cpu_time bigint 该算子在数据库节点上的最大执行时间(ms)。 total_cpu_time bigint 该算子在数据库节点上的总执行时间(ms)。 cpu_skew_percent integer 数据库节点间执行时间的倾斜率。 warning text 主要显示如下几类告警信息: Sort/SetOp/HashAgg/HashJoin spill Spill file size large than 256MB Broadcast size large than 100MB Early spill Spill times is greater than 3 Spill on memory adaptive Hash table conflict 父主题: Operator
  • 注意事项 PQprepare创建一个为PQexecPrepared执行用的预备语句,本特性支持命令的重复执行,不需要每次都进行解析和规划。PQprepare仅在协议3.0及以后的连接中支持,使用协议2.0时,PQprepare将失败。 该函数从查询字符串创建一个名为stmtName的预备语句,该查询字符串必须包含一个SQL命令。stmtName可以是""来创建一个未命名的语句,在这种情况下,任何预先存在的未命名的语句都将被自动替换;否则,如果在当前会话中已经定义了语句名称,那么这就是一个错误。如果使用了任何参数,那么在查询中将它们称为$1,$2等。nParams是在paramTypes[]数组中预先指定类型的参数的数量。(当nParams为0时,数组指针可以为NULL) paramTypes[]通过OID指定要分配给参数符号的数据类型。如果paramTypes为NULL ,或者数组中的任何特定元素为零,服务器将按照对非类型化字面字符串的相同方式为参数符号分配数据类型。另外,查询可以使用数字高于nParams的参数符号;还将推断这些符号的数据类型。 通过执行SQLPREPARE语句,还可以创建与PQexecPrepared一起使用的预备语句。此外,虽然没有用于删除预备语句的libpq函数,但是SQL DEALLOCATE语句可用于此目的。
  • 参数说明 参数 参数说明 ctx 表示给定的上下文。 query 被执行的sql语句。 args 被执行sql语句需要绑定的参数。支持按位置绑定和按名称绑定,详情见如下示例。 opts 事务隔离级别和事务访问模式,其中事务隔离级别(opts.Isolation)支持范围为sql.LevelReadUncommitted,sql.LevelReadCommitted,sql.LevelRepeatableRead,sql.LevelSerializable。事务访问模式(opts.ReadOnly)支持范围为true(read only)和false(read write)。
  • GLOBAL_STAT_XACT_USER_TABLES 显示各节点命名空间中用户表的事务状态信息。 表1 GLOBAL_STAT_XACT_USER_TABLES字段 名称 类型 描述 node_name name 节点名称。 relid oid 表的OID。 schemaname name 此表的模式名。 relname name 表名。 seq_scan bigint 此表发起的顺序扫描数。 seq_tup_read bigint 顺序扫描抓取的活跃行数。 idx_scan bigint 此表发起的索引扫描数。 idx_tup_fetch bigint 索引扫描抓取的活跃行数。 n_tup_ins bigint 插入行数。 n_tup_upd bigint 更新行数。 n_tup_del bigint 删除行数。 n_tup_hot_upd bigint HOT更新行数(比如没有更新所需的单独索引)。 父主题: Object
  • PG_APP_WORKLOADGROUP_MAPPING PG_APP_WORKLOADGROUP_MAPPING系统表提供了数据库负载映射组的信息。 表1 PG_APP_WORKLOADGROUP_MAPPING字段 名称 类型 描述 oid oid 行标识符(隐含属性,必须明确选择)。 appname name 应用名称。 workload_gpname name 映射到的负载组名称。 父主题: 系统表
  • MY_SOURCE MY_SOURCE视图显示当前用户拥有的存储过程或函数的信息,且提供存储过程或函数定义的字段。该视图同时存在于PG_CATALOG和SYS Schema下。 表1 MY_SOURCE字段 名称 类型 描述 owner character varying(64) 存储过程或函数的所有者。 name character varying(64) 存储过程或函数名称。 text text 存储过程或函数的定义。 父主题: 系统视图
  • SUMMARY_STATIO_ALL_SEQUENCES SUMMARY_STATIO_ALL_SEQUENCES视图包含数据库内汇聚的数据库中每个序列的每一行,显示特定序列关于I/O的统计。 表1 SUMMARY_STATIO_ALL_SEQUENCES字段 名称 类型 描述 schemaname name 序列中模式名。 relname name 序列名。 blks_read numeric 从序列中读取的磁盘块数。 blks_hit numeric 序列中缓存命中数。 父主题: Cache/IO
  • SUMMARY_WORKLOAD_SQL_ELAPSE_TIME SUMMARY_WORKLOAD_SQL_ELAPSE_TIME用来统计数据库主节点上workload(业务)负载的SUID信息。 表1 SUMMARY_WORKLOAD_SQL_ELAPSE_TIME字段 名称 类型 描述 node_name name 节点名称。 workload name workload(业务负载)名称。 total_select_elapse bigint 总select的时间花费(单位:微秒)。 max_select_elapse bigint 最大select的时间花费(单位:微秒)。 min_select_elapse bigint 最小select的时间花费(单位:微秒)。 avg_select_elapse bigint 平均select的时间花费(单位:微秒)。 total_update_elapse bigint 总update的时间花费(单位:微秒)。 max_update_elapse bigint 最大update的时间花费(单位:微秒)。 min_update_elapse bigint 最小update的时间花费(单位:微秒)。 avg_update_elapse bigint 平均update的时间花费(单位:微秒)。 total_insert_elapse bigint 总insert的时间花费(单位:微秒)。 max_insert_elapse bigint 最大insert的时间花费(单位:微秒)。 min_insert_elapse bigint 最小insert的时间花费(单位:微秒)。 avg_insert_elapse bigint 平均insert的时间花费(单位:微秒)。 total_delete_elapse bigint 总delete的时间花费(单位:微秒)。 max_delete_elapse bigint 最大delete的时间花费(单位:微秒)。 min_delete_elapse bigint 最小delete的时间花费(单位:微秒)。 avg_delete_elapse bigint 平均delete的时间花费(单位:微秒)。 父主题: Workload
  • 示例 -- 创建目标表products和源表newproducts,并插入数据 openGauss=# CREATE TABLE products ( product_id INTEGER, product_name VARCHAR2(60), category VARCHAR2(60) ); openGauss=# INSERT INTO products VALUES (1501, 'vivitar 35mm', 'electrncs'); openGauss=# INSERT INTO products VALUES (1502, 'olympus is50', 'electrncs'); openGauss=# INSERT INTO products VALUES (1600, 'play gym', 'toys'); openGauss=# INSERT INTO products VALUES (1601, 'lamaze', 'toys'); openGauss=# INSERT INTO products VALUES (1666, 'harry potter', 'dvd'); openGauss=# CREATE TABLE newproducts ( product_id INTEGER, product_name VARCHAR2(60), category VARCHAR2(60) ); openGauss=# INSERT INTO newproducts VALUES (1502, 'olympus camera', 'electrncs'); openGauss=# INSERT INTO newproducts VALUES (1601, 'lamaze', 'toys'); openGauss=# INSERT INTO newproducts VALUES (1666, 'harry potter', 'toys'); openGauss=# INSERT INTO newproducts VALUES (1700, 'wait interface', 'books'); -- 进行MERGE INTO操作 openGauss=# MERGE INTO products p USING newproducts np ON (p.product_id = np.product_id) WHEN MATCHED THEN UPDATE SET p.product_name = np.product_name, p.category = np.category WHERE p.product_name != 'play gym' WHEN NOT MATCHED THEN INSERT VALUES (np.product_id, np.product_name, np.category) WHERE np.category = 'books'; MERGE 4 -- 查询更新后的结果 openGauss=# SELECT * FROM products ORDER BY product_id; product_id | product_name | category ------------+----------------+----------- 1501 | vivitar 35mm | electrncs 1502 | olympus camera | electrncs 1600 | play gym | toys 1601 | lamaze | toys 1666 | harry potter | toys 1700 | wait interface | books (6 rows) -- 删除表 openGauss=# DROP TABLE products; openGauss=# DROP TABLE newproducts;
  • 语法格式 MERGE [/*+ plan_hint */] INTO table_name [ partition_clause ] [ [ AS ] alias ] USING { { table_name | view_name } | subquery } [ [ AS ] alias ] ON ( condition ) [ WHEN MATCHED THEN UPDATE SET { column_name = { expression | subquery | DEFAULT } | ( column_name [, ...] ) = ( { expression | subquery | DEFAULT } [, ...] ) } [, ...] [ WHERE condition ] ] [ WHEN NOT MATCHED THEN INSERT { DEFAULT VALUES | [ ( column_name [, ...] ) ] VALUES ( { expression | subquery | DEFAULT } [, ...] ) [, ...] [ WHERE condition ] } ];
  • 参数说明 plan_hint子句 以/*+ */的形式在MERGE关键字后,用于对MERGE对应的语句块生成的计划进行hint调优,详细用法请参见章节使用Plan Hint进行调优。每条语句中只有第一个/*+ plan_hint */注释块会作为hint生效,里面可以写多条hint。 INTO子句 指定正在更新或插入的目标表。 table_name 目标表的表名。 partition_clause 指定分区MERGE操作: PARTITION { ( partition_name ) | FOR ( partition_value [, ...] ) } | SUBPARTITION { ( subpartition_name ) | FOR ( subpartition_value [, ...] ) } 关键字详见SELECT一节介绍。 如果value子句的值和指定分区不一致,会抛出异常。 示例详见CREATE TABLE SUBPARTITION。 alias 目标表的别名。 取值范围:字符串,符合标识符命名规范。 USING子句 指定源表,源表可以为表、视图或子查询。 ON子句 关联条件,用于指定目标表和源表的关联条件。不支持更新关联条件中的字段。 WHEN MATCHED子句 当源表和目标表中数据针对关联条件可以匹配上时,选择WHEN MATCHED子句进行UPDATE操作。 不支持更新系统表、系统列。 WHEN NOT MATCHED子句 当源表和目标表中数据针对关联条件无法匹配时,选择WHEN NOT MATCHED子句进行INSERT操作。 不支持INSERT子句中包含多个VALUES。 WHEN MATCHED和WHEN NOT MATCHED子句顺序可以交换,可以缺省其中一个,但不能同时缺省,不支持同时指定两个WHEN MATCHED或WHEN NOT MATCHED子句。 DEFAULT 用对应字段的缺省值填充该字段。 如果没有缺省值,则为NULL。 WHERE condition UPDATE子句和INSERT子句的条件,只有在条件满足时才进行更新操作,可缺省。不支持WHERE条件中引用系统列。不建议使用int等数值类型作为condition,因为int等数值类型可以隐式转换为bool值(非0值隐式转换为true,0转换为false),可能导致非预期的结果。
  • PG_ENUM PG_ENUM系统表包含显示每个枚举类型值和标签的记录。给定枚举类型的内部表示实际上是PG_ENUM里面相关行的OID。 表1 PG_ENUM字段 名称 类型 引用 描述 oid oid - 行标识符(隐含属性,必须明确选择)。 enumtypid oid PG_TYPE.oid 拥有这个枚举值的PG_TYPE记录的OID。 enumsortorder real - 这个枚举值在它的枚举类型中的排序位置。 enumlabel name - 这个枚举值的文本标签。 PG_ENUM行的OID跟着一个特殊规则:偶数的OID保证用和它们的枚举类型一样的排序顺序排序。也就是,如果两个偶数OID属于相同的枚举类型,那么较小的OID必须有较小enumsortorder值。奇数OID需要毫无关系的排序顺序。这个规则允许枚举比较例程在许多常见情况下避开目录查找。创建和修改枚举类型的例程只要可能就尝试分配偶数OID给枚举值。 当创建了一个枚举类型时,它的成员赋予了排序顺序位置1到n。但是随后添加的成员可能会分配enumsortorder的负值或分数值。对这些值的唯一要求是它们要正确的排序和在每个枚举类型中唯一。 父主题: 系统表
  • 语法格式 [ WITH [ RECURSIVE ] with_query [, ...] ] SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] { * | {expression [ [ AS ] output_name ]} [, ...] } INTO [ [ GLOBAL | LOCAL ] [ TEMPORARY | TEMP ] | UNLOGGED ] [ TABLE ] new_table [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ WINDOW {window_name AS ( window_definition )} [, ...] ] [ { UNION | INTERSECT | EXCEPT | MINUS } [ ALL | DISTINCT ] select ] [ ORDER BY {expression [ [ ASC | DESC | USING operator ] | nlssort_expression_clause ] [ NULLS { FIRST | LAST } ]} [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start [ ROW | ROWS ] ] [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ] [ {FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT |WAIT N]} [...] ];
共100000条
提示

您即将访问非华为云网站,请注意账号财产安全