@Test public void testSingleIndex() throws Exception { SPARQLParser parser = new SPARQLParser(); ParsedQuery pq1 = parser.parseQuery(q15, null); ParsedQuery pq2 = parser.parseQuery(q7, null); ParsedQuery pq3 = parser.parseQuery(q8, null); ParsedQuery pq4 = parser.parseQuery(q9, null); SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet( (Projection) pq2.getTupleExpr()); SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet( (Projection) pq3.getTupleExpr()); SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet( (Projection) pq4.getTupleExpr()); List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); list.add(extTup1); List<QueryModelNode> optTupNodes = Lists.newArrayList(); optTupNodes.add(extTup2); optTupNodes.add(extTup3); IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator( pq1.getTupleExpr(), list); Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator() .getPlans(iep.getIndexedTuples()); IndexPlanValidator ipv = new IndexPlanValidator(false); Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans); ThreshholdPlanSelector tps = new ThreshholdPlanSelector( pq1.getTupleExpr()); TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .1, 1, 0, 0); NodeCollector nc = new NodeCollector(); optimalTup.visit(nc); List<QueryModelNode> qNodes = nc.getNodes(); Assert.assertEquals(qNodes.size(), optTupNodes.size()); for (QueryModelNode node : qNodes) { Assert.assertTrue(optTupNodes.contains(node)); } }
@Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } ThreshholdPlanSelector(TupleExpr query); }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } ThreshholdPlanSelector(TupleExpr query); @Override TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight,
            double commonVarWeight, double extProdWeight); double getCost(TupleExpr te, double indexWeight, double commonVarWeight, double dirProdWeight); }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } ThreshholdPlanSelector(TupleExpr query); @Override TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight,
            double commonVarWeight, double extProdWeight); double getCost(TupleExpr te, double indexWeight, double commonVarWeight, double dirProdWeight);  }