| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.expression.condition; |
| 7 |
|
| 8 |
import org.h2.command.query.Query; |
| 9 |
import org.h2.engine.SessionLocal; |
| 10 |
import org.h2.expression.Expression; |
| 11 |
import org.h2.expression.ExpressionVisitor; |
| 12 |
import org.h2.table.ColumnResolver; |
| 13 |
import org.h2.table.TableFilter; |
| 14 |
import org.h2.util.StringUtils; |
| 15 |
|
| 16 |
/** |
| 17 |
* Base class for predicates with a subquery. |
| 18 |
*/ |
| 19 |
abstract class PredicateWithSubquery extends Condition { |
| 20 |
|
| 21 |
/** |
| 22 |
* The subquery. |
| 23 |
*/ |
| 24 |
final Query query; |
| 25 |
|
| 26 |
PredicateWithSubquery(Query query) { |
| 27 |
this.query = query; |
| 28 |
} |
| 29 |
|
| 30 |
@Override |
| 31 |
public void mapColumns(ColumnResolver resolver, int level, int state) { |
| 32 |
query.mapColumns(resolver, level + 1); |
| 33 |
} |
| 34 |
|
| 35 |
@Override |
| 36 |
public Expression optimize(SessionLocal session) { |
| 37 |
query.prepare(); |
| 38 |
return this; |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public void setEvaluatable(TableFilter tableFilter, boolean value) { |
| 43 |
query.setEvaluatable(tableFilter, value); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags) { |
| 48 |
return StringUtils.indent(builder.append('('), query.getPlanSQL(sqlFlags), 4, false).append(')'); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public void updateAggregate(SessionLocal session, int stage) { |
| 53 |
query.updateAggregate(session, stage); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public boolean isEverything(ExpressionVisitor visitor) { |
| 58 |
return query.isEverything(visitor); |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public int getCost() { |
| 63 |
return query.getCostAsExpression(); |
| 64 |
} |
| 65 |
|
| 66 |
} |