private static float getDistinctEstimate(PlanNode node, QueryMetadataInterface metadata, float cost) throws QueryMetadataException, TeiidComponentException { PlanNode projectNode = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT); float result = cost; if (projectNode != null) { result = getNDVEstimate(node.getParent(), metadata, cost, (List)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS), false); if (result == UNKNOWN_VALUE) { if (cost == UNKNOWN_VALUE) { return UNKNOWN_VALUE; } return cost/2; } } return result; } private static void setCardinalityEstimate(PlanNode node, Float bestEstimate, boolean setColEstimates, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
private static float getDistinctEstimate(PlanNode node, QueryMetadataInterface metadata, float cost) throws QueryMetadataException, TeiidComponentException { PlanNode projectNode = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT); float result = cost; if (projectNode != null) { result = getNDVEstimate(node.getParent(), metadata, cost, (List)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS), false); if (result == UNKNOWN_VALUE) { if (cost == UNKNOWN_VALUE) { return UNKNOWN_VALUE; } return cost/2; } } return result; } private static void setCardinalityEstimate(PlanNode node, Float bestEstimate, boolean setColEstimates, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
private static float getDistinctEstimate(PlanNode node, QueryMetadataInterface metadata, float cost) throws QueryMetadataException, TeiidComponentException { PlanNode projectNode = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT); float result = cost; if (projectNode != null) { result = getNDVEstimate(node.getParent(), metadata, cost, (List)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS), false); if (result == UNKNOWN_VALUE) { if (cost == UNKNOWN_VALUE) { return UNKNOWN_VALUE; } return cost/2; } } return result; } private static void setCardinalityEstimate(PlanNode node, Float bestEstimate, boolean setColEstimates, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
cardinality = NewCalculateCostUtil.computeCostForTree(indNode, metadata); comp.ndv = NewCalculateCostUtil.getNDVEstimate(indNode, metadata, cardinality, elems, true); if (bound) { if (dca != null) {
cardinality = NewCalculateCostUtil.computeCostForTree(indNode, metadata); comp.ndv = NewCalculateCostUtil.getNDVEstimate(indNode, metadata, cardinality, elems, true); if (bound) { if (dca != null) {
cardinality = NewCalculateCostUtil.computeCostForTree(indNode, metadata); comp.ndv = NewCalculateCostUtil.getNDVEstimate(indNode, metadata, cardinality, elems, true); if (bound) { if (dca != null) {
float ndv = NewCalculateCostUtil.getNDVEstimate(planNode, metadata, cardinality, stagedGroupingSymbols, false); if (ndv != NewCalculateCostUtil.UNKNOWN_VALUE && cardinality / ndv < 4) { continue;
float ndv = NewCalculateCostUtil.getNDVEstimate(planNode, metadata, cardinality, stagedGroupingSymbols, false); if (ndv != NewCalculateCostUtil.UNKNOWN_VALUE && cardinality / ndv < 4) { continue;
float ndv = NewCalculateCostUtil.getNDVEstimate(planNode, metadata, cardinality, stagedGroupingSymbols, false); if (ndv != NewCalculateCostUtil.UNKNOWN_VALUE && cardinality / ndv < 4) { continue;
/** * For a Group or Dup Removal node, the cost is basically the smaller of the largest NDV of the * selected columns and cost of the child node (if it is known). * @param node * @param metadata * @throws QueryMetadataException * @throws TeiidComponentException */ private static void estimateNodeCost(PlanNode node, List expressions, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException { PlanNode child = node.getFirstChild(); float childCost = child.getCardinality(); if(childCost == UNKNOWN_VALUE) { setCardinalityEstimate(node, null, true, metadata); return; } float cardinality = getNDVEstimate(node, metadata, childCost, expressions, true); setCardinalityEstimate(node, cardinality, true, metadata); }
/** * For a Group or Dup Removal node, the cost is basically the smaller of the largest NDV of the * selected columns and cost of the child node (if it is known). * @param node * @param metadata * @throws QueryMetadataException * @throws TeiidComponentException */ private static void estimateNodeCost(PlanNode node, List expressions, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException { PlanNode child = node.getFirstChild(); float childCost = child.getCardinality(); if(childCost == UNKNOWN_VALUE) { setCardinalityEstimate(node, null, true, metadata); return; } float cardinality = getNDVEstimate(node, metadata, childCost, expressions, true); setCardinalityEstimate(node, cardinality, true, metadata); }
/** * For a Group or Dup Removal node, the cost is basically the smaller of the largest NDV of the * selected columns and cost of the child node (if it is known). * @param node * @param metadata * @throws QueryMetadataException * @throws TeiidComponentException */ private static void estimateNodeCost(PlanNode node, List expressions, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException { PlanNode child = node.getFirstChild(); float childCost = child.getCardinality(); if(childCost == UNKNOWN_VALUE) { setCardinalityEstimate(node, null, true, metadata); return; } float cardinality = getNDVEstimate(node, metadata, childCost, expressions, true); setCardinalityEstimate(node, cardinality, true, metadata); }
float leftNdv = getNDVEstimate(child1, metadata, childCost1, leftExpressions, false); float rightNdv = getNDVEstimate(child2, metadata, childCost2, rightExpressions, false); float leftNdv1 = getNDVEstimate(child1, metadata, childCost1, leftExpressions, true); float rightNdv1 = getNDVEstimate(child2, metadata, childCost2, rightExpressions, true);
float leftNdv = getNDVEstimate(child1, metadata, childCost1, leftExpressions, false); float rightNdv = getNDVEstimate(child2, metadata, childCost2, rightExpressions, false); float leftNdv1 = getNDVEstimate(child1, metadata, childCost1, leftExpressions, null); float rightNdv1 = getNDVEstimate(child2, metadata, childCost2, rightExpressions, null);
float leftNdv = getNDVEstimate(child1, metadata, childCost1, leftExpressions, false); float rightNdv = getNDVEstimate(child2, metadata, childCost2, rightExpressions, false); float leftNdv1 = getNDVEstimate(child1, metadata, childCost1, leftExpressions, true); float rightNdv1 = getNDVEstimate(child2, metadata, childCost2, rightExpressions, true);
Collection<ElementSymbol> indElements = ElementCollectorVisitor.getElements(indExpr, true); float indSymbolNDV = getNDVEstimate(independentNode, metadata, independentCardinality, indElements, true); boolean unknownNDV = false; if (indSymbolNDV == UNKNOWN_VALUE) { float depSymbolNDV = getNDVEstimate(target, metadata, depTargetCardinality, depElems, isAccess?true:null); boolean usesKey = usesKey(target, depElems, metadata); if (depSymbolNDV == UNKNOWN_VALUE) { if (unknownNDV || depSymbolNDV > 2 * getNDVEstimate(target, metadata, depTargetCardinality, depElems, null)) { continue;
Collection<ElementSymbol> indElements = ElementCollectorVisitor.getElements(indExpr, true); float indSymbolNDV = getNDVEstimate(independentNode, metadata, independentCardinality, indElements, true); boolean unknownNDV = false; if (indSymbolNDV == UNKNOWN_VALUE) { float depSymbolNDV = getNDVEstimate(target, metadata, depTargetCardinality, depElems, isAccess?true:null); boolean usesKey = usesKey(target, depElems, metadata); if (depSymbolNDV == UNKNOWN_VALUE) { if (unknownNDV || depSymbolNDV > 2 * getNDVEstimate(target, metadata, depTargetCardinality, depElems, null)) { continue;
List rightExpressions = (List)joinNode.getProperty(NodeConstants.Info.RIGHT_EXPRESSIONS); float sourceNdv = NewCalculateCostUtil.getNDVEstimate(sourceNode, metadata, sourceCost, entry.leftCandidate?leftExpressions:rightExpressions, true); float siblingNdv = NewCalculateCostUtil.getNDVEstimate(siblingNode, metadata, siblingCost, entry.leftCandidate?rightExpressions:leftExpressions, true);
List rightExpressions = (List)joinNode.getProperty(NodeConstants.Info.RIGHT_EXPRESSIONS); float sourceNdv = NewCalculateCostUtil.getNDVEstimate(sourceNode, metadata, sourceCost, entry.leftCandidate?leftExpressions:rightExpressions, true); float siblingNdv = NewCalculateCostUtil.getNDVEstimate(siblingNode, metadata, siblingCost, entry.leftCandidate?rightExpressions:leftExpressions, true);
List rightExpressions = (List)joinNode.getProperty(NodeConstants.Info.RIGHT_EXPRESSIONS); float sourceNdv = NewCalculateCostUtil.getNDVEstimate(sourceNode, metadata, sourceCost, entry.leftCandidate?leftExpressions:rightExpressions, true); float siblingNdv = NewCalculateCostUtil.getNDVEstimate(siblingNode, metadata, siblingCost, entry.leftCandidate?rightExpressions:leftExpressions, true);