I use Slick 1.0.0-RC1. I have this definition for table object:
object ProductTable extends Table[(Int, String, String, String, Double, java.sql.Date, Int, Option[Int], Int, Boolean)]("products") {
def id = column[Int]("productId", O.PrimaryKey, O.AutoInc)
def title = column[String]("title")
def description = column[String]("description")
def shortDescription = column[String]("shortDescription")
def price = column[Double]("price")
def addedDate = column[java.sql.Date]("addedDate")
def brandId = column[Int]("brandId")
def defaultImageId = column[Option[Int]]("defaultImageId")
def visitCounter = column[Int]("visitCounter")
def archived = column[Boolean]("archived")
def * = id ~ title ~ description ~ shortDescription ~ price ~ addedDate ~ brandId ~ defaultImageId ~ visitCounter ~ archived
}
I need a simple query which selects 8 rows from database:
ProductTable.filter(_.title === "something")
.sortBy(_.visitCounter)
.map(_.title)
.take(8)
.selectStatement
And the output is:
select x2.x3 from
(select x4.`title` as x3 from `products` x4
where x4.`title` = 'something'
order by x4.`visitCounter` limit 8) x2
If I get rid of take()
method:
ProductTable.filter(_.title === "something")
.sortBy(_.visitCounter)
.map(_.title)
.selectStatement
then the output is:
select x2.`title` from `products` x2
where x2.`title` = 'something'
order by x2.`visitCounter`
So my question is: Why does Slick generate a subquery when its query object is constructed with take()
method?
P.S. If it can be related, I use MySql driver with all of these