I have this table
CREATE TABLE gotrax1.wifi_log (
WifiID int(11) NOT NULL AUTO_INCREMENT,
UnitID int(11) DEFAULT NULL,
ServerTime timestamp NULL DEFAULT CURRENT_TIMESTAMP (),
FileTime bigint(20) DEFAULT NULL,
WLANTYPE text DEFAULT NULL,
MACSRC varchar(25) DEFAULT NULL,
MACDST varchar(25) DEFAULT NULL,
BSSID varchar(25) DEFAULT NULL,
SIG int(11) DEFAULT NULL,
ESSID text DEFAULT NULL,
PRIMARY KEY (WifiID)
)
I need to run this query on it
SELECT
COUNT(DISTINCT(MACDST)) AS MACDST,
COUNT(DISTINCT(MACSRC)) AS MACSRC,
COUNT(DISTINCT(BSSID)) AS BSSID,
COUNT(DISTINCT(MACDST))-COUNT(DISTINCT(MACSRC)) AS UnitDIFF,
UnitID, FileTime, WLANTYPE
FROM wifi_log
GROUP BY FileTime,UnitID,WLANTYPE
ORDER BY FileTime DESC;
It is dog slow and does a full file sort. Normally I know to add an index following the order of a where clause. I have no idea how to do it with this query and this table to avoid the filesort. Any suggestions would be terrific thankyou.
COUNT(DISTINCT)will also slow things down.explain select ...to see the execution plan.