Jump to content

  •  

Bug Tracker Migration

June 3rd
Good news everyone! The staff has decided that it is time to slowly kill off this Bug Tracker. We will begin the process of slowly migrating from this Bug Tracker over to our Github Issues which can be found here: https://github.com/HerculesWS/Hercules/issues

Over the next couple of days, I will be closing off any opportunity to create new reports. However, I still will keep the opportunity to reply to existing Bug Reports. Doing this will allow us to slowly fix any bug reports we have listed here so that we can easily migrate over to our Issue Tracker.

Update - June 7th 2015: Creating new bug posts has been disabled. Please use our https://github.com/HerculesWS/Hercules/issues tracker to post bugs. Users are still able to reply to existing bug posts.

- Administration

Issue Information

  • #003289

  • 4 - High

  • Confirmed

Issue Confirmations

  • Yes (1)No (0)
Photo

poor sql table indexing causes full table scans

Posted by Hercules Bot on 25 June 2009 - 03:09 AM

Originally posted by theultramage
http://www.eathena.w...er&showbug=3289

I have used mysqld's slow query logging feature to generate a list of frequently occurring queries that accessed a large number of rows. This usually means that a full table scan was needed to execute the query, which in turn means that it might be room for improvement. This is achieved by adding indexes on appropriate columns.

Here is a list of slow queries. All measurements were performed on a server with ~1400 on-line chars, 300k chars in database, and several million rows in inventory/cart/storage dbs. There are also numerous recorded performance problems with Ceres CP, however I'm not sure if it is relevant here so I'll skip them.

DELETE FROM `pet` WHERE pet_id IN (SELECT card1 | card2 <<2 FROM `inventory` WHERE char_id = '%d' AND card0 = -256 UNION SELECT card1 | card2 <<2 FROM `cart_inventory` WHERE char_id = '%d' AND card0 = -256)
location: /src/char_sql/char.c, line 1376, char deletion
performance: 1-8 seconds, billions of rows scanned
comment: MySQL 5 is unable to optimize this IN() query, producing a ridiculously inefficient loop over all pets, and re-running the sub-query every time. Suggest either rewriting as a JOIN, or removing entirely in favor of a one-by-one item-based deletion (already done in /charmerge).

DELETE FROM `pet` WHERE `char_id`='%d' AND `incuvate` = '0';
location: /src/char_sql/char.c, line 1372, char deletion
performance: 0.12-0.14 seconds
comment: Missing index on pet.char_id.

DELETE FROM `friends` WHERE `friend_id` = '%d';
location: /src/char_sql/char.c, line 1396, char deletion
performance: 1 second
comment: Missing index on `friend_id`.

SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`card0`,`card1`,`card2`,`card3` FROM `mail` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d
location: /src/char_sql/int_mail.c, line 40, mail_fromsql
performance: quite bad
comment: Missing index on `dest_id`.

SELECT `party_id` FROM `party` WHERE `name`='%s';
location: /src/char_sql/int_party.c, line 302, party creation check
performance: 0.15-0.30 seconds, 40k rows scanned
comment: Missing index on `name`.

SELECT guild_id FROM `guild` WHERE name='%s';
location: /src/char_sql/int_guild, line 818, guild creation check
performance: 0.15s, 16k rows examined
comment: Missing index on `name`.

SELECT `guild_id` FROM `guild` WHERE `master` = '%s';
location: /src/char_sql/char.c, line 1147, char deletion
performance: 0.15s, 16k rows examined
comment: Missing index on `master`.

DELETE FROM `guild_alliance` WHERE `guild_id` = '%d' OR `alliance_id` = '%d';
location: /src/char_sql/int_guild.c, line 1501, guild break
performance: 0-0.05s
comment: Not sure why it's logged - needs EXPLAIN analysis.

DELETE FROM `mercenary` WHERE `char_id` = '%d';
location: /src/char_sql/int_mercenary.c, line 63, mercenary_owner_delete
performance: 0s
comment: Missing index on `char_id`.

DELETE FROM `ipbanlist` WHERE `rtime` <= NOW();
location: /src/login/ipban_sql.c, line 248, ipban_cleanup
performance: 0s
comment: Missing index on `rtime`.

This post has been edited by theultramage: Jun 24 2009, 08:22 PM

Originally posted by MarkZD
Should be moved to Database, as fixing indexes will give a great update.
There maybe some other principles not followed on our database, as making foreign key indexes.

Originally posted by Brian
The "Database" category is for bugs with rAthena's RO databases (mobs, items, skills, etc.)

Bugs with rAthena's MySQL database fit better in Core.

Originally posted by Ind
something i did over a discussion on irc: