Author Topic: Help me speed up this MySQL query...  (Read 2929 times)

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Help me speed up this MySQL query...
« on: March 05, 2010, 07:34:05 PM »
 UPDATE `dplogin_filehashlog` `hl` LEFT JOIN `dplogin_connectlog` `cl` ON `cl`.`id` = `hl`.`connectid` SET `flags` = (`flags` | 1) WHERE `playerid` = ####;


Query OK, 52026 rows affected (22 min 11.19 sec)
Rows matched: 52026  Changed: 52026  Warnings: 0

IronFist

  • Autococker
  • Posts: 1304
Re: Help me speed up this MySQL query...
« Reply #1 on: April 01, 2010, 09:09:48 AM »
I imagine you've already found something that works for you, but it would be easier to locate potential problems or rewrite queries if we had just the database schema that we could populate with our own dummy data.

e.g. http://snippets.dzone.com/posts/show/360

« Last Edit: July 25, 2010, 06:57:01 PM by IronFist »

f3l1x

  • Committee Member
  • VM-68
  • Posts: 213
Re: Help me speed up this MySQL query...
« Reply #2 on: September 26, 2010, 03:50:03 PM »
Left join and right join is the same. I think this is faster way..

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Help me speed up this MySQL query...
« Reply #3 on: October 07, 2010, 06:03:34 PM »
Applicable tables:

Code: [Select]
--
-- Table structure for table `dplogin_filehashlog`
--

DROP TABLE IF EXISTS `dplogin_filehashlog`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `dplogin_filehashlog` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `connectid` int(10) unsigned NOT NULL,
  `filehash` int(10) unsigned NOT NULL,
  `filenameid` smallint(10) unsigned NOT NULL,
  `flags` tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `filehash` (`filehash`),
  KEY `flags` (`flags`),
  KEY `filenameid` (`filenameid`)
) ENGINE=MyISAM AUTO_INCREMENT=71897491 DEFAULT CHARSET=latin1 COMMENT='Log of periodic file checks.';
SET character_set_client = @saved_cs_client;

--
-- Table structure for table `dplogin_connectlog`
--

DROP TABLE IF EXISTS `dplogin_connectlog`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `dplogin_connectlog` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `playerid` int(10) unsigned NOT NULL,
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `connectinfo` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `connectinfo` (`connectinfo`)
) ENGINE=MyISAM AUTO_INCREMENT=20486498 DEFAULT CHARSET=latin1 COMMENT='Date and connection info log';
SET character_set_client = @saved_cs_client;

Wow, didn't realize playerid wasn't indexed.  That's probably the biggest issue.

Edit: Adding an index didn't seem to help. :(

Query OK, 73433 rows affected (25 min 26.82 sec)
Rows matched: 73433  Changed: 73433  Warnings: 0
« Last Edit: October 07, 2010, 10:12:30 PM by jitspoe »

f3l1x

  • Committee Member
  • VM-68
  • Posts: 213
Re: Help me speed up this MySQL query...
« Reply #4 on: October 08, 2010, 08:10:35 AM »
Try this:

ALTER TABLE dplogin_connectlog ADD KEY playerid (playerid);

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Help me speed up this MySQL query...
« Reply #5 on: November 05, 2010, 05:56:08 PM »
Quote
Edit: Adding an index didn't seem to help. :(