返回首页

gbase数据、南大通用产品文档:GBase8a

更新日期:2024年09月11日

使用unixODBC 访问GBase 数据库时出现段错误 ........
78

在该步骤中可以设置rebalance 任务的优先级。先设置参数
gcluster_rebalancing_concurrent_count=0 阻止rebalance 任务被执行。然后利用
rebalance instance 把当前集群下所有表加入到gclusterdb.rebalancing_status 中。调整
完每个表的rebalance 任务的优先级后再设置gcluster_rebalancing_concurrent_count
为需要的并发数,
开始执行数据重分布。
详细步骤参考章节调整rebalance 任务优先
级。
操作步骤
步骤1:初始化hashmap:

GBase 8a MPP Cluster 产品手册
4 管理员指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
246
$ gccli -uroot
GBase client 9.5.3.17.117651. Copyright (c) 2004-2020, GBase.
All Rights
Reserved.
gbase> use vc vc1;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> initnodedatamap;
Query OK, 0 rows affected, 5 warnings (Elapsed: 00:00:01.45)
步骤2:执行数据重分布:
gbase> show variables like '%rebalanc%';
+-------------------------------------------------------+-----------+
| Variable_name
| Value
|
+-------------------------------------------------------+-----------+
| _t_gcluster_rebalance_mirror_node
| 0
|
| gcluster_load_rebalance_seed
| 5
|
| gcluster_rebalancing_concurrent_count
| 5
|
| gcluster_rebalancing_ignore_mirror
| OFF
|
| gcluster_rebalancing_immediate_recover_internal_table | OFF
|
| gcluster_rebalancing_parallel_degree
| 4
|
| gcluster_rebalancing_random_table_quick_mode
| 1
|
| gcluster_rebalancing_step
| 100000000 |
| gcluster_rebalancing_update_status_on_drop_table
| ON
|
+-------------------------------------------------------+-----------+
9 rows in set (Elapsed: 00:00:00.24)
gbase> rebalance database demo;
Query OK, 2 rows affected (Elapsed: 00:00:01.45)
查看rebalance 状态:
gbase> select index_name, status, percentage
from gclusterdb.rebalancing_status;
+------------+-----------+------------+
| index_name | status
| percentage |
+------------+-----------+------------+
| demo.t
| COMPLETED |
100 |
| demo.tt
| COMPLETED |
100 |
+------------+-----------+------------+
2 rows in set (Elapsed: 00:00:00.04)
gbase> quit
Bye

GBase 8a MPP Cluster 产品手册
4 管理员指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
247

