Search code examples
performancecounth2sorm

How to speed up a simple count operation in SORM?


I'm trying to perform a simple count operation on a large table with SORM. This works inexplicably slow. Code:

case class Tests (datetime: DateTime, value:Double, second:Double)

object DB extends Instance (
  entities = Set() +
    Entity[Tests](),
  url = "jdbc:h2:~/test",
  user = "sa",
  password = "",
  poolSize = 10
)

object TestSORM {
  def main(args: Array[String]) {
    println("Start at " + DB.now())
    println(" DB.query[Tests].count() = " + DB.query[Tests].count())
    println("Finish at " + DB.now())
    DB.close()
  }
}

Results:

Start at 2013-01-28T22:36:05.281+04:00
 DB.query[Tests].count() = 3390132
Finish at = 2013-01-28T22:38:39.655+04:00

It took two and a half minutes! In H2 console 'select count(*) from tests' works in a tick. What is my mistake? Can I execute a sql query through it?

Thanks in advance!


Solution

  • It's a known optimization issue. Currently SORM does not utilize a COUNT operation. Since finally the issue has come up, I'll address it right away. Expect a release fixing this in the comming days.


    The issue fix has been delayed. You can monitor its status on the issue tracker.