GBase 8a集群视图有哪些使用限制?

使用限制:
(1)视图名不能和现有表名重复
(2)创建视图时SELECT语句必须引用表或视图,且引用的表或视图必须存在
(3)视图所引用的表不能是临时表
(4)创建视图时SELECT语句不能使用系统或用户变量
(5)创建视图时SELECT语句中不能包含子查询
(6)创建视图时不能使用预处理语句参数,存储过程中的参数或局部变量
(7)在存储过程中不能修改ALTER视图
(8)不能给视图添加索引
(9)不能对视图进行INSERT、UPDATE和DELETE操作

如何修改审计日志的表结构?

审计日志表表结构
11.5_r12.4_R1.1版本对审计日志表表结构增加了4列。
原表结构:
start_time 开始执行的时间
user_host 登陆的用户名和host
query_time sql 执行的时间
rows 返回结果集行数
db sql 执行的当前数据库名
sql_text sql 内容
conn_type 用户登陆方式(CAPI、ODBC、JDBC、ADO)

审计日志表新增列的内容如下:
Taskid 全局唯一的任务号
End_time SQL执行结束的时间
Sql_type 标识SQL类型,DDL,DML,DQL,OTHERS
Status 标识SQL执行成功还是失败,SUCCESS,FAILED

项目上手动修改表结构。

修改审计日志表结构的方法
1)由于审计日志表是系统表,需要手工修改每个节点gcluster和gnode的审计日志表的表结构
2)修改审计日志表结构时需要关闭审计日志功能,set global audit_log=off;
3)修改审计日志表结构之前需要执行:set sql_mode=’’;
4)修改表结构有两种方法

  • 方法一,直接在原表上增加列

    Alter self table audit_log add column taskid bigint not null first;
    Alter self table audit_log add column end_time timestamp not null after start_time;
    Alter self table audit_log add column sql_type mediumtext not null after sql_text;
    Alter self table audit_log add column status mediumtext not null after sql_type;

  • 方法二,创建新表,倒数据后,替换原表

    Taskid bigint not null,
    Start_time timestamp not null,
    End_time timestamp not null,
    User_host mediumtext not null,
    Query_time time not null,
    Rows integer not null,
    Db varchar(512) not null,
    Sql_text mediumtext not null,
    Sql_type mediumtext not null,
    Status mediumtext not null,
    Conn_type mediumtext not null
    ) engine =gssys character set utf8 comment=’Audit log’;
    Insert into audit_log_new(start_time, user_host, query_time, rows, db, sql_text, conn_type) select * from audit_log;
    Alter self table audit_log rename to audit_log_bak;
    Alter self table audit_log_new rename to audit_log;
    5)替换完成后需要重新开启审计日志功能: set global audit_log=on;

字符可以使用ascii函数获取其ascii码,但中文在utf8编码下一个中文占3个字节,无法通过ascii函数获取其ascii编码,有什么办法解决吗?

使用ord函数获取中文的ascii码,可参考SQL手册中ORD(str)函数的说明。

gbase> select ord('李');
 +------------+
 | ord('李')  |
 +------------+
 |   15113614 |
 +------------+
 1 row in set (Elapsed: 00:00:00.00)

 gbase> select char(ord('李'));
 +------------------+
 | char(ord('李')) |
 +------------------+
 | 李         |
 +------------------+
1 row in set (Elapsed: 00:00:00.00) 

删除数据能否回收rowid?

由于shrink space时,rowid回收,如果不含索引,回收的粒度是DC,即所有被delete的DC对应的rowid都能回收。
以下是做的简单测试:
(1)gnone层总行数6001215

gbase> select count(*) from lineitem;
+----------+
| count(*) |
+----------+
|  6001215 |
+----------+
1 row in set (Elapsed: 00:00:00.14)
gbase> select min(rowid),max(rowid) from lineitem;
+------------+------------+
| min(rowid) | max(rowid) |
+------------+------------+
|          0 |    6001214 |
+------------+------------+
1 row in set (Elapsed: 00:00:00.51)

(2)删除中间1个DC的数据

gbase> delete from lineitem where rowid> 65535 and rowid <2*65536;
Query OK, 65536 rows affected (Elapsed: 00:00:00.11)
gbase> alter table lineitem shrink space;
Query OK, 0 rows affected (Elapsed: 00:00:00.07)

(3)查看rowid

gbase> select min(rowid),max(rowid) from lineitem;
+------------+------------+
| min(rowid) | max(rowid) |
+------------+------------+
|          0 |    5935678 |
+------------+------------+
1 row in set (Elapsed: 00:00:00.45)

(4)插入数据后,查看rowid

gbase> insert into lineitem(l_comment) values('hello');
Query OK, 1 row affected (Elapsed: 00:00:00.40)
gbase> select rowid from lineitem where l_comment='hello';
+---------+
| rowid   |
+---------+
| 5935679 |
+---------+
1 row in set (Elapsed: 00:00:01.60)

如何限制集群sql下发的任务数目?

增加集群层参数配置限制集群sql下发的任务数目。
(1)查询当前集群已有用户及其优先级别select user, task_priority from gbase.user,明确后续参数的数值配置;
(2)gbase_use_priority_queue为优先级队列启用的开关,置1打开;
(3)将参数_gbase_priority_tasks设置为期望的相同优先级任务的最大下发数目(默认值为CPU核数,上限为64);
(4)将参数_gbase_priority_total_tasks设置为期望的全部优先级任务的最大下发数目(默认值为CPU核数的2倍,上限为128)。
注意:受控的任务语句只限于select查询及DML中的查询部分,上述参数均不支持show variables ...查询,修改后需重启集群生效。