语法:
func(expr)over([partition_clause][order_by_clause][windowing_clause]
OLAP 函数中开窗子句:[windowing_clause]子句
使用范围和具体语法如下:
支持windowing_clause 的OLAP func 函数有:sum、avg、count、max、min,不支
持distinct 关键字。
windowing_cluase 语法图如下





关键字说明:
Rows 指定行的范围
Range 指定值的范围
Unbounded 无限
Preceding 向上,减去,提前

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 590
Following 向下,加上,
延后
Current row 当前行
示例:
表结构:create table t(a int,b int,c int,d datetime);
示例以a 列数据分组,以b 列或者d 列数据排序,输出同一分组内开窗子句指定范
围的c 列累加和sum(c)
需提前打开支持子句的控制参数:
set _t_gbase_new_window_function_support=1
示例1:指定行范围的窗口,从当前行的前一行,到当前行。
gbase> select a,b,c,sum(c)over(partition by a order by b,c rows between 1 preceding and
current row) as 'sum(c)' from t;
+------+------+------+--------+
| a | b | c | sum(c) |
+------+------+------+--------+
| 2 | 1 | 1 | 1 |
| 2 | 2 | 1 | 2 |
| 1 | 1 | 2 | 2 |
| 1 | 2 | 4 | 6 |
| 1 | 3 | 5 | 9 |
+------+------+------+--------+
5 rows in set (Elapsed: 00:00:00.21)
示例2:指定行范围的窗口,从当前行的前一行,到当前行的后一行。
gbase> select a,b,c,sum(c)over(partition by a order by b,c rows between 1 preceding and
1 following) as 'sum(c)' from t;
+------+------+------+--------+
| a | b | c | sum(c) |
+------+------+------+--------+
| 2 | 1 | 1 | 2 |
| 2 | 2 | 1 | 2 |
| 1 | 1 | 2 | 6 |

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 591
| 1 | 2 | 4 | 11 |
| 1 | 3 | 5 | 9 |
+------+------+------+--------+
5 rows in set (Elapsed: 00:00:00.07)
示例3:
指定值范围的窗口,
当前行数值列
(b 列)
的值为x,
窗口为b 列值在 [
(x-2),x
]
闭区间范围,输出同组该范围内c 列的累加和。
gbase> select a,b,c,sum(c)over(partition by a order by b range between 2 preceding and
current row) as 'sum(c)' from t;
+------+------+------+--------+
| a | b | c | sum(c) |
+------+------+------+--------+
| 2 | 1 | 1 | 1 |
| 2 | 2 | 1 | 2 |
| 1 | 1 | 2 | 2 |
| 1 | 2 | 4 | 6 |
| 1 | 3 | 5 | 11 |
+------+------+------+--------+
5 rows in set (Elapsed: 00:00:00.10)
示例4:
指定值范围的窗口,
当前行的日期列d 日期值为x,
窗口为d 列日期值在 [
x
的前2 天,x 的后3 天 ] 闭区间的范围,输出同组该范围内c 列的累加和。
gbase> select a,d,c,sum(c)over(partition by a order by d range between 2 preceding and
3 following) as 'sum(c)' from t;
+------+---------------------+------+--------+
| a | d | c | sum(c) |
+------+---------------------+------+--------+
| 2 | 2010-10-10 10:00:00 | 1 | 2 |
| 2 | 2010-10-10 10:01:00 | 1 | 2 |
| 1 | 2010-10-08 10:00:00 | 2 | 6 |
| 1 | 2010-10-11 06:00:00 | 4 | 9 |
| 1 | 2010-10-12 10:00:00 | 5 | 9 |
+------+---------------------+------+--------+

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 592
5 rows in set (Elapsed: 00:00:00.36)
示例5:
指定值范围的窗口,
当前行的日期列d 日期值为x,
窗口为d 列日期值在 [ 行
首,x 的后3 分钟 ] 闭区间的范围,输出同组该范围内c 列的累加和。
gbase> select a,d,c,sum(c)over(partition by a order by d range between unbounded
preceding and interval 3 minute following) as 'sum(c)' from t;
+------+---------------------+------+--------+
| a | d | c | sum(c) |
+------+---------------------+------+--------+
| 1 | 2010-10-08 10:00:00 | 2 | 2 |
| 1 | 2010-10-11 06:00:00 | 4 | 6 |
| 1 | 2010-10-12 10:00:00 | 5 | 11 |
| 2 | 2010-10-10 10:00:00 | 1 | 2 |
| 2 | 2010-10-10 10:01:00 | 1 | 2 |
+------+---------------------+------+--------+
5 rows in set (Elapsed: 00:00:00.07)

使用约束:
1.
_t_gbase_new_window_function_support 参数为控制支持
windowing_clause 子句的参数,
参数值默认为0,
不支持windowing_clause 子句,
设置为1 时支持windowing_clause 子句。
set _t_gbase_new_window_function_support=1
2.
不支持windowing_clause 子句情况下,开窗方式是固定的,范围是:
Range between unbounded preceding and current row
3.
Partition 子句为空,则不分组,即说明全部数据为一组;order
by 子句为
空,则每个分组中的所有数据不排序,即一个分组就是一个“子窗口”。
4.
between bound1 and bound2
bound1 定义窗口的起始位置,bound2 定义窗口的结束位置。
单独一个bound 时,为起始位置的定义,结束位置默认为current row,如:
select a,b,c,sum(c)over(partition by a order by b range 2 preceding) as 'sum(c)' from t;

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 593
5.
unbounded preceding
指明起始位置,即当前分组中的行首,不能出现在bound2 中。
6.
unbounded following
指明结束位置,即当前分组中的行尾,不能出现在bound1 中。
7.
current row
指明起始或结束位置为当前行。
8.
在如下情况时,order by 关键字后可以有多个表达式:
Range between unbounded preceding and current row
Range between unbounded preceding and unbounded following
Range between current row and current row
Range between current row and unbounded following
9.
value_expr preceding | value_expr following
起始位置为value_expr following 时,则结束位置应为value_expr following;
结束位置为value_expr preceding 时,则起始位置应为value_expr preceding。
10.
rows 关键字后接value_expr 时,不支持interval 子句
value_expr 为num 时,标识了行的偏移量,为数值常量,正整数(四舍五入)。不
可为负数、数值函数、表列。
11.
range 关键字后接value_expr 时支持interval 子句,
且order
by 后只能有
一个表达式:
value_expr 为num 时,order by 后的表达式只能为数值或日期(时间)类型;
value_expr 为interval 子句时,order by 后的表达式只能为日期(时间)类型;
value_expr 为num 时,标识了行的偏移量,为数值常量,正整数(四舍五入)。不
可为负数、数值函数、表列。
12.
range 关键字,order by 后接唯一表达式用于计算窗口范围时:
排序存在null 值且在行首时,除非unbounded preceding,该行不计入窗口范围;
排序存在null 值且在行尾时,除非unbounded following,该行不计入窗口范围;
当前行为null 值,除非unbounded preceding/following,窗口范围仅为该行。

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 594
13.
日期(时间)类型的支持范围:date、datetime 和timestamp。


ROWID 函数
ROWID 为转换函数。
功能描述
ROWID 是表中记录的唯一标识,功能与主键类似,由server 自动维护,不实际存
储。
使用说明
实现了两种语法:伪列形式和函数形式(两种写法完全等价,不区分大小写)。其
中,函数形式为ROWID(表名)。
示例
SELECT *, ROWID, ROWID(t1) FROM t1;
SELECT * FROM t1 WHERE ROWID = 1;
功能说明

ROWID 返回类型为BIGINT,从0 开始排号;

ROWID 相当于server 给表自动添加的伪列,可以查询及使用,由server 自动
维护,不实际存储,不需要也不允许用户进行管理(如修改或创建索引等);


ROWID 作为保留字使用,不允许使用ROWID 作为任何数据对象的名称(不论大
小写及是否有单撇);

DML 不会影响原有数据的ROWID;

性能方面,ROWID 与常量的简单比较,如...WHERE ROWID = 1,可以使用智能
索引对dc 进行过滤,支持的比较类型包括:>,>=,<,<=,=,<>,IS
NULL,
IS NOT NULL,BETWEEN,NOT BETWEEN;

仅Express 引擎支持ROWID,对于Express 引擎不支持的语句,GBase 标准引
擎执行时(如含有ROWID)会报错。外部表由于不走Express 引擎,故外部表
不支持ROWID。
示例
示例1:ROWID, ROWID(t1)

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 595
gbase> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected

gbase> CREATE TABLE t1(i int, j int);
Query OK, 0 rows affected

gbase> INSERT INTO t1 VALUES(2,1),(2,3),(2,3),(2,5),(3,2),(3,2),(3,2),(3,4),(3,1),(3,5);
Query OK, 10 rows affected
Records: 10 Duplicates: 0 Warnings: 0

gbase> SELECT *, ROWID, ROWID(t1) FROM t1;
+------+------+-------+-------+
| i | j | ROWID | rowid |
+------+------+-------+-------+
| 2 | 1 | 0 | 0 |
| 2 | 3 | 1 | 1 |
| 2 | 3 | 2 | 2 |
| 2 | 5 | 3 | 3 |
| 3 | 2 | 4 | 4 |
| 3 | 2 | 5 | 5 |
| 3 | 2 | 6 | 6 |
| 3 | 4 | 7 | 7 |
| 3 | 1 | 8 | 8 |
| 3 | 5 | 9 | 9 |
+------+------+-------+-------+
10 rows in set
示例2:ROWID = 1
gbase> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected

gbase> CREATE TABLE t1(i int, j int);
Query OK, 0 rows affected

gbase> INSERT INTO t1 VALUES(2,1),(2,3),(2,3),(2,5),(3,2),(3,2),(3,2),(3,4),(3,1),(3,5);
Query OK, 10 rows affected
Records: 10 Duplicates: 0 Warnings: 0

gbase> SELECT * FROM t1 WHERE ROWID = 1;
+------+------+
| i | j |
+------+------+
| 2 | 3 |
+------+------+
1 row in set

GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 596