-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix expression predicate pushdown not firing before AddExchanges #11083
Fix expression predicate pushdown not firing before AddExchanges #11083
Conversation
4d1a5e9
to
cb42214
Compare
(rebased) |
cb42214
to
f619fa5
Compare
if (constraint.predicate().isEmpty() && newDomain.contains(node.getEnforcedConstraint())) { | ||
if (constraint.predicate().isEmpty() && | ||
// TODO do we need to track enforced ConnectorExpression in TableScanNode? | ||
TRUE.equals(connectorExpression.orElse(TRUE)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is clearer:
Optional.of(TRUE).equals(connectorExpression)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connectorExpression.orElse(TRUE)
is already used in oither places in this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unrelated question for my understanding/learning.
LGTM otherwise.
...trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushPredicateIntoTableScan.java
Show resolved
Hide resolved
Previous build failure https://github.com/trinodb/trino/runs/5435574464
re-run. |
Failure looks related, but it's unclear yet what's the mechanics of that. |
cc: @ebyhr |
69d8776
to
14fe409
Compare
(just rebased) |
The class's toString is used in EXPLAIN and was missing since class was converted not to be enum.
The toString is user-visible in EXPLAIN. It should include all the filtering-related information.
14fe409
to
e8c1d0d
Compare
This looks like a Cassandra bug to me. Before the change, the filter was subsumed, and This is fixed with |
Before the change, the pushdown of `ConnectorExpression` was fired only when - there was some other `TupleDomain` constraint to be pushed down, OR - during `AddExchanges`, because functional predicate is created there. This commit enables expression-based pushdown early, allowing further pushdowns -- like aggregation or join pushdown -- to happen. These need to happen before `AddExchanges`.
e8c1d0d
to
4600f05
Compare
...trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushPredicateIntoTableScan.java
Outdated
Show resolved
Hide resolved
Pushing dynamic filters into a connector, as part of `Constraint.expression`, is void, as connector cannot make any sense of dynamic filters. This also avoids `ConnectorMetadata.applyFilter` when dynamic filter is the only predicate in the `FilterNode`.
e6ba9f2
to
37ffe62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -105,6 +108,21 @@ public boolean equals(Object obj) | |||
@Override | |||
public String toString() | |||
{ | |||
return schemaName + ":" + tableName; | |||
String string = format("%s:%s", schemaName, tableName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: string
is a strange name for a variable, could this be changed? (I see it elsewhere in the Cassandra Plugin code, but only 2 places).
Most code uses toStringHelper(this)
or else:
StringBuilder builder = new StringBuilder(format("%s:%s", schemaName, tableName));
...
if (this.partitions.isPresent()) {
builder.append(format(" %d partitions %s", partitions.size(), Stream.concat(....
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HiveTableHandle
handles it like this:
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append(schemaName).append(":").append(tableName);
bucketHandle.ifPresent(bucket -> {
builder.append(" buckets=").append(bucket.getReadBucketCount());
if (!bucket.getSortedBy().isEmpty()) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leveyja if i were using StringBuilder
i would indeed use builder
and i had this this way originally.
However, there is no benefit of using StringBuilder
in this code (no performance gain), and append
vs +=
is just more verbose, so i switch to String
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@findepi String string
is just something I've never seen before. StringBuilder builder
- it is a builder, it's common.
If you want to stick with String
+ concatenation, I'd use String toString
to give it more meaning.
Object object
, List list
, all of these are redundant / unseen in my experience.
Re: performance gain - it's not in an inner loop, but there are intermediate strings generated by all the concatenations (I count at least 10), so while I wouldn't classify it as "performance gain", I'd see it as much better to use a builder for arbitrary String concatenation, unless it is absolutely trivial (e.g., throw new IllegalStateException("blah " + input)
StringBuilder builder = new StringBuilder(schemaName).append(":").append(tableName);
^ This removes the String.format("%s:%s")
- so I'd say we go with it. String string
honestly made me comment - it's very weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String toString
would be fine, i don't see much difference. Perhaps it could also be result
StringBuilder builder
would be OK too. I just find it hard to read and will prefer ordinary string concatenation -- as implemented in this PR, or here
trino/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultQueryBuilder.java
Lines 79 to 93 in bf79840
String sql = "SELECT " + getProjection(client, columns, columnExpressions); | |
sql += getFrom(client, baseRelation, accumulator::add); | |
List<String> clauses = toConjuncts(client, session, connection, tupleDomain, accumulator::add); | |
if (additionalPredicate.isPresent()) { | |
clauses = ImmutableList.<String>builder() | |
.addAll(clauses) | |
.add(additionalPredicate.get()) | |
.build(); | |
} | |
if (!clauses.isEmpty()) { | |
sql += " WHERE " + Joiner.on(" AND ").join(clauses); | |
} | |
sql += getGroupBy(client, groupingSets); |
anyway, i am open for this to be changed
@Override | ||
public String toString() | ||
{ | ||
String string = format("%s(%s", kind, trinoType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use StringBuilder
to remove the String string
variable and intermediate string creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no performance benefit to doing so, as java internally replaces this with StringBuilder, and it doesn't improve readability IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original comment is on the String string
naming - String toStirng
is better.
If we're arguing about performance benefit, why use String.format here instead of concatenation?
//String string = format("%s(%s", kind, trinoType);
String toString = kind + "(" _ trinoTyper;
Ultimately, my comment is: this toString()
method differs from all others in style + variable naming - arguing about the performance isn't really my point - it's consistency. Thanks for pointing out Java (sometimes) optimizes "a" + "b" + "c"
to use StringBuilder - I suggested StringBuilder to match the existing style, and as a (possible) workaround for the String string
naming.
I'd still suggest you rename that String toString
, whatever else about String.format + builder, etc 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annnnd now I see it's merged :-)
Ignore me! ;-)
master is broken due to 70c988b |
Thanks @sopel39 after merging this i see failure
https://github.com/trinodb/trino/runs/5508053581?check_suite_focus=true weird side is, the CI was green for this PR |
Before the change, the pushdown of
ConnectorExpression
was fired onlywhen
TupleDomain
constraint to be pushed down, ORAddExchanges
, because functional predicate is created there.This commit enables expression-based pushdown early, allowing further
pushdowns -- like aggregation or join pushdown -- to happen. These need
to happen before
AddExchanges
.Extracted from #11045
Relates to #18