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
RenderTable.WHEN_MULTIPLE_TABLES only works with table lists, not with joins #15993
Comments
Huh, yes, thanks for your report. Interesting, we should check if the single element in Should be an easy fix |
Fixed in versions:
Thanks again for your report! |
There are other cases when the setting currently fails, including:
|
What's the reason for using this flag, if I may ask? |
Wow. thanks for very quick fix @lukaseder We wanted to make our queries shorter. With always adding schema and table name to column names our queries were way too long to track them in GoogleCloud SQL query insights. Queries displayed there are cut to 1000 chars so usually we're not able to see conditions for most of our queries. We're using sharding so we have multiple schemas per db host and in result removing just schema name is no go for us. I'm currently working on optimizing our db queries and seeing query stats but not being able to see whole query make this task harder. This render table feature is perfect for that by making queries more compact To sum up we don't have any must have use case case for that feature but it's quality of life feature if you analyze queries from db side by making queries shorter and more compact. |
I see. Well, the simplest way to shorten your queries' SQL string length is to always alias your tables. That way, the fully qualified table identifier remains in the At least, this works as workarounds until all known issues of this flag are fixed. |
Thanks for the tip. We already thought about aliases. The main problem is how to enforce it in automatic way and that it will be transparent for other engineers. We already have couple hundreds if not more than thousands of existed queries and few dozens engineers working on the project. Like I said it's quality of life change for us not something essential so we can wait for proper fix. For sure then I can test it on huge number of existed queries and leave feedback again if needed. |
I see, in that case, a flag would indeed work best. I've often wondered if yet another flag that removes schema qualification only in references not in declarations would be helpful. I.e. this: select t.col
from schema.t.col As long as there are no ambiguous tables |
I think yes if |
There's always an edge case...
I don't think it will be, at least compared to
I don't know. It seems like one of those "quick wins" for trivial queries, but as soon as the query gets mildly complex (a single join or subquery being "complex"), then it's completely useless. I thought about your other comments again:
Do you ever need multiple schemas per query? Otherwise, why not just set the
How about patching generated code such that all table references in the generated public class Tables {
public static Book BOOK = com.example.Book.BOOK.as("book");
} |
Expected behavior
org.jooq.impl.SelectQueryImpl#accept0
will detect if there are joins in query if WHEN_MULTIPLE_TABLES is set and force adding table names in column names in such casePlace to change in code -
org.jooq.impl.SelectQueryImpl#accept0
:getFrom().size()
need to be replaced as in case of join in query it only contains oneorg.jooq.impl.Join
object and only then this object contains inside 2 tables so justsize()
ongetFrom()
doesn't cover all cases of multiple tables in query.Simple solution for
join
case should be adding to condition&& !(getFrom().get(0) instanceof JoinTable)
but maybe there is more cases to cover that I'm also not aware.Actual behavior
When WHEN_MULTIPLE_TABLES is set in settings table name is not added to column name when query contains multiple tables in join.
Example code for query:
Error with generated query:
Root cause:
Condition in
org.jooq.impl.SelectQueryImpl#accept0
doesn't recognize multiple tables inJoin
objects ingetFrom()
Steps to reproduce the problem
Set
renderTable
inSettings
toWHEN_MULTIPLE_TABLES
.Create code with query containing
join
with columns with the same name inon
likeselect(...).from(x).join(y).on(x.z.eq(y.z))
jOOQ Version
3.19.1
Database product and version
8.0.33-google
Java Version
openjdk 17.0.9 2023-10-17
OS Version
No response
JDBC driver name and version (include name if unofficial driver)
No response
The text was updated successfully, but these errors were encountered: