mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-33018 support varchar_pattern_ops on unique indexes
This commit is contained in:
parent
661dd35d89
commit
068cf0e519
@ -133,11 +133,11 @@ class postgres_sql_generator extends sql_generator {
|
||||
$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.
|
||||
// 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 INDEX ([a-z0-9_]+) ON ([a-z0-9_]+) \($field\)$/", "CREATE INDEX \\1_pattern ON \\2 USING btree ($field varchar_pattern_ops)", $sql, -1, $count);
|
||||
$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;
|
||||
|
@ -1676,6 +1676,21 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$table = new xmldb_table('testtable');
|
||||
$index = new xmldb_index('path', XMLDB_INDEX_NOTUNIQUE, array('path'), array('varchar_pattern_ops'));
|
||||
$this->assertTrue($dbman->index_exists($table, $index));
|
||||
|
||||
// Try unique indexes too.
|
||||
$dbman->drop_table($this->tables[$tablename]);
|
||||
|
||||
$table = new xmldb_table('testtable');
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('path', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL, null);
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_index('path', XMLDB_INDEX_UNIQUE, array('path'), array('varchar_pattern_ops'));
|
||||
$dbman->create_table($table);
|
||||
$this->tables[$tablename] = $table;
|
||||
|
||||
$table = new xmldb_table('testtable');
|
||||
$index = new xmldb_index('path', XMLDB_INDEX_UNIQUE, array('path'), array('varchar_pattern_ops'));
|
||||
$this->assertTrue($dbman->index_exists($table, $index));
|
||||
}
|
||||
|
||||
public function test_index_max_bytes() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user