=== modified file 'includes/database/database.inc'
--- includes/database/database.inc	2009-12-13 18:10:42 +0000
+++ includes/database/database.inc	2009-12-15 06:21:03 +0000
@@ -2373,6 +2373,18 @@ function db_field_names($fields) {
 }
 
 /**
+ * Check if an index exists.
+ *
+ * @param $name
+ *   Index name.
+ * @return
+ *   TRUE if the given index exists, otherwise FALSE.
+ */
+function db_index_exists($name) {
+  return Database::getConnection()->schema()->indexExists($name);
+}
+
+/**
  * Check if a table exists.
  */
 function db_table_exists($table) {

=== modified file 'includes/database/mysql/schema.inc'
--- includes/database/mysql/schema.inc	2009-09-29 15:13:54 +0000
+++ includes/database/mysql/schema.inc	2009-12-13 16:58:07 +0000
@@ -269,11 +269,11 @@ class DatabaseSchema_mysql extends Datab
   }
 
   public function renameTable($table, $new_name) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
+    $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
   }
 
   public function dropTable($table) {
-  	$this->connection->query('DROP TABLE {' . $table . '}');
+    $this->connection->query('DROP TABLE {' . $table . '}');
   }
 
   public function addField($table, $field, $spec, $keys_new = array()) {
@@ -300,7 +300,7 @@ class DatabaseSchema_mysql extends Datab
   }
 
   public function dropField($table, $field) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} DROP `' . $field . '`');
+    $this->connection->query('ALTER TABLE {' . $table . '} DROP `' . $field . '`');
   }
 
   public function fieldSetDefault($table, $field, $default) {
@@ -315,31 +315,35 @@ class DatabaseSchema_mysql extends Datab
   }
 
   public function fieldSetNoDefault($table, $field) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT');
+    $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT');
+  }
+
+  public function indexExists($table, $name) {
+    return $this->connection->query('SHOW INDEX FROM {' . $table . "} WHERE key_name = '$name'")->fetchField();
   }
 
   public function addPrimaryKey($table, $fields) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')');
+    $this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')');
   }
 
   public function dropPrimaryKey($table) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} DROP PRIMARY KEY');
+    $this->connection->query('ALTER TABLE {' . $table . '} DROP PRIMARY KEY');
   }
 
   public function addUniqueKey($table, $name, $fields) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')');
+    $this->connection->query('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')');
   }
 
   public function dropUniqueKey($table, $name) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} DROP KEY `' . $name . '`');
+    $this->connection->query('ALTER TABLE {' . $table . '} DROP KEY `' . $name . '`');
   }
 
   public function addIndex($table, $name, $fields) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')');
+    $this->connection->query('ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')');
   }
 
   public function dropIndex($table, $name) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} DROP INDEX `' . $name . '`');
+    $this->connection->query('ALTER TABLE {' . $table . '} DROP INDEX `' . $name . '`');
   }
 
   public function changeField($table, $field, $field_new, $spec, $keys_new = array()) {

=== modified file 'includes/database/pgsql/schema.inc'
--- includes/database/pgsql/schema.inc	2009-09-29 15:13:54 +0000
+++ includes/database/pgsql/schema.inc	2009-12-13 17:03:08 +0000
@@ -275,11 +275,11 @@ class DatabaseSchema_pgsql extends Datab
   }
 
   function renameTable($table, $new_name) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
+    $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
   }
 
   public function dropTable($table) {
-  	$this->connection->query('DROP TABLE {' . $table . '}');
+    $this->connection->query('DROP TABLE {' . $table . '}');
   }
 
   /**
@@ -320,14 +320,14 @@ class DatabaseSchema_pgsql extends Datab
         ->execute();
     }
     if ($fixnull) {
-    	$this->connection->query("ALTER TABLE {" . $table . "} ALTER $field SET NOT NULL");
+      $this->connection->query("ALTER TABLE {" . $table . "} ALTER $field SET NOT NULL");
     }
     if (isset($new_keys)) {
       $this->_createKeys($table, $new_keys);
     }
     // Add column comment.
     if (!empty($spec['description'])) {
-    	$this->connection->query('COMMENT ON COLUMN {' . $table . '}.' . $field . ' IS ' . $this->prepareComment($spec['description']));
+      $this->connection->query('COMMENT ON COLUMN {' . $table . '}.' . $field . ' IS ' . $this->prepareComment($spec['description']));
     }
   }
 
@@ -340,7 +340,7 @@ class DatabaseSchema_pgsql extends Datab
    *   The field to be dropped.
    */
   public function dropField($table, $field) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} DROP COLUMN "' . $field . '"');
+    $this->connection->query('ALTER TABLE {' . $table . '} DROP COLUMN "' . $field . '"');
   }
 
   /**
@@ -373,7 +373,11 @@ class DatabaseSchema_pgsql extends Datab
    *   The field to be altered.
    */
   public function fieldSetNoDefault($table, $field) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" DROP DEFAULT');
+    $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" DROP DEFAULT');
+  }
+
+  public function indexExists($table, $name) {
+    return $this->connection->query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '$name'")->fetchField();
   }
 
   /**
@@ -385,7 +389,7 @@ class DatabaseSchema_pgsql extends Datab
    *   Fields for the primary key.
    */
   public function addPrimaryKey($table, $fields) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . implode(',', $fields) . ')');
