How to write a simple but optimized left join for MySQL in Slick

How would I write the equivalent of this LEFT OUTER JOIN request using Slick?

SELECT i.itemid, p.propvalue
FROM items i
LEFT JOIN properties p ON i.itemid = p.itemid AND p.propname = "Property Name"
WHERE i.available

I read the documents, and it seemed that this was just what I needed.

for {
  (i, p) <- Items leftJoin Properties on ((i, p) => (i.itemid === p.itemid && p.propname === "Property Name")) if i.available === 1.toByte
} yield (i.itemid, p.propvalue)

However, Slick writes a very complex query with subqueries, which leads to poor performance and actually causes MySQL to hang on what looks like any machine, but to my dev machine. I am using Slick 2.02 on Scala 2.10.4.

I even get subqueries from something even simpler

for {
  (i, p) <- Items leftJoin Properties on (_.itemid === _.itemid)
} yield (i.itemid, p.propvalue)

What am I doing wrong? How to get Slick to write a LEFT JOIN like the one I wrote in MySQL above?

+4
source share

All Articles