| 1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.table; 2 3 import com.daffodilwoods.daffodildb.client.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.table.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.*; 8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 9 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 10 import com.daffodilwoods.database.resource.*; 11 import com.daffodilwoods.database.sqlinitiator.*; 12 13 23 24 public class DistinctPlan extends PlanExceptionAbstract implements CostFactorConstants { 25 26 29 30 private _TablePlan tablePlan; 31 32 36 37 private _Reference[] selectReferences; 38 39 43 44 private _Reference[] selectListQuestionReferences; 45 46 50 51 private boolean costCalculated; 52 53 public DistinctPlan(_TablePlan tPlan0, _Order order0, _Reference[] selectReferences0, _Reference[] selectListQuestionReferences0) { 54 tablePlan = tPlan0; 55 selectReferences = selectReferences0; 56 selectListQuestionReferences = selectListQuestionReferences0; 57 } 58 59 64 65 public int getType() throws DException { 66 return tablePlan.getType(); 67 } 68 69 75 76 public double getCost(_ServerSession session) throws DException { 77 costCalculated = true; 78 return DISTINCT * tablePlan.getCost(session); 79 } 80 81 90 91 public double getCost(_ServerSession session, booleanvalueexpression condition, long estimatedRows) throws DException { 92 return DISTINCT * tablePlan.getCost(session, condition, estimatedRows); 93 } 94 95 102 103 public _Iterator execute(_ServerSession session) throws DException { 104 if (!costCalculated) { 105 getCost(session); 106 } 107 _Iterator iterator = tablePlan.execute(session); 108 iterator = new DistinctIterator(iterator, selectReferences, selectListQuestionReferences, session); 109 return iterator; 110 } 111 112 122 123 public _Iterator execute(_ServerSession session, booleanvalueexpression condition) throws DException { 124 return new DistinctIterator(tablePlan.execute(session, condition), selectReferences, selectListQuestionReferences, session); 125 } 126 127 134 135 public long getRowCount(_ServerSession serverSession) throws DException { 136 return tablePlan.getRowCount(serverSession) / DISTINCT; 137 } 138 139 144 145 public _Order getOrder() throws DException { 146 return tablePlan.getOrder(); 147 } 148 149 public String getVerifier() throws DException { 150 StringBuffer buffer = new StringBuffer (); 151 buffer.append(tabW("[ DISTINCT_PLAN ]")); 152 buffer.append("\n" + tablePlan.getVerifier()); 153 buffer.append(tab("[/DISTINCT_PLAN ]")); 154 return buffer.toString(); 155 } 156 157 public String toString() { 158 return " DISTINCTPLAN [ " + tablePlan + "]"; 159 } 160 161 167 168 public _QueryPlan getQueryPlan() throws DException { 169 _QueryPlan cplan = tablePlan.getQueryPlan(); 170 _QueryPlan[] cplans = cplan == null ? null : new _QueryPlan[] {cplan}; 171 return new QueryPlan("DistinctPlan", cplans, null, null); 172 } 173 174 179 180 public _TablePlan[] getChildTablePlans() throws DException { 181 childPlans = tablePlan.getChildTablePlans(); 182 initializeTableDetails(); 183 return new _TablePlan[] {this}; 184 } 185 190 191 public double getCostWithoutOrder(_ServerSession session, booleanvalueexpression condition, long estimatedRowCount) throws DException { 192 return getCost(session, condition, estimatedRowCount); 193 } 194 195 public double getCostWithoutOrder(_ServerSession session) throws DException { 196 return getCost(session); 197 } 198 199 public _Iterator executeWithOutOrder(_ServerSession session, booleanvalueexpression condition) throws DException { 200 return execute(session, condition); 201 } 202 203 public _Iterator executeWithoutOrder(_ServerSession session) throws DException { 204 return execute(session); 205 } 206 207 } 208 | Popular Tags |