Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impure Infix Clauses are removed via column pruning #1583

Closed
deusaquilus opened this issue Aug 26, 2019 · 1 comment
Closed

Impure Infix Clauses are removed via column pruning #1583

deusaquilus opened this issue Aug 26, 2019 · 1 comment

Comments

@deusaquilus
Copy link
Collaborator

deusaquilus commented Aug 26, 2019

Version: (e.g. 3.4.4-SNAPSHOT)
Module: (e.g. quill-sql)
Database: (e.g. ALL)

The current behavior of column pruning removes a column from all queries and subqueries where it is not used. For example:

case class Person(id:Int, name:String, other:Int)
run { query[Person].map(p => (p.id, p.name, p.other)).map(t => (t._1, t._2)) }
// SELECT p.id, p.name FROM person p

Note that this behavior happens even with nested queries:

run { query[Person].map(p => (p.id, p.name, p.other)).nested.map(t => (t._1, t._2)) }
// SELECT p.id, p.name FROM (SELECT x.id, x.name FROM person x) AS p

The same behavior occurs with infixes:

run { query[Person].map(p => (p.id, p.name, infix"foobar${p.other}")).map(t => (t._1, t._2)) }
// SELECT p.id, p.name FROM person p

While this kind of behavior should be fine for pure infixes, infixes such as rank and distinct on totally break by this behavior:

run { query[Person].map(p => (infix"DISTINCT ON (${p.other})".as[Int], p.name, p.id)).map(t => (t._2, t._3)) }
// SELECT p.name, p.id FROM person p

In general, it seems that for impure-infixes, the assumption that the infix clause can be pruned with the containing column is incorrect. The SQL normalization needs to be changed accordingly.

@getquill/maintainers

@deusaquilus
Copy link
Collaborator Author

Fixed via #1597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant