You are here

function _boost_index_exists in Boost 6

Add an index if it doesn't exist

Parameters

$ret: Array to which query results will be added.

$table: The table to be altered.

$index: The name of the index.

3 calls to _boost_index_exists()
boost_has_site_changed in ./boost.module
Checks various timestamps in the database.
boost_update_6121 in ./boost.install
Update 6121 - Add indexes to database for boost_has_site_changed() function.
boost_update_6124 in ./boost.install
Update 6124 - Add missing page_type index to boost_cache_relationships table

File

./boost.module, line 4827
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function _boost_index_exists(&$ret, $table, $index) {
  global $db_type;
  if (db_table_exists($table)) {
    if (stristr($db_type, 'pgsql')) {

      // Selecting a db schema table, don't put pg_indexes inside {}
      $result = db_query("SELECT * FROM pg_indexes WHERE tablename = '{%s}'", $table);
      while ($name = db_fetch_array($result)) {
        if (stristr($name['indexname'], $index)) {
          return TRUE;
        }
      }
    }
    else {
      $result = db_query('SHOW INDEX FROM {%s}', $table);
      while ($name = db_fetch_array($result)) {
        if ($name['Column_name'] == $index) {
          return TRUE;
        }
      }
    }

    // Index doesn't exists create it
    db_add_index($ret, $table, $index, array(
      $index,
    ));
  }
  return FALSE;
}