zio / zio-quill

Compile-time Language Integrated Queries for Scala
https://zio.dev/zio-quill
Apache License 2.0
2.14k stars 347 forks source link

`Force index` doesn't work with infix query #3026

Open feiluo-db opened 2 months ago

feiluo-db commented 2 months ago

This template isn't a strict requirement to open issues, but please try to provide as much information as possible.

Version: 3.16.2 Module: (e.g. quill-jdbc) quill-jdbc Database: (e.g. mysql) mysql

Expected behavior

Trying to get force index work on a multi table join query.

Tried using raw query with infix and it turns out the force index part is removed in the compiled SQL query.

infix"""
SELECT A.c1, A.c2, B.c1
FROM A force index (iA)
JOIN B force index (iB)
ON A.c3 = B.c3
WHERE
...
""".as[Query[MyEntity]]

The compiled query became

SELECT x11.c1 AS _1, x11.c2 AS _2, x12.c1 AS _3
FROM A x01 
INNER JOIN B x12
ON x11.c3 = x12.c3
WHERE
...

Actual behavior

How can I make force index work

Steps to reproduce the behavior

If the issue can be reproduced using a mirror context, please provide a scastie snippet that reproduces it. See https://scastie.scala-lang.org/fwbrasil/Z2CeR2qHQJK6EyQWUBhANA as an example. Remember to select the correct Quill version in the left menu.

Workaround

@getquill/maintainers