提交 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 {
Database db = session.getDatabase();
boolean persistent = db.isPersistent();
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);
table.lock(session, true, true);
if (!table.isPersistIndexes()) {
......@@ -71,12 +77,6 @@ public class CreateIndex extends SchemaCommand {
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;
if (primaryKey) {
if (table.findPrimaryKey() != null) {
......
......@@ -100,9 +100,14 @@ public class TestReadOnly extends TestBase {
private void testReadOnlyDbCreate() throws SQLException {
deleteDb("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 = 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).
execute("CREATE TABLE TEST(ID INT)");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论