提交 a85c7840 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Check count of table scans in testFunctionIndex() and add a comment in IndexCursor

上级 d2b6a1bf
......@@ -89,6 +89,8 @@ public class IndexCursor implements Cursor {
alwaysFalse = true;
break;
}
// If index can perform only full table scan do not try to use it for regular
// lookups, each such lookup will perform an own table scan.
if (index.isFindUsingFullTableScan()) {
continue;
}
......
......@@ -16,6 +16,7 @@ import java.util.HashSet;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import org.h2.api.ErrorCode;
import org.h2.command.dml.Select;
import org.h2.result.SortOrder;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
......@@ -26,6 +27,8 @@ import org.h2.value.ValueInt;
*/
public class TestIndex extends TestBase {
private static int testFunctionIndexCounter;
private Connection conn;
private Statement stat;
private final Random random = new Random();
......@@ -708,6 +711,14 @@ public class TestIndex extends TestBase {
}
public static ResultSet testFunctionIndexFunction() {
// There are additional callers like JdbcConnection.prepareCommand() and
// CommandContainer.recompileIfReqired()
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
if (element.getClassName() == Select.class.getName()) {
testFunctionIndexCounter++;
break;
}
}
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ID", Types.INTEGER, ValueInt.PRECISION, 0);
rs.addColumn("VALUE", Types.INTEGER, ValueInt.PRECISION, 0);
......@@ -718,6 +729,7 @@ public class TestIndex extends TestBase {
}
private void testFunctionIndex() throws SQLException {
testFunctionIndexCounter = 0;
stat.execute("CREATE ALIAS TEST_INDEX FOR \"" + TestIndex.class.getName() + ".testFunctionIndexFunction\"");
try (ResultSet rs = stat.executeQuery("SELECT * FROM TEST_INDEX() WHERE ID = 1 OR ID = 3")) {
assertTrue(rs.next());
......@@ -730,6 +742,7 @@ public class TestIndex extends TestBase {
} finally {
stat.execute("DROP ALIAS TEST_INDEX");
}
assertEquals(1, testFunctionIndexCounter);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论