提交 a944cc8b authored 作者: Thomas Mueller's avatar Thomas Mueller

Executing the statement CREATE INDEX IF ALREADY EXISTS if the index already…

Executing the statement CREATE INDEX IF ALREADY EXISTS if the index already exists no longer fails for a read only database.
上级 167230d2
...@@ -58,6 +58,12 @@ public class CreateIndex extends SchemaCommand { ...@@ -58,6 +58,12 @@ public class CreateIndex extends SchemaCommand {
Database db = session.getDatabase(); Database db = session.getDatabase();
boolean persistent = db.isPersistent(); boolean persistent = db.isPersistent();
Table table = getSchema().getTableOrView(session, tableName); Table table = getSchema().getTableOrView(session, tableName);
if (getSchema().findIndex(session, indexName) != null) {
if (ifNotExists) {
return 0;
}
throw DbException.get(ErrorCode.INDEX_ALREADY_EXISTS_1, indexName);
}
session.getUser().checkRight(table, Right.ALL); session.getUser().checkRight(table, Right.ALL);
table.lock(session, true, true); table.lock(session, true, true);
if (!table.isPersistIndexes()) { if (!table.isPersistIndexes()) {
...@@ -71,12 +77,6 @@ public class CreateIndex extends SchemaCommand { ...@@ -71,12 +77,6 @@ public class CreateIndex extends SchemaCommand {
indexName = table.getSchema().getUniqueIndexName(session, table, Constants.PREFIX_INDEX); indexName = table.getSchema().getUniqueIndexName(session, table, Constants.PREFIX_INDEX);
} }
} }
if (getSchema().findIndex(session, indexName) != null) {
if (ifNotExists) {
return 0;
}
throw DbException.get(ErrorCode.INDEX_ALREADY_EXISTS_1, indexName);
}
IndexType indexType; IndexType indexType;
if (primaryKey) { if (primaryKey) {
if (table.findPrimaryKey() != null) { if (table.findPrimaryKey() != null) {
......
...@@ -100,9 +100,14 @@ public class TestReadOnly extends TestBase { ...@@ -100,9 +100,14 @@ public class TestReadOnly extends TestBase {
private void testReadOnlyDbCreate() throws SQLException { private void testReadOnlyDbCreate() throws SQLException {
deleteDb("readonly"); deleteDb("readonly");
Connection conn = getConnection("readonly"); Connection conn = getConnection("readonly");
Statement stat = conn.createStatement();
stat.execute("create table a(id int)");
stat.execute("create index ai on a(id)");
conn.close(); conn.close();
conn = getConnection("readonly;ACCESS_MODE_DATA=r"); conn = getConnection("readonly;ACCESS_MODE_DATA=r");
Statement stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table if not exists a(id int)");
stat.execute("create index if not exists ai on a(id)");
assertThrows(ErrorCode.DATABASE_IS_READ_ONLY, stat). assertThrows(ErrorCode.DATABASE_IS_READ_ONLY, stat).
execute("CREATE TABLE TEST(ID INT)"); execute("CREATE TABLE TEST(ID INT)");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat). assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论