返回首页

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

更新日期:2024年09月11日

+------------+-------------------------+
2 rows in set (Elapsed: 00:00:00.47)
注意
如果用户在GROUP BY 部分省略的列在分组中不是唯一的,请不要
使用这个特性,否则将得到不可预知的结果。
GROUP BY 优化
使用hint 优化GROUP BY:

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
873
create table users(u_id int,u_name char(10),birthday datetime,address
varchar(10));
create table products(p_id int,p_name char(10),price float,stocks int);
create table orders(o_id int,u_id int,p_id int,amount int);
insert into users values (0,'zhao','1990-12-29 12:00:00','中国.吉林.长春');
insert into users values (1,'qian','1990-12-29 12:00:00','中国.北京');
insert into users values (2,'sun','1990-12-29 12:00:00','中国.上海');
insert into users values (3,'li','1990-12-29 12:00:00','中国.天津');
insert into users values (4,'zhou','1990-12-29 12:00:00','中国.湖北.武汉');
insert into users values (5,'wu','1990-12-29 12:00:00','中国.湖南.长沙');
insert into users values (6,'zheng','1990-12-29 12:00:00','中国.河北.沧州');
insert into users values (7,'wang','1990-12-29 12:00:00','中国.辽宁.沈阳');
insert into users values (8,'zhao','1990-12-29 12:00:00','中国.云南.昆明');
insert into users values (9,'li','1990-12-29 12:00:00','中国.西藏.拉萨');
insert into orders values (600001,1,100010,2500);
insert into orders values (600002,3,100008,3500);
insert into orders values (600003,4,100009,500);
insert into orders values (600004,5,100007,5000);
insert into orders values (600005,9,100003,2510);
insert into orders values (600006,0,100004,10500);
insert into orders values (600007,3,100002,5500);
insert into orders values (600008,3,100001,6000);
insert into orders values (600009,4,100009,2100);
insert into orders values (600010,5,100001,1300);
insert into orders values (600011,6,100007,8900);
insert into orders values (600012,9,100008,2900);
insert into orders values (600013,2,100009,6900);
insert into orders values (600014,1,100002,3600);
insert into orders values (600015,1,100003,1500);
SELECT /*+ first_groupby */ distinct `users`.u_name , sum(orders.amount)
FROM
users,
orders
WHERE
users.u_id
=
orders.u_id
GROUP BY
`users`.u_name ORDER BY
`users`.u_name limit 3;
上面的sql 会先在orders 表上做group by 之后再去join users。

参数说明:轻量级死锁检测周期。
该参数属于SIGHUP 类型参数,
请参考表GUC 参数设置方式中对应设置方法进行设置。
取值范围:整型,最小值0,最大值1440,单位为分钟(min)
默认值:5min

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
1337

下列 CREATE FUNCTION 语句创建读取客户地址的例程:
CREATE FUNCTION read_address (lastname CHAR(15)) -- one argument
RETURNING CHAR(15), CHAR(15), CHAR(20), CHAR(15),CHAR(2)
CHAR(5); -- 6 items

DEFINE p_lname,p_fname, p_city CHAR(15);
--define each routine variable
DEFINE p_add CHAR(20);
DEFINE p_state CHAR(2);
DEFINE p_zip CHAR(5);

SELECT fname, address1, city, state, zipcode
INTO p_fname, p_add, p_city, p_state, p_zip
FROM customer
WHERE lname = lastname;

RETURN p_fname, lastname, p_add, p_city, p_state, p_zip;
--6 items
END FUNCTION;

DOCUMENT 'This routine takes the last name of a customer as',
--brief description
'its only argument. It returns the full name and address',
'of the customer.'

WITH LISTING IN 'pathname' -- modify this pathname according
-- to the conventions that your operating system requires

-- compile-time warnings go here
; -- end of the routine read_address