提交 267e7083 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Fix for TestIndexHints

上级 1d3079b7
...@@ -18,6 +18,8 @@ import java.sql.Statement; ...@@ -18,6 +18,8 @@ import java.sql.Statement;
*/ */
public class TestIndexHints extends TestBase { public class TestIndexHints extends TestBase {
private Connection conn;
/** /**
* Run just this test. * Run just this test.
* *
...@@ -39,11 +41,12 @@ public class TestIndexHints extends TestBase { ...@@ -39,11 +41,12 @@ public class TestIndexHints extends TestBase {
testPlanSqlHasIndexesInCorrectOrder(); testPlanSqlHasIndexesInCorrectOrder();
testWithTableAlias(); testWithTableAlias();
testWithTableAliasCalledUse(); testWithTableAliasCalledUse();
conn.close();
deleteDb("indexhints"); deleteDb("indexhints");
} }
private void createDb() throws SQLException { private void createDb() throws SQLException {
Connection conn = getConnection("indexhints"); conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test (x int, y int)"); stat.execute("create table test (x int, y int)");
stat.execute("create index idx1 on test (x)"); stat.execute("create index idx1 on test (x)");
...@@ -52,7 +55,6 @@ public class TestIndexHints extends TestBase { ...@@ -52,7 +55,6 @@ public class TestIndexHints extends TestBase {
} }
private void testQuotedIdentifier() throws SQLException { private void testQuotedIdentifier() throws SQLException {
Connection conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("explain analyze select * " + ResultSet rs = stat.executeQuery("explain analyze select * " +
"from test use index(\"Idx3\") where x=1 and y=1"); "from test use index(\"Idx3\") where x=1 and y=1");
...@@ -66,54 +68,44 @@ public class TestIndexHints extends TestBase { ...@@ -66,54 +68,44 @@ public class TestIndexHints extends TestBase {
plan = rs.getString(1); plan = rs.getString(1);
assertTrue(plan.contains("/* PUBLIC.\"Idx3\":")); assertTrue(plan.contains("/* PUBLIC.\"Idx3\":"));
assertTrue(plan.contains("USE INDEX (\"Idx3\")")); assertTrue(plan.contains("USE INDEX (\"Idx3\")"));
conn.close();
} }
private void testWithSingleIndexName() throws SQLException { private void testWithSingleIndexName() throws SQLException {
Connection conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("explain analyze select * " + ResultSet rs = stat.executeQuery("explain analyze select * " +
"from test use index(idx1) where x=1 and y=1"); "from test use index(idx1) where x=1 and y=1");
rs.next(); rs.next();
String result = rs.getString(1); String result = rs.getString(1);
assertTrue(result.contains("/* PUBLIC.IDX1:")); assertTrue(result.contains("/* PUBLIC.IDX1:"));
conn.close();
} }
private void testWithTableAlias() throws SQLException { private void testWithTableAlias() throws SQLException {
Connection conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("explain analyze select * " + ResultSet rs = stat.executeQuery("explain analyze select * " +
"from test t use index(idx2) where x=1 and y=1"); "from test t use index(idx2) where x=1 and y=1");
rs.next(); rs.next();
String result = rs.getString(1); String result = rs.getString(1);
assertTrue(result.contains("/* PUBLIC.IDX2:")); assertTrue(result.contains("/* PUBLIC.IDX2:"));
conn.close();
} }
private void testWithTableAliasCalledUse() throws SQLException { private void testWithTableAliasCalledUse() throws SQLException {
// make sure that while adding new syntax for table hints, code // make sure that while adding new syntax for table hints, code
// that uses "USE" as a table alias still works // that uses "USE" as a table alias still works
Connection conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.executeQuery("explain analyze select * " + stat.executeQuery("explain analyze select * " +
"from test use where use.x=1 and use.y=1"); "from test use where use.x=1 and use.y=1");
conn.close();
} }
private void testWithMultipleIndexNames() throws SQLException { private void testWithMultipleIndexNames() throws SQLException {
Connection conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("explain analyze select * " + ResultSet rs = stat.executeQuery("explain analyze select * " +
"from test use index(idx1, idx2) where x=1 and y=1"); "from test use index(idx1, idx2) where x=1 and y=1");
rs.next(); rs.next();
String result = rs.getString(1); String result = rs.getString(1);
assertTrue(result.contains("/* PUBLIC.IDX2:")); assertTrue(result.contains("/* PUBLIC.IDX2:"));
conn.close();
} }
private void testPlanSqlHasIndexesInCorrectOrder() throws SQLException { private void testPlanSqlHasIndexesInCorrectOrder() throws SQLException {
Connection conn = getConnection("indexhints");
ResultSet rs = conn.createStatement().executeQuery("explain analyze select * " + ResultSet rs = conn.createStatement().executeQuery("explain analyze select * " +
"from test use index(idx1, idx2) where x=1 and y=1"); "from test use index(idx1, idx2) where x=1 and y=1");
rs.next(); rs.next();
...@@ -123,23 +115,18 @@ public class TestIndexHints extends TestBase { ...@@ -123,23 +115,18 @@ public class TestIndexHints extends TestBase {
"from test use index(idx2, idx1) where x=1 and y=1"); "from test use index(idx2, idx1) where x=1 and y=1");
rs2.next(); rs2.next();
assertTrue(rs2.getString(1).contains("USE INDEX (IDX2, IDX1)")); assertTrue(rs2.getString(1).contains("USE INDEX (IDX2, IDX1)"));
conn.close();
} }
private void testWithEmptyIndexHintsList() throws SQLException { private void testWithEmptyIndexHintsList() throws SQLException {
Connection conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("explain analyze select * " + ResultSet rs = stat.executeQuery("explain analyze select * " +
"from test use index () where x=1 and y=1"); "from test use index () where x=1 and y=1");
rs.next(); rs.next();
String result = rs.getString(1); String result = rs.getString(1);
assertTrue(result.contains("/* PUBLIC.TEST.tableScan")); assertTrue(result.contains("/* PUBLIC.TEST.tableScan"));
conn.close();
} }
private void testWithInvalidIndexName() throws SQLException { private void testWithInvalidIndexName() throws SQLException {
Connection conn = getConnection("indexhints");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
try { try {
stat.executeQuery("explain analyze select * " + stat.executeQuery("explain analyze select * " +
...@@ -148,8 +135,6 @@ public class TestIndexHints extends TestBase { ...@@ -148,8 +135,6 @@ public class TestIndexHints extends TestBase {
+ "Index \"IDX_DOESNT_EXIST\" not found"); + "Index \"IDX_DOESNT_EXIST\" not found");
} catch (SQLException e) { } catch (SQLException e) {
assertEquals(ErrorCode.INDEX_NOT_FOUND_1, e.getErrorCode()); assertEquals(ErrorCode.INDEX_NOT_FOUND_1, e.getErrorCode());
} finally {
conn.close();
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论