How do you print the select statements for the following Slick queries?

Jack picture Jack · Feb 12, 2013 · Viewed 10.9k times · Source

I would like to find out which of the following queries would be the most efficient for getting a row count on a table, so I'm trying to print out the select statements. I know you can add.selectStatement to a Queryable but don't know if this tells me the complete truth because I'll have to remove the result generating code, e.g. .list.length and replace it with .selectStatement. Slick probably picks up that you are looking for the length and optimises further, so I want to see the select statement for the whole query, including the SQL that will be generated because of the .list.length, or .count).first

Query(MyTable).list.length

(for{mt <- MyTable} yield mt).list.length

(for{mt <- MyTable} yield mt.count).first

Answer

user1187983 picture user1187983 · Feb 5, 2014

In play-2.2.1 with slick 2.0.0, in application.conf have:

logger.scala.slick.jdbc.JdbcBackend.statement=DEBUG