Hey Lukas, Thanks for getting back on this. The way I was imagining it would be something that would warn the developer in development mode. In such a setup, something "too clever" which might have false positives isn't a big deal (as long as there's a way to disable for specific queries).
Alok On Wed, Jul 15, 2015 at 3:02 AM, Lukas Eder <[email protected]> wrote: > Hi Alok, > > I just found that this old mail still lacks an answer to your question at > the bottom... > > 2015-06-23 18:53 GMT+02:00 Alok Menghrajani <[email protected]>: > >> Hi, >> >> I just wanted to point out that when using fetchInto(FOO), you'll >> usually want to also do select(FOO.fields()) and avoid fetching all >> the columns. >> >> For example: >> jooqContext.select() >> .from(AUTHOR) >> .join(BOOK).on(AUTHOR.ID.eq(BOOK.AUTHOR)) >> .where(BOOK.TITLE.eq("nightfall")) >> .fetchInto(AUTHOR); >> >> Will result in: >> select author.id, author.first_name, author.last_name, book.id, >> book.author, book.title from author join book on author.id = >> book.author where book.title = ? >> >> However: >> jooqContext.select(AUTHOR.fields()) >> .from(AUTHOR) >> .join(BOOK).on(AUTHOR.ID.eq(BOOK.AUTHOR)) >> .where(BOOK.TITLE.eq("nightfall")) >> .fetchInto(AUTHOR); >> >> Results in the more efficient: >> select author.id, author.first_name, author.last_name from author join >> book on author.id = book.author where book.title = ? >> >> I'm guessing jooq could be improved to detect when too much data is >> being fetched and thrown away from the database (in development, the >> framework could keep track of which fields were eventually used and >> log some kind of warning?). > > > I think that such an approach is a bit too "clever". Think about it this > way: > > 1. fetchInto(AUTHOR) is just short for fetch().into(AUTHOR), so the > fetch() action is decoupled from the mapping action into(AUTHOR). You could > even map the same Result<?> several times, e.g. once into(AUTHOR) and once > into(BOOK) > 2. You should be the one completely defining your SQL statement, not some > internal rule inside of jOOQ. For instance, the semantics of SELECT > DISTINCT T1.A, T1.B, T2.X, T2.Y FROM ... is very different from the similar > statement SELECT DISTINCT T1.A, T1.B FROM ... > > Hope this helps, > Lukas > > -- > You received this message because you are subscribed to the Google Groups > "jOOQ User Group" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