+    $this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . implode(',', $fields) . ')');
   }
 
   /**
@@ -395,7 +399,7 @@ class DatabaseSchema_pgsql extends Datab
    *   The table to be altered.
    */
   public function dropPrimaryKey($table) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT {' . $table . '}_pkey');
+    $this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT {' . $table . '}_pkey');
   }
 
   /**
@@ -437,7 +441,7 @@ class DatabaseSchema_pgsql extends Datab
    *   An array of field names.
    */
   public function addIndex($table, $name, $fields) {
-  	$this->connection->query($this->_createIndexSql($table, $name, $fields));
+    $this->connection->query($this->_createIndexSql($table, $name, $fields));
   }
 
   /**
@@ -534,7 +538,7 @@ class DatabaseSchema_pgsql extends Datab
     $this->connection->query("UPDATE {" . $table . "} SET $field_new = CAST(" . $field . "_old as " . $typecast . ")");
 
     if ($not_null) {
-    	$this->connection->query("ALTER TABLE {" . $table . "} ALTER $field_new SET NOT NULL");
+      $this->connection->query("ALTER TABLE {" . $table . "} ALTER $field_new SET NOT NULL");
     }
 
     $this->dropField($table, $field . '_old');

=== modified file 'includes/database/schema.inc'
--- includes/database/schema.inc	2009-12-04 16:31:04 +0000
+++ includes/database/schema.inc	2009-12-13 16:53:47 +0000
@@ -338,6 +338,18 @@ abstract class DatabaseSchema implements
   abstract public function fieldSetNoDefault($table, $field);
 
   /**
+   * Checks if an index exists.
+   *
+   * @param $table
+   *   Name of the table.
+   * @param $name
+   *   Name of the index.
+   * @return
+   *   Index name if the table exists. Otherwise FALSE.
+   */
+  abstract public function indexExists($table, $name);
+
+  /**
    * Add a primary key.
    *
    * @param $table

=== modified file 'includes/database/sqlite/schema.inc'
--- includes/database/sqlite/schema.inc	2009-09-29 15:13:54 +0000
+++ includes/database/sqlite/schema.inc	2009-12-13 17:04:54 +0000
@@ -220,7 +220,7 @@ class DatabaseSchema_sqlite extends Data
   *   The new name for the table.
   */
   public function renameTable($table, $new_name) {
-  	$this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
+    $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
   }
 
   /**
@@ -230,7 +230,7 @@ class DatabaseSchema_sqlite extends Data
    *   The table to be dropped.
    */
   public function dropTable($table) {
-  	$this->connection->query('DROP TABLE {' . $table . '}');
+    $this->connection->query('DROP TABLE {' . $table . '}');
   }
 
   /**
@@ -429,10 +429,14 @@ class DatabaseSchema_sqlite extends Data
     $schema['indexes'][$name] = $fields;
     $statements = $this->createIndexSql($table, $schema);
     foreach ($statements as $statement) {
-    	$this->connection->query($statement);
+      $this->connection->query($statement);
     }
   }
 
+  public function indexExists($table, $name) {
+    return ($this->connection->query("PRAGMA index_info($name)")->fetchField() != '');
+  }
+
   /**
    * Drop an index.
    *
@@ -442,7 +446,7 @@ class DatabaseSchema_sqlite extends Data
    *   The name of the index.
    */
   public function dropIndex($table, $name) {
-  	$this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name);
+    $this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name);
   }
 
   /**
@@ -459,7 +463,7 @@ class DatabaseSchema_sqlite extends Data
     $schema['unique keys'][$name] = $fields;
     $statements = $this->createIndexSql($table, $schema);
     foreach ($statements as $statement) {
-    	$this->connection->query($statement);
+      $this->connection->query($statement);
     }
   }
 
@@ -472,7 +476,7 @@ class DatabaseSchema_sqlite extends Data
    *   The name of the key.
    */
   public function dropUniqueKey($table, $name) {
-  	$this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name);
+    $this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name);
   }
 
   /**

=== modified file 'modules/simpletest/tests/schema.test'
--- modules/simpletest/tests/schema.test	2009-09-29 15:13:54 +0000
+++ modules/simpletest/tests/schema.test	2009-12-14 02:47:45 +0000
@@ -1,4 +1,4 @@
-<?php
+g<?php
 // $Id: schema.test,v 1.9 2009/09/29 15:13:56 dries Exp $
 
 /**
@@ -128,4 +128,15 @@ class SchemaTestCase extends DrupalWebTe
       $this->assertEqual($comment, $description, t('The comment matches the schema description.'));
     }
   }
+
+  /**
+   * Test index status.
+   */
+  function testCheckIndex() {
+    $node_changed_index = Database::getConnection()->schema()->indexExists('node', 'node_changed');
+    $this->assertTrue($node_changed_index, t('Node index exists'));
+
+    $node_fake_index = Database::getConnection()->schema()->indexExists('node', 'node_not_exists');
+    $this->assertFalse($node_fake_index, t('Fake index does not exists'));
+  }
 }

