MySql优化查询Daloradius表

时间:2014-11-27 19:14:06

标签: mysql

有没有办法优化这些查询?我尝试使用multy查询运行但仍然很慢......

select date_format(acctstoptime,'%Y-%m-%d') as fecha,
avg(acctsessiontime) as SessionTimeAVG, sum(acctinputoctets),sum(acctoutputoctets)
from radacct  ,userinfo
where userinfo.username=radacct.username 
and  userinfo.company='98' and acctstoptime is not null 
group by date_format(acctstoptime,'%Y-%m-%d')
order by date_format(acctstoptime,'%Y-%m-%d') desc limit 0,30;  

select date_format(acctstoptime,'%Y-%m') as fecha,
avg(acctsessiontime) as SessionTimeAVG,
sum(acctinputoctets),sum(acctoutputoctets)
from radacct ,userinfo
where userinfo.username=radacct.username 
and  userinfo.company='98' and acctstoptime is not null
group by date_format(acctstoptime,'%Y-%m')
order by date_format(acctstoptime,'%Y-%m') desc limit 0,12; 

说明:

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  userinfo    ref username,company    company 203 const   5265    Using where; Using temporary; Using filesort
1   SIMPLE  radacct ref username,acctstoptime   username    66  radius.userinfo.username    5   Using where
1   SIMPLE  userinfo    ref username,company    company 203 const   5265    Using where; Using temporary; Using filesort
1   SIMPLE  radacct ref username,acctstoptime   username    66  radius.userinfo.username    5   Using where

编辑结构DALORADIUS表格

CREATE TABLE `radacct` (
  `radacctid` bigint(21) NOT NULL AUTO_INCREMENT,
  `acctsessionid` varchar(64) NOT NULL DEFAULT '',
  `acctuniqueid` varchar(32) NOT NULL DEFAULT '',
  `username` varchar(64) NOT NULL DEFAULT '',
  `groupname` varchar(64) NOT NULL DEFAULT '',
  `realm` varchar(64) DEFAULT '',
  `nasipaddress` varchar(15) NOT NULL DEFAULT '',
  `nasportid` varchar(15) DEFAULT NULL,
  `nasporttype` varchar(32) DEFAULT NULL,
  `acctstarttime` datetime DEFAULT NULL,
  `acctstoptime` datetime DEFAULT NULL,
  `acctsessiontime` int(12) DEFAULT NULL,
  `acctauthentic` varchar(32) DEFAULT NULL,
  `connectinfo_start` varchar(50) DEFAULT NULL,
  `connectinfo_stop` varchar(50) DEFAULT NULL,
  `acctinputoctets` bigint(20) DEFAULT NULL,
  `acctoutputoctets` bigint(20) DEFAULT NULL,
  `calledstationid` varchar(50) NOT NULL DEFAULT '',
  `callingstationid` varchar(50) NOT NULL DEFAULT '',
  `acctterminatecause` varchar(32) NOT NULL DEFAULT '',
  `servicetype` varchar(32) DEFAULT NULL,
  `framedprotocol` varchar(32) DEFAULT NULL,
  `framedipaddress` varchar(15) NOT NULL DEFAULT '',
  `acctstartdelay` int(12) DEFAULT NULL,
  `acctstopdelay` int(12) DEFAULT NULL,
  `xascendsessionsvrkey` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`radacctid`),
  KEY `username` (`username`),
  KEY `framedipaddress` (`framedipaddress`),
  KEY `acctsessionid` (`acctsessionid`),
  KEY `acctsessiontime` (`acctsessiontime`),
  KEY `acctuniqueid` (`acctuniqueid`),
  KEY `acctstarttime` (`acctstarttime`),
  KEY `acctstoptime` (`acctstoptime`),
  KEY `nasipaddress` (`nasipaddress`)
) ENGINE=InnoDB AUTO_INCREMENT=812908 DEFAULT CHARSET=latin1;


CREATE TABLE `userinfo` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(128) DEFAULT NULL,
  `firstname` varchar(200) DEFAULT NULL,
  `lastname` varchar(200) DEFAULT NULL,
  `email` varchar(200) DEFAULT NULL,
  `department` varchar(200) DEFAULT NULL,
  `company` varchar(200) DEFAULT NULL,
  `workphone` varchar(200) DEFAULT NULL,
  `homephone` varchar(200) DEFAULT NULL,
  `mobilephone` varchar(200) DEFAULT NULL,
  `address` varchar(200) DEFAULT NULL,
  `city` varchar(200) DEFAULT NULL,
  `state` varchar(200) DEFAULT NULL,
  `country` varchar(100) DEFAULT NULL,
  `zip` varchar(200) DEFAULT NULL,
  `notes` varchar(200) DEFAULT NULL,
  `changeuserinfo` varchar(128) DEFAULT NULL,
  `portalloginpassword` varchar(128) DEFAULT '',
  `enableportallogin` int(32) DEFAULT '0',
  `creationdate` datetime DEFAULT '0000-00-00 00:00:00',
  `creationby` varchar(128) DEFAULT NULL,
  `updatedate` datetime DEFAULT '0000-00-00 00:00:00',
  `updateby` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `username` (`username`),
  KEY `company` (`company`)
) ENGINE=MyISAM AUTO_INCREMENT=54258 DEFAULT CHARSET=latin1;

我无法将公司修改为数字,这是daloradius表。

感谢' S

0 个答案:

没有答案