From a3207d65c16189871006a123ac87b619d47042e7 Mon Sep 17 00:00:00 2001 From: Mark Hale Date: Fri, 27 Oct 2023 15:48:42 +0100 Subject: [PATCH] Add support for NAryUnion to evaluation statistics. --- .../optimizers/ExtendedEvaluationStatistics.java | 14 ++++++++++++++ .../gin/halyard/optimizers/NAryUnionOptimizer.java | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/strategy/src/main/java/com/msd/gin/halyard/optimizers/ExtendedEvaluationStatistics.java b/strategy/src/main/java/com/msd/gin/halyard/optimizers/ExtendedEvaluationStatistics.java index 8ab944cd7..788feb48f 100644 --- a/strategy/src/main/java/com/msd/gin/halyard/optimizers/ExtendedEvaluationStatistics.java +++ b/strategy/src/main/java/com/msd/gin/halyard/optimizers/ExtendedEvaluationStatistics.java @@ -1,6 +1,7 @@ package com.msd.gin.halyard.optimizers; import com.google.common.collect.Iterables; +import com.msd.gin.halyard.algebra.NAryUnion; import com.msd.gin.halyard.algebra.StarJoin; import java.io.IOException; @@ -308,11 +309,24 @@ public void meetOther(QueryModelNode node) { meet((TupleFunctionCall)node); } else if (node instanceof StarJoin) { meet((StarJoin)node); + } else if (node instanceof NAryUnion) { + meet((NAryUnion)node); } else { super.meetOther(node); } } + public void meet(NAryUnion node) { + double card = 0.0; + for (TupleExpr expr : node.getArgs()) { + expr.visit(this); + updateMap(expr); + card += this.cardinality; + } + cardinality = card; + updateMap(node); + } + public void meet(StarJoin node) { TupleExpr sp = node.getArg(0); sp.visit(this); diff --git a/strategy/src/main/java/com/msd/gin/halyard/optimizers/NAryUnionOptimizer.java b/strategy/src/main/java/com/msd/gin/halyard/optimizers/NAryUnionOptimizer.java index f936a0e31..7535c637a 100644 --- a/strategy/src/main/java/com/msd/gin/halyard/optimizers/NAryUnionOptimizer.java +++ b/strategy/src/main/java/com/msd/gin/halyard/optimizers/NAryUnionOptimizer.java @@ -20,11 +20,11 @@ public class NAryUnionOptimizer implements QueryOptimizer { private final int minUnions; - public NAryUnionOptimizer(int minJoins) { - if (minJoins < 1) { + public NAryUnionOptimizer(int minUnions) { + if (minUnions < 1) { throw new IllegalArgumentException("Minimum unions must be greater than or equal to one"); } - this.minUnions = minJoins; + this.minUnions = minUnions; } @Override