请教大家两个问题, mysql 中有两个表:
1 )策略细则表,有三种策略, strategytype 为 1,2 或者 3 ,每种策略的 phonecode 等参数类型不一样:
CREATE TABLE iptv_ipandphonecode
(
codeid
int(11) NOT NULL,
regionname
char(255) NOT NULL,
areaname
char(255) NOT NULL,
strategytype
int NOT NULL,
codetype
int NOT NULL,
phonecode
char(255) default '' NULL,/format : YYYY.MM.DD HH24:MI:SS/
startcode
char(255) default '' NULL,/format : YYYY.MM.DD HH24:MI:SS/
endcode
char(255) default '' NULL,
upgradeflag
int NOT NULL,
remark
char(255) default '' NULL,
reserve1
int(11) default NULL,
reserve2
char(255) default NULL,
PRIMARY KEY (codeid
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
策略表,用来存储当前是否配置了升级策略:
CREATE TABLE iptv_strategyrelation
(
strategyid
int(11) NOT NULL,
codeid
int(11) NOT NULL,
remark
char(255) default NULL,
reserve1
int(11) default NULL,
reserve2
char(255) default NULL,
PRIMARY KEY (strategyid
,codeid
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
每次当有一个升级请求过来时候,都需要执行如下三个 SQL 查询语句,分别用来判断上报的参数是否在 iptv_ipandphonecode 表中存在,如果存在就认为符合策略,否则认为不符合策略:
select sb.codeid,sb.regionname,sb.strategytype,sb.codetype,sb.phonecode,sb.startcode,sb.endcode,sb.upgradeflag,sb.remark from iptv_ipandphonecode sb, iptv_strategyrelation sb2 where sb.codeid=sb2.codeid and sb.strategytype=3 and sb2.strategyid=?
select sb.codeid,sb.regionname,sb.strategytype,sb.codetype,sb.phonecode,sb.startcode,sb.endcode,sb.upgradeflag,sb.remark from iptv_ipandphonecode sb, iptv_strategyrelation sb2 where sb.codeid=sb2.codeid and sb.strategytype=2 and sb2.strategyid=?
select sb.codeid,sb.regionname,sb.strategytype,sb.codetype,sb.phonecode,sb.startcode,sb.endcode,sb.upgradeflag,sb.remark from iptv_ipandphonecode sb, iptv_strategyrelation sb2 where sb.codetype=3 and sb.codeid=sb2.codeid and sb.strategytype=1 and sb2.strategyid=?
在表 iptv_ipandphonecode 中的数据有十万条的时候,表 2 的对应条数也很多,导致上面的 SQL 级联查询很慢,请问有优化的方法吗?是否能把上面的三种查询方式统一起来?或者别的办法?
然后再导入第二张策略表: insert into iptv_strategyrelation(strategyid,codeid)values(?,?)
这个导入有没优化的办法,谢谢!
1
liprais 2016-08-03 09:58:21 +08:00 via iPhone
导入用 load file in path ,比一条条插入快
|
2
klaksvik 2017-11-07 14:54:52 +08:00
@wangpugod2003 兄,PTE 考试 7 炸有经验么? OZing
|