From 9e1a34680136c8ae3512497b5707ca2ef06adc1c Mon Sep 17 00:00:00 2001 From: ClownXC <598457447@qq.com> Date: Sun, 5 Jan 2025 09:01:49 +0800 Subject: [PATCH] [CALCITE-6763] Optimize logic to select the tiles with the fewest rows Optim define tile --- .../calcite/materialize/MaterializationService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java b/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java index 91cdeca0c05..195f50fb917 100644 --- a/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java +++ b/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java @@ -50,7 +50,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.PriorityQueue; import java.util.Set; import static org.apache.calcite.linq4j.Nullness.castNonNull; @@ -241,8 +240,7 @@ private MaterializationService() { // TODO: Use a partially-ordered set data structure, so we are not scanning // through all tiles. if (!exact) { - final PriorityQueue> queue = - new PriorityQueue<>(1, C); + Pair bestCandidate = null; for (Map.Entry entry : actor.keyByTile.entrySet()) { final TileKey tileKey2 = entry.getKey(); @@ -254,13 +252,13 @@ && allSatisfiable(measureList, tileKey2)) { final CalciteSchema.TableEntry tableEntry = checkValid(materializationKey); if (tableEntry != null) { - queue.add(Pair.of(tableEntry, tileKey2)); + Pair candidate = Pair.of(tableEntry, tileKey2); + if (bestCandidate == null || C.compare(candidate, bestCandidate) < 0) { + bestCandidate = candidate; + } } } } - if (!queue.isEmpty()) { - return queue.peek(); - } } // What we need is not there. If we can't create, we're done.