This is an automated email from the ASF dual-hosted git repository.

sereda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new 59aa115  [CALCITE-2909] Optimize Enumerable SemiJoin with lazy 
computation of innerLookup (Ruben Quesada Lopez)
59aa115 is described below

commit 59aa1153cfc60c8c29af3eccdbf353b3887926ef
Author: rubenada <[email protected]>
AuthorDate: Mon Mar 11 11:15:05 2019 +0100

    [CALCITE-2909] Optimize Enumerable SemiJoin with lazy computation of 
innerLookup (Ruben Quesada Lopez)
---
 .../java/org/apache/calcite/linq4j/EnumerableDefaults.java     | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java 
b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
index 33aa145..2625bb8 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
@@ -34,6 +34,8 @@ import 
org.apache.calcite.linq4j.function.NullableLongFunction1;
 import org.apache.calcite.linq4j.function.Predicate1;
 import org.apache.calcite.linq4j.function.Predicate2;
 
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Sets;
 
@@ -1298,14 +1300,16 @@ public abstract class EnumerableDefaults {
       final EqualityComparer<TKey> comparer) {
     return new AbstractEnumerable<TSource>() {
       public Enumerator<TSource> enumerator() {
-        final Enumerable<TKey> innerLookup =
+        // CALCITE-2909 Delay the computation of the innerLookup until the 
moment when we are sure
+        // that it will be really needed, i.e. when the first outer enumerator 
item is processed
+        final Supplier<Enumerable<TKey>> innerLookup = Suppliers.memoize(() ->
             comparer == null
                 ? inner.select(innerKeySelector).distinct()
-                : inner.select(innerKeySelector).distinct(comparer);
+                : inner.select(innerKeySelector).distinct(comparer));
 
         return EnumerableDefaults.where(outer.enumerator(), v0 -> {
           final TKey key = outerKeySelector.apply(v0);
-          return innerLookup.contains(key);
+          return innerLookup.get().contains(key);
         });
       }
     };

Reply via email to