Exemplo n.º 1
0
 /**
  * Given one correct xmldb_index, returns the SQL statements
  * needed to create it (in array).
  *
  * @param xmldb_table $xmldb_table The xmldb_table instance to create the index on.
  * @param xmldb_index $xmldb_index The xmldb_index to create.
  * @return array An array of SQL statements to create the index.
  * @throws coding_exception Thrown if the xmldb_index does not validate with the xmldb_table.
  */
 public function getCreateIndexSQL($xmldb_table, $xmldb_index)
 {
     $sqls = parent::getCreateIndexSQL($xmldb_table, $xmldb_index);
     $hints = $xmldb_index->getHints();
     $fields = $xmldb_index->getFields();
     if (in_array('varchar_pattern_ops', $hints) and count($fields) == 1) {
         // Add the pattern index and keep the normal one, keep unique only the standard index to improve perf.
         foreach ($sqls as $sql) {
             $field = reset($fields);
             $count = 0;
             $newindex = preg_replace("/^CREATE( UNIQUE)? INDEX ([a-z0-9_]+) ON ([a-z0-9_]+) \\({$field}\\)\$/", "CREATE INDEX \\2_pattern ON \\3 USING btree ({$field} varchar_pattern_ops)", $sql, -1, $count);
             if ($count != 1) {
                 debugging('Unexpected getCreateIndexSQL() structure.');
                 continue;
             }
             $sqls[] = $newindex;
         }
     }
     return $sqls;
 }