提交 3ca9d063 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

TestQueryCache fixed

上级 782069ef
......@@ -38,30 +38,43 @@ public class TestQueryCache extends TestBase {
private void test1() throws Exception {
Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar) " +
"as select x, space(100) from system_range(1, 1000)");
stat.execute("create table test(id int, name varchar)");
PreparedStatement prep;
conn.prepareStatement("select count(*) from test t1, test t2");
// query execution may be fast here but the parsing must be slow
StringBuilder queryBuilder = new StringBuilder("select count(*) from test t1 where \n");
for (int i = 0; i < 1000; i++) {
if (i != 0) {
queryBuilder.append(" and ");
}
queryBuilder.append(" TIMESTAMP '2005-12-31 23:59:59' = TIMESTAMP '2005-12-31 23:59:59' ");
}
String query = queryBuilder.toString();
conn.prepareStatement(query);
long time;
ResultSet rs;
long first = 0;
for (int i = 0; i < 4; i++) {
// 1000 iterations to warm up and avoid JIT effects
for (int i = 0; i < 1010; i++) {
// this should both ensure results are not re-used
// stat.execute("set mode regular");
// stat.execute("create table x()");
// stat.execute("drop table x");
time = System.nanoTime();
prep = conn.prepareStatement("select count(*) from test t1, test t2");
prep = conn.prepareStatement(query);
execute(prep);
rs = stat.executeQuery("select count(*) from test t1, test t2");
prep.close();
rs = stat.executeQuery(query);
rs.next();
int c = rs.getInt(1);
rs.close();
assertEquals(1000000, c);
assertEquals(0, c);
time = System.nanoTime() - time;
if (first == 0) {
if (i == 1000) {
// take from cache and do not close, so that next iteration will have a cache miss
prep = conn.prepareStatement(query);
} else if (i == 1001) {
first = time;
} else {
} else if (i > 1001) {
assertSmaller(time, first);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论