View Issue Details

IDProjectCategoryView StatusLast Update
0003492mantisbtperformancepublic2006-02-04 05:47
Reporterchipux Assigned Tograngeway  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionno change required 
Summary0003492: Better Indexes on SQL
Description
  • Added Several Indexes and changed one query to increase performance.
  • Also sets the view_bug page to do a 2nd level sort based on the last_updated field.
Additional Information

http://force-elite.com/~chip/patches/mantis/faster-better-cooler.patch

Without this Patch our MySQL Performance would degrade greatly under high concurant load. The Largest part of this is MySQL would not use the Index for the Custom Fields Table.(because it is a joint Index, and most mantis selects are only on one field.)

We also changed several tables to InnoDB type for increased performance (row-level locking helped alot!)

TagsNo tags attached.
Attached Files
faster-better-cooler.diff (2,639 bytes)   
Index: sql/db_generate.sql
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/sql/db_generate.sql,v
retrieving revision 1.14
diff -u -r1.14 db_generate.sql
--- sql/db_generate.sql	22 Mar 2003 10:53:25 -0000	1.14
+++ sql/db_generate.sql	7 Jan 2004 06:38:25 -0000
@@ -20,7 +20,8 @@
   file_type varchar(250) NOT NULL default '',
   date_added datetime NOT NULL default '1970-01-01 00:00:01',
   content longblob NOT NULL,
-  PRIMARY KEY  (id)
+  PRIMARY KEY  (id),
+  KEY bug_id (bug_id)
 ) TYPE=MyISAM;
 
 #
@@ -113,6 +114,11 @@
   view_state int(2) NOT NULL default '10',
   summary varchar(128) NOT NULL default '',
-  PRIMARY KEY  (id)
+  PRIMARY KEY  (id),
+  KEY idx_mantis_bug_table_reporter_id (reporter_id),
+  KEY idx_mantis_bug_table_handler_id (handler_id),
+  KEY idx_mantis_bug_table_priority (priority),
+  KEY project_id (project_id),
+  KEY status (status)
 ) TYPE=MyISAM;
 
 #
@@ -196,7 +202,9 @@
   field_id int(3) NOT NULL default '0',
   bug_id int(7) NOT NULL default '0',
   value varchar(255) NOT NULL default '',
-  PRIMARY KEY  (field_id,bug_id)
+  KEY value (value),
+  KEY field_id (field_id),
+  KEY bug_id (bug_id)
 ) TYPE=MyISAM;
 
 #
@@ -695,7 +703,8 @@
   cookie_string varchar(64) NOT NULL default '',
   PRIMARY KEY  (id),
   UNIQUE KEY username (username),
-  UNIQUE KEY cookie_string (cookie_string)
+  UNIQUE KEY cookie_string (cookie_string),
+  KEY email (email)
 ) TYPE=MyISAM;
 
 #
Index: core/filter_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/filter_api.php,v
retrieving revision 1.14
diff -u -r1.14 filter_api.php
--- core/filter_api.php	17 Aug 2003 23:08:48 -0000	1.14
+++ core/filter_api.php	7 Jan 2004 06:38:25 -0000
@@ -168,7 +168,7 @@
 		}
 
 		# Get the total number of bugs that meet the criteria.
-		$query = "SELECT COUNT( $t_bug_table.id ) as count $t_from $t_join $t_where";
+		$query = "SELECT COUNT( DISTINCT ( $t_bug_table.id ) ) as count $t_from $t_join $t_where";
 		$result = db_query( $query );
 		$bug_count = db_result( $result );
 
@@ -224,7 +224,14 @@
 			$c_dir = 'ASC';
 		}
 
-		$query2 .= " ORDER BY '$c_sort' $c_dir";
+                $t_upd = ', last_updated DESC';
+
+                if( $c_sort != 'last_updated') {
+		        $query2 .= " ORDER BY '$c_sort' $c_dir $t_upd";
+                }
+                else {
+                        $query2 .= " ORDER BY '$c_sort' $c_dir";
+                }
 
 		# Figure out the offset into the db query
 		#
faster-better-cooler.diff (2,639 bytes)   

Activities

chipux

chipux

2004-01-07 21:14

reporter   ~0004861

This patch is no longer needed.

Bug 0003494 contains this patch and other enhancments.

-chipux

vboctor

vboctor

2004-01-13 22:31

manager   ~0004886

I would rather keep this one open since it includes the indices patch without including other enhancements. Ideally, we should have a patch per enhancement rather than a patch for a group of them.

I also attached the patch to the bug.

grangeway

grangeway

2005-12-17 18:47

reporter   ~0011803

I'm going to resolve this off for now - We've added a number of indices, and changed the code since January 2004.

Before applying anything from this patch, we'd need to re-evaulate the code/database performance so i'm not sure it makes sense to leave this open.

Chipux: if you are aware of any indexes that would be useful to have against the 1.0.x branch or CVS head, please let us know.

THanks
Paul