[#1502] Eagerly initialise scope with all tables

This is required to support implicit join paths referencing roots from outer scopes from within correlated subqueries in the SELECT clause
This commit is contained in:
lukaseder 2018-02-09 16:00:27 +01:00
parent 03d197cb33
commit 47b5551982
3 changed files with 16 additions and 5 deletions

View File

@ -182,8 +182,7 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
public RenderContext scopeRegister(QueryPart part) {
if (scopeLevel >= 0) {
if (part instanceof TableImpl) {
Table<?> table = (Table<?>) part;
Table<?> root = table;
Table<?> root = (Table<?>) part;
Table<?> child = root;
List<ForeignKey<?, ?>> keys = new ArrayList<ForeignKey<?, ?>>();
List<Table<?>> tables = new ArrayList<Table<?>>();

View File

@ -142,8 +142,8 @@ implements
private static final EnumSet<SQLDialect> EMULATE_NATURAL_OUTER_JOIN = EnumSet.of(CUBRID, H2);
private static final EnumSet<SQLDialect> EMULATE_JOIN_USING = EnumSet.of(CUBRID, H2);
private final Table<?> lhs;
private final Table<?> rhs;
final Table<?> lhs;
final Table<?> rhs;

View File

@ -452,6 +452,8 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
@Override
public final void accept(Context<?> context) {
context.scopeStart();
for (Table<?> table : getFrom())
registerTable(context, table);
SQLDialect dialect = context.dialect();
SQLDialect family = context.family();
@ -770,6 +772,16 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
context.scopeEnd();
}
private final void registerTable(Context<?> context, Table<?> table) {
if (table instanceof JoinTable) {
registerTable(context, ((JoinTable) table).lhs);
registerTable(context, ((JoinTable) table).rhs);
}
else if (table instanceof TableImpl) {
context.scopeRegister(table);
}
}
private final void pushWindow(Context<?> context) {
// [#531] [#2790] Make the WINDOW clause available to the SELECT clause
// to be able to inline window definitions if the WINDOW clause is not
@ -1786,7 +1798,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
return getSelect0();
}
private <Q extends QueryPartList<? super Field<?>>> Q resolveAsterisk(Q result) {
private final <Q extends QueryPartList<? super Field<?>>> Q resolveAsterisk(Q result) {
// [#109] [#489]: SELECT * is only applied when at least one table
// from the table source is "unknown", i.e. not generated from a