Skip to content

Commit

Permalink
Optimisation: Added an index on bug_id field in the mantis_bug_file_t…
Browse files Browse the repository at this point in the history
…able.

A admin/upgrades/0_18_inc.php
- Added to include upgrades since 0.18.0

M admin/upgrade.php
- Add upgrade steps in 0_18_inc.php

M core/database_api.php
- (db_key_exists_on_field): Checks if there exists a field on the specified table/field of the specified type.


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@2291 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
vboctor committed Jan 31, 2004
1 parent 32d5527 commit f84b3e7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
3 changes: 2 additions & 1 deletion admin/upgrade.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: upgrade.php,v 1.3 2004-01-11 07:16:09 vboctor Exp $
# $Id: upgrade.php,v 1.4 2004-01-31 15:10:33 vboctor Exp $
# --------------------------------------------------------
?>
<?php
Expand All @@ -19,6 +19,7 @@
$upgrade_set->add_items( include( 'upgrades/0_15_inc.php' ) );
$upgrade_set->add_items( include( 'upgrades/0_16_inc.php' ) );
$upgrade_set->add_items( include( 'upgrades/0_17_inc.php' ) );
$upgrade_set->add_items( include( 'upgrades/0_18_inc.php' ) );
?>
<html>
<head>
Expand Down
40 changes: 40 additions & 0 deletions admin/upgrades/0_18_inc.php
@@ -0,0 +1,40 @@
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details

# Changes applied to 0.18 database

# --------------------------------------------------------
# $Id: 0_18_inc.php,v 1.1 2004-01-31 15:10:34 vboctor Exp $
# --------------------------------------------------------
?>
<?php
require_once( 'db_table_names_inc.php' );

$upgrades = array();

$upgrades[] = new FunctionUpgrade(
'0.18-vb-1',
'Add index on bug_id field in mantis_bug_file_table.',
'upgrade_0_18_vb_1' );

function upgrade_0_18_vb_1() {
global $t_bug_file_table;

if ( !db_key_exists_on_field( $t_bug_file_table, 'bug_id', 'MUL' ) ) {
$query = "ALTER TABLE $t_bug_file_table ADD INDEX bug_id ( bug_id )";
$result = @db_query( $query );

if ( false == $result ) {
return false;
}
}

return true;
}

return $upgrades;
?>
34 changes: 31 additions & 3 deletions core/database_api.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: database_api.php,v 1.19 2004-01-11 07:16:10 vboctor Exp $
# $Id: database_api.php,v 1.20 2004-01-31 15:10:33 vboctor Exp $
# --------------------------------------------------------

###########################################################################
Expand Down Expand Up @@ -162,6 +162,35 @@ function db_field_exists( $p_field_name, $p_table_name, $p_db_name = '') {
return false;
}

# --------------------
# Check if there is an index defined on the specified table/field and with
# the specified type.
#
# $p_table: Name of table to check
# $p_field: Name of field to check
# $p_key: key type to check for (eg: PRI, MUL, ...etc)
function db_key_exists_on_field( $p_table, $p_field, $p_key ) {
$c_table = db_prepare_string( $p_table );
$c_field = db_prepare_string( $p_field );
$c_key = db_prepare_string( $p_key );

$query = "DESCRIBE $c_table";

$result = db_query( $query );

$count = db_num_rows( $result );

for ( $i=0 ; $i < $count ; $i++ ) {
$row = db_fetch_array( $result );

if ( $row['Field'] == $c_field ) {
return ( $row['Key'] == $c_key );
}
}

return false;
}

# --------------------
function db_error_num() {
return mysql_errno();
Expand Down Expand Up @@ -216,5 +245,4 @@ function db_prepare_bool( $p_bool ) {
}
db_select_db( $g_database_name );
}

?>
?>
1 change: 1 addition & 0 deletions doc/ChangeLog
Expand Up @@ -14,6 +14,7 @@ Mantis ChangeLog
* Fix #3495: Warning even if administrator account is disabled.
* Fix #3501: No output for print_all_bug_page.php when status=closed, and Hide Status Closed is selected.
* Fix #3506: PHP error if "duplicate id" refers to a bug that does not exist.
* Opt #0000: Added an index on bug_id field in the mantis_bug_file_table.
* Updated copyright to include 2004

2003.12.08 - 0.18.0
Expand Down

0 comments on commit f84b3e7

Please sign in to comment.