11月6日,由腾讯云主办的首届“DB—数据库诊断大赛”决赛在腾讯Techo开发者大会活动现场圆满落幕,此前800多名选手经过初赛的激烈角逐后,共有30位进入本次决赛。经过腾讯云智能数据库管家DBbrain的智能打分,终雷孝龙以78分的成绩摘得本次奖杯,亚军和季军则分别由赵文新和王加雷获得。
腾讯云数据库负责人林晓斌(丁奇)为获奖者颁奖
(一等奖得主远程参赛,所以很遗憾没有颁奖照片)
以下是本次比赛全部获奖名单:
本次“DB—数据库诊断大赛” 的规则是由参赛者领取的腾讯云账号,通过在云服务器上模拟业务访问,造成每组的MySQL云数据库上出现故障、异常、隐患等现象,参赛者需根据云基础监控和日志信息,在不降低业务访问量的情况下,对业务代码或数据库进行优化。
比赛一大亮点是由腾讯云数据库智能管家DBbrain担任评审,对每个参赛用户的实例进行实时健康巡检和智能打分。比赛结束后,按照DBbrain的健康打分确定排名,分数相同则用时短者获胜。DBbrain利用机器学习、大数据等技术吸收了大量 DBA 成熟经验,其作为智能评审官,不仅确保了比赛结果的公平性、公正性和权威性,同时DBbrain也跟选手同场竞技,真正实现了“故障秒级发现、优化秒级输出、性能明显提升”的7*24数据库无人值守的新模式,充分展现了DBbrain的强大数据库诊断和优化的能力。
决赛由MySQL之父 Michael Widenius亲自为获奖者颁发奖品,林晓斌、周彦伟、赵振平等业界大咖也就队伍的优化思路进行了点评,DBbrain的能力获得了大家的一致认可。
诊断赛的题目均是从DBbrain为云上客户提供数据库智能优化服务中遇到的实际业务问题提炼出来的,且DBbrain能够实时给出优化建议。通过本次比赛也不难看出,DBbrain对用户有着不可替代的价值。
今天,数据君也为大家带来了决赛的赛题解析和建议优化思路,有兴趣的朋友可以关注“腾讯云数据库”官方微信,回复“赛题复现”,按照指示即可进行比赛场景复现,亲手体验哦~
初赛赛题解析请点击右侧文字跳转阅读:800人参赛只有1人全部答对,题目却是现实中发生过的故障?
一、赛题设置
显示不完全的代码,请左右滑动阅读。
原表结构
create table region (
regionkey integer not null,
name varchar(25) not null,
comment varchar(152),
primary key(regionkey)
);
create table nation (
nationkey integer not null,
name varchar(25) not null,
regionkey integer not null,
comment varchar(152),
primary key(nationkey)
);
create tablecustomer (
custkey integer not null,
name varchar(25) CHARACTER SET utf8 COLLATEutf8_bin not null,
address varchar(40) not null,
nationkey integer not null,
phone varchar(15) not null,
acctbal decimal(15,2) not null,
mktsegment varchar(10) not null,
comment varchar(117) not null,
primary key(custkey)
);
create tableorders (
orderkey integer not null,
custkey integer not null,
orderstatus varchar(1) not null,
totalprice decimal(15,2) not null,
orderdate date not null,
orderpriority varchar(15) not null,
clerk varchar(15) not null,
shippriority integer not null,
comment varchar(79) not null,
primary key(orderkey)
);
原始select1语句
select c.custkey, c.phone,sum(o.totalprice) totalprice
from nation n
inner join customer c on c.nationkey = n.nationkey
inner join orders o on o.clerk = c.name
where n.name = "CHINA" and c.mktsegment ="HOUSEHOLD" and c.phone like "28-520%"
group byc.custkey, c.phone
执行计划
原始select2语句
select *
from (
select custkey, orderdate, sum(totalprice) as totalprice
from orders
group by custkey, orderdate
)
where orderdate= "2019-08-01"
执行计划
原始select3语句
select c.custkey, sum(o.totalprice)totalprice
from customer c
left join orders o on o.custkey = c.custkey
where c.phone like "33-64%" and c.name likeconcat("Customer#00003", "%")
group byc.custkey
执行计划
原始select4语句
select c.custkey, c.phone
from nation n
inner join customer c on c.nationkey = n.nationkey
where n.name = "CHINA" and exists (
select 1 from orders o where o.custkey = c.custkey and o.orderdate ="1998-08-11"
)
执行计划
二、赛题解析
优化后的表结构
CREATETABLE`region` (
`regionkey`int(11) NOTNULL,
`name`varchar(25) NOTNULL,
`comment`varchar(152) DEFAULTNULL,
PRIMARY KEY (`regionkey`)
)
CREATETABLE`nation` (
`nationkey`int(11) NOTNULL,
`name`char(25) NOTNULL,
`regionkey`int(11) NOTNULL,
`comment`varchar(152) DEFAULTNULL,
PRIMARY KEY (`nationkey`),
KEY`index_0` (`name`)
)
CREATETABLE`customer` (
`custkey`int(11) NOTNULL,
`name`varchar(25) CHARACTERSET utf8 COLLATE utf8_bin NOTNULL,
`address`varchar(40) NOTNULL,
`nationkey`int(11) NOTNULL,
`phone`char(15) NOTNULL,
`acctbal`decimal(15,2) NOTNULL,
`mktsegment`char(10) NOTNULL,
`comment`varchar(117) NOTNULL,
PRIMARY KEY (`custkey`),
KEY`index_1` (`phone`,`nationkey`,`name`),
KEY`index_2` (`nationkey`),
KEY`index_0` (`name`,`phone`)
)
CREATETABLE`orders` (
`orderkey`int(11) NOTNULL,
`custkey`int(11) NOTNULL,
`orderstatus`varchar(1) NOTNULL,
`totalprice`decimal(15,2) NOTNULL,
`orderdate`dateNOTNULL,
`orderpriority`char(15) NOTNULL,
`clerk`char(15) NOTNULL,
`shippriority`int(11) NOTNULL,
`comment`varchar(79) NOTNULL,
PRIMARY KEY (`orderkey`),
KEY`index_0` (`orderdate`,`custkey`,`totalprice`),
KEY`index_3` (`clerk`,`totalprice`),
KEY`index_1` (`custkey`,`totalprice`)
)
优化后的select1语句
select c.custkey, c.phone, sum(o.totalprice) totalprice
from nation n
inner join customer c on c.nationkey = n.nationkey
inner join orders o on o.clerk = c.name COLLATE utf8_bin
where n.name = 'CHINA'and c.mktsegment = 'HOUSEHOLD'and c.phone like'28-520%'
groupby c.custkey, c.phone
执行计划
优化后的select2语句
SELECT
`t`.`custkey`,
`t`.`orderdate`,
SUM(`t`.`totalprice`) AS`totalprice`
FROM
`dbaas`.`orders`AS`t`
WHERE
`t`.`orderdate` = '2019-08-01'
GROUPBY
`t`.`custkey`,
`t`.`orderdate`
执行计划
优化后的select3语句
select c.custkey, sum(o.totalprice)totalprice
from customer c
left join orders o on o.custkey = c.custkey
where c.phone like "33-64%" and c.name like concat("Customer#00003","%")
group by c.custkey
执行计划
优化后的select4语句
SELECT
`t1`.`custkey`,
`t1`.`phone`
FROM
(
SELECT
*
FROM
`dbaas`.`nation`AS`t`
WHERE
`t`.`name` = 'CHINA'
) AS`t0`
INNER JOIN`dbaas`.`customer`AS`t1`ON`t0`.`nationkey` = `t1`.`nationkey`
INNER JOIN (
SELECT
`t2`.`custkey`
FROM
`dbaas`.`orders`AS`t2`
WHERE
`t2`.`orderdate` = '1998-08-11'
GROUPBY
`t2`.`custkey`
) AS`t5`ON`t1`.`custkey` = `t5`.`custkey`
执行计划
三、DBbrain