一、OpenGauss数据库简介
1.联机事务处理:OLTP,存储业务活动数据,常用行存;opengauss常用与该场景,默认行存;
2.OLAP:联机分析处理,存储历史数据;
常用列存,内存;
二、opengauss数据库在金融领域的使用实践;
1.openGauss:关系型数据库RDBMS;
2.特性
(1)高性能:故障切换时间小于10s;
(2)高可用
(3)高安全
(4)全开放
(5)易运维
3.与postgresql对比:
执行模型:opengauss采用线程;
并发控制:openGauss64位事务ID;
postgresql32位事务ID;
日志和检查点:opengauss采用增量checkpoint机制,极致RTO优化小于10s;postgresql采用全量;
多引擎:postgresql只支持行存;Opengauss支持行存,列存,内存引擎,
opengauss逻辑模块:
4.优化器:
rbo:基于规则;
cbo:基于代价
三、opengauss金融领域实验介绍:
实验流程:
1.登录数据库:
gsql -d(数据库名) postgres -p(端口号) 15400 -r(交互式);
2.创建数据库
create databASE finance(名称) encoding 'UTF8' (模板)TEMPLATE=TEMPLATE0;
3.连接数据库
-c finance(数据库名)
或者
\connect finance
4.创建模式
create scheme finance:
5.创建搜索路径:
set serch-path to fianace:
四、opengauss金融领域实验数据操作
1.创建客户信息表:
create table client(
c_id int primary key,
c_name varchar(60) not null,
c_mail char(30) unique,
c_id_card char(20) unque not null,
c_phone char
);
2.插入数据:
Insert into client(c_id,c_name,.c_email,c_id_card,c_phone)values
(111,‘张三’,'111@zs.com','11,'1111'),
(222,‘李四’,'222@ls.com','22,'2222');
opengauss中:
字符中的中文占三个字节;
3.添加约束
alter table finances_products(表名) add constraint c_p_mount(约束名) check((列)p_mount>=0)
4.条件查询
select * from client where c_id=111;
5.单表查询:
select c_id,c_name from client;
6.子查询:
select i1.c_id,i1.c_name from client i1 where c_id>111
7.聚合查询
select count(*) from client;
select avg(i_amount) from insurance
8.嵌套查询:
select i1.i_name,i1.i_amount,i1.i_person
from insurance i1
where i-amount>(select avg(i_amount) from insurance i2);
9.连接查询
(1)半连接:
查询用户编号在银行卡列表出现的用户的用户编号,姓名
select c_id,c_name from client
where exists (select * from bank_card where client.c_id=bank_card.c_id)
(2)反连接:
查询银行卡号不是“123”的用户编号,姓名:
select c_id,c_name from client
where c_id not in (select c_id from bank_card where b_number like'123');
(3)order by排序(默认升序):
select i_name from insurance where i_id>2 order by i_amount DESC;
(4)GROUP BY分组
select p_year,count(p_id) from finances group by p_year;
(5)having字句和with as查询;
select i_persion,count(i_amount) from insurance Group by i_persion having count(i_mount)=2;
with as:建立一临时表从中查询;
with temp as(select c_id from client )
select *from temp;
(6)创建视图:
create view v_client
as select c_id,c_name,c_id_card from client
where exists(select * from bank_card where client.c_id=bank_card.c_id);
(7)修改视图
在查询基础上过滤出信用卡用户
create or replace view v_client
as
select c_id,c_name, c_id_card from client
where exists(select * from bank_card
where client.c_id=bank_card.c_id
and bank_card.b_type='信用卡'
);
(8)修改视图名称:
alter view v_client rename to v_client_new;
物化视图:
创建后,数据直接从视图查,增量和全量之分;
(9)删除视图:
drop view v_client_new
(10)创建索引
create index idx_property on property(pro_c_id desc(设倒序默认升序),pro_income);
(11)重建索引:
drop index idx_property
create index idx_property on property(pro_c_id desc(倒序默认升序),pro_income);
(12)重命名索引
alter index idx_property rename to idx_property_temp;
(13)删除索引
drop index idx_property_temp;
(14)修改数据:
更新bank_card表中c_id<10且在client表存在的所有行,
设置b_type的值为借记卡;
update bank_card set bank_card.b_type='借记卡'
from client
where bank_card.b_c_id=client.c_id
and bank_card.b_c_id<10;
(15)删除fund表数据
delete from fund where f_id<3
(16)创建用户dbuser并赋予创建数据库的权限
create user dbuser with create identified by 'Gauss#3demo'(密码);
(17)授权用户对finance数据库bank_card表查询和插入权限
grant select,insert on finance.bank_card to dbuser
(18)将finance模式的所有权限授予dbuser用户;
grant all on schema finance to abuser;
(19)使用新用户连接finance数据库
gsql -d finance -U dbuser -p 15400 -r
(20)登录数据库finance
gsql -d finance -p 15400
(21)设置默认查询路径为finance
set serch_path to finance
(22)级联删除schema
drop schema finance cascade
评论(0)