netripper

netripper

Feb 25th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.52 KB | None | 0 0
  1. CREATE TABLE IF NOT EXISTS `log` (
  2.   `idx` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  3.   `when` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  4.   `how` VARCHAR(50) NOT NULL DEFAULT '',
  5.   `where` VARCHAR(50) NOT NULL DEFAULT '',
  6.   `who` VARCHAR(50) NOT NULL DEFAULT '',
  7.   `what` text NOT NULL,
  8.   PRIMARY KEY  (`idx`),
  9.   KEY `where` (`where`),
  10.   KEY `who` (`who`),
  11.   KEY `how` (`how`)
  12. ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1255578 ;
  13.  
  14. -- table contains about 2.2mil records at the time of this pastebin
  15.  
  16. -- this query takes 6.65 sec
  17. SELECT DATE(`when`) FROM log WHERE `where` LIKE '#htc-linux' ORDER BY `when` DESC LIMIT 1;
  18.  
  19. -- explain plan for this query
  20. id  select_type     TABLE   TYPE    possible_keys   KEY     key_len     REF     ROWS    Extra
  21. 1   SIMPLE  log     range   WHERE   WHERE   152     NULL    687818  USING WHERE; USING filesort
  22.  
  23. -- this query takes 8.8 sec
  24. SELECT DATE(`when`) FROM log WHERE `where` = '#htc-linux' ORDER BY `when` DESC LIMIT 1;
  25.  
  26. -- explain plan for this query
  27. id  select_type     TABLE   TYPE    possible_keys   KEY     key_len     REF     ROWS    Extra
  28. 1   SIMPLE  log     REF     WHERE   WHERE   152     const   687838  USING WHERE; USING filesort
  29.  
  30. -- the query with = takes longer than the query with LIKE.. i also need case-insensitivity (well, currently, it's adjustable when i fix the script, but i see no point with those results)
  31.  
  32. -- my.cnf is not optimized (not manually anyway)
  33. -- machine specs:
  34. -- intel xeon quadcore 3ghz
  35. -- 2gb ram
  36. -- 2 disks in mirror raid
  37.  
  38. -- adding an index on when/who/where doesn't make a difference
Add Comment
Please, Sign In to add comment