方解石SQL性能调整

时间:2019-02-21 02:38:52

标签: apache-calcite

我用方解石做一些sql工作,下面是一个简单的测试代码:

String json = "{\"DATA\":{\"CAR_NO\":123123},\"USER_ID\":300,\"USER_NAME\":\"user1\"}";
    ResultSet resultSet = null;
    long begin = System.currentTimeMillis();

    for (int j = 0; j < 1000; j++) {
        Statement statement = connection.createStatement();

        rootSchema.add("testDB", new JsonSchema("testTAB", json));

        resultSet = statement.executeQuery(
                "select * from \"testDB\".\"testTAB\" where USER_ID =300 order by USER_ID desc ");

        while (resultSet.next()) {
            JSONObject jo = new JSONObject();
            int n = resultSet.getMetaData().getColumnCount();
            for (int i = 1; i <= n; i++) {
                jo.put(resultSet.getMetaData().getColumnName(i), resultSet.getObject(i));
            }
        }

        resultSet.close();
        statement.close();
        connection.close();
    }

    System.out.println("Time elapsed:" + (System.currentTimeMillis() - begin));

对我来说,方解石的执行时间似乎很慢,for循环执行500次需要13秒,1000次执行需要22秒。我发现statement.executeQuery花费了大部分时间
有什么性能调整线索吗?谢谢

0 个答案:

没有答案