1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.compile.Optimizable; 25 import org.apache.derby.iapi.sql.compile.OptimizableList; 26 import org.apache.derby.iapi.sql.compile.OptimizablePredicate; 27 import org.apache.derby.iapi.sql.compile.OptimizablePredicateList; 28 import org.apache.derby.iapi.sql.compile.Optimizer; 29 import org.apache.derby.iapi.sql.compile.CostEstimate; 30 import org.apache.derby.iapi.sql.compile.Visitable; 31 import org.apache.derby.iapi.sql.compile.Visitor; 32 import org.apache.derby.iapi.sql.compile.RequiredRowOrdering; 33 import org.apache.derby.iapi.sql.compile.RowOrdering; 34 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 35 36 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 37 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 38 39 import org.apache.derby.iapi.sql.Activation; 40 import org.apache.derby.iapi.sql.ResultSet; 41 import org.apache.derby.iapi.reference.ClassName; 42 43 import org.apache.derby.iapi.services.classfile.VMOpcode; 44 45 import org.apache.derby.iapi.error.StandardException; 46 47 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 48 49 import org.apache.derby.iapi.services.compiler.MethodBuilder; 50 51 import org.apache.derby.iapi.services.sanity.SanityManager; 52 53 import org.apache.derby.iapi.util.JBitSet; 54 55 56 import java.util.Properties ; 57 import java.util.Vector ; 58 59 71 public class DistinctNode extends SingleChildResultSetNode 72 { 73 boolean inSortedOrder; 74 75 85 public void init( 86 Object childResult, 87 Object inSortedOrder, 88 Object tableProperties) throws StandardException 89 { 90 super.init(childResult, tableProperties); 91 92 if (SanityManager.DEBUG) 93 { 94 if (!(childResult instanceof Optimizable)) 95 { 96 SanityManager.THROWASSERT("childResult, " + childResult.getClass().getName() + 97 ", expected to be instanceof Optimizable"); 98 } 99 if (!(childResult instanceof FromTable)) 100 { 101 SanityManager.THROWASSERT("childResult, " + childResult.getClass().getName() + 102 ", expected to be instanceof FromTable"); 103 } 104 } 105 106 ResultColumnList prRCList; 107 108 115 116 119 prRCList = this.childResult.getResultColumns().copyListAndObjects(); 120 resultColumns = this.childResult.getResultColumns(); 121 this.childResult.setResultColumns(prRCList); 122 123 127 resultColumns.genVirtualColumnNodes(this, prRCList); 128 129 132 resultColumns.verifyAllOrderable(); 133 134 this.inSortedOrder = ((Boolean ) inSortedOrder).booleanValue(); 135 } 136 137 140 141 146 public CostEstimate optimizeIt(Optimizer optimizer, 147 OptimizablePredicateList predList, 148 CostEstimate outerCost, 149 RowOrdering rowOrdering) 150 throws StandardException 151 { 152 CostEstimate childCost = 153 ((Optimizable) childResult).optimizeIt(optimizer, 154 predList, 155 outerCost, 156 rowOrdering); 157 158 return super.optimizeIt(optimizer, predList, outerCost, rowOrdering); 159 } 160 161 166 public CostEstimate estimateCost(OptimizablePredicateList predList, 167 ConglomerateDescriptor cd, 168 CostEstimate outerCost, 169 Optimizer optimizer, 170 RowOrdering rowOrdering) 171 throws StandardException 172 { 173 CostEstimate childCost = 176 ((Optimizable) childResult).estimateCost(predList, 177 cd, 178 outerCost, 179 optimizer, 180 rowOrdering); 181 182 costEstimate = getCostEstimate(optimizer); 183 costEstimate.setCost(childCost.getEstimatedCost(), 184 childCost.rowCount(), 185 childCost.singleScanRowCount()); 186 187 188 192 return costEstimate; 193 } 194 195 200 201 public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate) 202 throws StandardException 203 { 204 return false; 205 } 207 208 214 215 public String toString() 216 { 217 if (SanityManager.DEBUG) 218 { 219 return childResult.toString() + "\n" + super.toString(); 220 } 221 else 222 { 223 return ""; 224 } 225 } 226 227 239 240 public ResultSetNode optimize(DataDictionary dataDictionary, 241 PredicateList predicates, 242 double outerRows) 243 throws StandardException 244 { 245 248 childResult = (ProjectRestrictNode) childResult.optimize( 249 dataDictionary, 250 predicates, 251 outerRows); 252 Optimizer optimizer = getOptimizer( 253 (FromList) getNodeFactory().getNode( 254 C_NodeTypes.FROM_LIST, 255 getNodeFactory().doJoinOrderOptimization(), 256 this, 257 getContextManager()), 258 predicates, 259 dataDictionary, 260 (RequiredRowOrdering) null); 261 262 costEstimate = optimizer.newCostEstimate(); 265 266 costEstimate.setCost(childResult.getCostEstimate().getEstimatedCost(), 267 childResult.getCostEstimate().rowCount(), 268 childResult.getCostEstimate().singleScanRowCount()); 269 270 return this; 271 } 272 273 286 boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, Vector fbtVector) 287 { 288 292 return false; 293 } 294 295 301 public void generate(ActivationClassBuilder acb, 302 MethodBuilder mb) 303 throws StandardException 304 { 305 308 assignResultSetNumber(); 309 310 costEstimate = childResult.getFinalCostEstimate(); 312 313 316 int orderItem = acb.addItem(acb.getColumnOrdering(resultColumns)); 317 318 328 329 acb.pushGetResultSetFactoryExpression(mb); 330 331 childResult.generate(acb, mb); 332 mb.push(true); 333 mb.push(inSortedOrder); 334 mb.push(orderItem); 335 resultColumns.generateHolder(acb, mb); 336 mb.push(resultColumns.getTotalColumnSize()); 337 mb.push(resultSetNumber); 338 mb.push(costEstimate.rowCount()); 339 mb.push(costEstimate.getEstimatedCost()); 340 341 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "getSortResultSet", 342 ClassName.NoPutResultSet, 9); 343 } 344 } 345 | Popular Tags |