Statement.excecuteQuery()
花费太多时间,无论查询是什么。
athenaQuery = "SELECT DISTINCT date " +
"FROM sid.lvmh_shareofshelf_new_cat_all_dod "+
"where scope='PCD' and date!='' and country='" + countryName+ "' " +
"and rname='" + rname + "' and top_category_lvmh='" + top_category_lvmh +
"' ORDER BY date DESC";
stmt = conn.createStatement();
long startTime = System.nanoTime();
rs = stmt.executeQuery(athenaQuery);
long endTime = System.nanoTime();
System.out.println("Total time taken : "+ (endTime - startTime));
所用时间为 2776930359 纳秒(2.776930359 秒)
最佳答案
我不知道你的项目的内部结构。我建议一些对您有帮助的事情。
- 创建准备语句而不是每次都编译。准备带参数的查询。这是您可以做的语法级别优化。
- 每次需要Where子句参数时,都可以为其创建索引。这是数据库级别的优化。
比尝试看看性能提高!!
关于java - Statement.executeQuery() 花费太多时间。有什么办法可以优化这个吗?我正在使用雅典娜数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49399761/