我们有一个15000000条目数据库,并执行
之类的SELECT。SELECT technical_id, attribute_a, attribute_b, attribute_c from test WHERE ( attribute_a_fltr @> (?::character varying[]) OR attribute_a_fltr = '{n/a}') AND ( attribute_b_fltr @> (?::character varying[]) OR attribute_b_fltr = '{n/a}') AND ( attribute_c = ? OR attribute_c = 0)
将在尝试9次后急剧降低。这是结果
Iteration: 0 Entries: 593 time :6931
Iteration: 1 Entries: 593 time :7879
Iteration: 2 Entries: 593 time :8721
Iteration: 3 Entries: 593 time :9490
Iteration: 4 Entries: 593 time :10240
Iteration: 5 Entries: 593 time :11016
Iteration: 6 Entries: 593 time :11736
Iteration: 7 Entries: 593 time :12461
Iteration: 8 Entries: 593 time :13168
Iteration: 9 Entries: 593 time :152329
Iteration: 10 Entries: 593 time :290717
Iteration: 11 Entries: 593 time :435933
Iteration: 12 Entries: 593 time :567401
Iteration: 13 Entries: 593 time :695307
Iteration: 14 Entries: 593 time :835853
这是Java代码
Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test-db", props);
PreparedStatement prepStatement = connection.prepareStatement(FILTER_7);
prepStatement.setString(1,"{AAAAAAIAAAAAIAAAAAAAAgAAAAAgAAAAAAACAAAAACAAAAAAAAIAAgAAIAAgAAAAAgACAAAgACAAAAAAAAIA}");
prepStatement.setString(2,"{gAAAAAAQAAAAAAIAAABAAAAAAAgAAAAAAQAAACAAAAAABAAAAIAAAAAAEAAAAAACAAAAQAAAAgAIAEAAAAAA}");
prepStatement.setInt(3, 1979);
long t0 = System.currentTimeMillis();
long iter = 0;
while (true) {
ResultSet resultSet = prepStatement.executeQuery();
long count = 0;
while(resultSet.next()) {
++count;
}
System.out.println("Iteration: "+iter +" Entries: "+ count + " time :" + (System.currentTimeMillis() - t0));
++iter;
}