Skip to content

Commit

Permalink
CREATE/ALTER/DROP INDEX测试
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Oct 21, 2015
1 parent af33568 commit 85b9518
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lealone-sql/src/main/java/org/lealone/sql/Parser.java
Expand Up @@ -3891,7 +3891,7 @@ private StatementBase parseCreate() {
} else if (readIf("DATABASE")) {
return parseCreateDatabase();
}
// tables or linked tables
// table or index
boolean memory = false, cached = false;
if (readIf("MEMORY")) {
memory = true;
Expand Down
Expand Up @@ -15,30 +15,65 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lealone.test.sql.ddl;
package org.lealone.test.db.index;

import org.junit.Test;
import org.lealone.test.sql.SqlTestBase;
import org.lealone.db.Constants;
import org.lealone.db.index.Index;
import org.lealone.db.table.Table;
import org.lealone.test.db.DbObjectTestBase;

public class IndexTest extends DbObjectTestBase {

public class CreateIndexTest extends SqlTestBase {
@Test
public void run() {
create();
alter();
drop();
}

void create() {
executeUpdate("DROP TABLE IF EXISTS CreateIndexTest");
executeUpdate("CREATE TABLE IF NOT EXISTS CreateIndexTest (f1 int NOT NULL, f2 int, f3 int)");

//executeUpdate("CREATE PRIMARY KEY HASH ON CreateIndexTest(f1)");
Table table = schema.findTableOrView(session, "CreateIndexTest");
assertNotNull(table);

executeUpdate("CREATE PRIMARY KEY HASH ON CreateIndexTest(f1)");
Index index = table.findPrimaryKey();
assertNotNull(index);
String indexName = index.getName();
assertTrue(indexName.startsWith(Constants.PREFIX_PRIMARY_KEY));

executeUpdate("DROP INDEX IF EXISTS " + indexName);
index = schema.findIndex(session, indexName);
assertNull(index);

executeUpdate("CREATE PRIMARY KEY HASH IF NOT EXISTS idx0 ON CreateIndexTest(f1)");
index = schema.findIndex(session, "idx0");
assertNotNull(index);

executeUpdate("CREATE UNIQUE HASH INDEX IF NOT EXISTS idx1 ON CreateIndexTest(f2)");
index = schema.findIndex(session, "idx1");
assertNotNull(index);

executeUpdate("CREATE INDEX IF NOT EXISTS idx2 ON CreateIndexTest(f3)");
index = schema.findIndex(session, "idx2");
assertNotNull(index);
}

void alter() {
executeUpdate("ALTER INDEX idx2 RENAME TO idx22");

executeUpdate("DROP INDEX IF EXISTS idx22");

//executeUpdate("CREATE SCHEMA IF NOT EXISTS schema0 AUTHORIZATION sa");
//executeUpdate("ALTER INDEX mydb.public.idx0 RENAME TO schema0.idx1");
Index index = schema.findIndex(session, "idx22");
assertNotNull(index);
index = schema.findIndex(session, "idx2");
assertNull(index);
}

//executeUpdate("ALTER INDEX mydb.public.idx0 RENAME TO idx1");
void drop() {
executeUpdate("DROP INDEX IF EXISTS idx22");
Index index = schema.findIndex(session, "idx22");
assertNull(index);
}
}

This file was deleted.

0 comments on commit 85b9518

Please sign in to comment.