1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.table; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 4 import com.daffodilwoods.daffodildb.server.sql99.common.*; 5 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.condition.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*; 8 import com.daffodilwoods.daffodildb.server.sql99.expression. 9 booleanvalueexpression.*; 10 import com.daffodilwoods.database.resource.*; 11 import com.daffodilwoods.database.sqlinitiator.*; 12 13 28 29 public class IndexPredicate 30 implements _IndexPredicateInterface, SimpleConstants { 31 32 35 36 private AllColumnPredicates indexedAllColumnPredicate; 37 38 41 42 private AllColumnPredicates nonIndexedAllColumnPredicate; 43 44 47 48 private double cost; 49 50 54 55 private double ETROW; 56 57 61 62 private _Order order; 63 64 67 68 private TableDetails tableDetails; 69 70 73 74 private int indexPosition; 75 76 80 81 private boolean isNoRecordIterator; 83 public IndexPredicate(AllColumnPredicates indexedAllColumnPredicate0, 84 AllColumnPredicates nonIndexedAllColumnPredicate0) { 85 indexedAllColumnPredicate = indexedAllColumnPredicate0; 86 nonIndexedAllColumnPredicate = nonIndexedAllColumnPredicate0; 87 indexPosition = -1; 88 } 89 90 97 98 public double getCost(Object session) throws DException { 99 long rowCount = getRowCount(); 100 103 if (rowCount == -1) { 104 int rowc = ( (_IndexTable) session).getEstimatedRowCount(); 105 rowCount = rowc; 106 } 107 108 Object [] object = (Object []) CostCalculator.getCostForIndexedPredicate( 109 indexedAllColumnPredicate, rowCount); 110 if (object != null) { 111 cost = ( (Double ) object[0]).doubleValue(); 112 ETROW = ( (Double ) object[1]).doubleValue(); 113 } 114 else { 115 ETROW = rowCount; 116 } 117 object = (Object []) CostCalculator.getCostForNonIndexedPredicate( 118 nonIndexedAllColumnPredicate, ETROW); 119 if (object != null) { 120 cost = cost + ( (Double ) object[0]).doubleValue(); 121 ETROW = ( (Double ) object[1]).doubleValue(); 122 } 123 return cost; 124 } 125 126 130 131 public double getCost() { 132 return cost; 133 } 134 135 140 141 public void setCost(double cost0) throws DException { 142 cost = cost0; 143 } 144 145 150 151 private long getRowCount() throws DException { 152 long rowCount = tableDetails.getRowCount(); 153 156 157 return rowCount; 158 } 159 160 173 174 public _Iterator execute(Object indexTable) throws DException { 175 if (isNoRecordIterator) { 176 return getNoRecordIterator(); 177 } 178 _Iterator iterator = null; 179 if (indexedAllColumnPredicate != null) { iterator = getIndexedIterator(indexTable); 181 } 182 else { 183 iterator = getTableIterator(indexTable); 184 } 185 if (nonIndexedAllColumnPredicate != null) { 186 iterator = getNonIndexedFilterIterator(iterator, indexTable); 187 } 188 if (order != null) { 189 order.setSolvableByIndex(false); 190 } 191 return iterator; 192 } 193 194 201 202 private _Iterator getNonIndexedFilterIterator(_Iterator iterator, 203 Object indexTable) throws 204 DException { 205 booleanvalueexpression nonIndexedCondition = nonIndexedAllColumnPredicate. 206 getNonIndexedCondition(); 207 return GeneralPurposeStaticClass. 208 getNonIndexedFilterIteratorForConditionExecute(indexTable, 209 nonIndexedCondition, new TableDetails[] {tableDetails} 210 , iterator); 211 } 212 213 219 220 private _Iterator getIndexedIterator(Object indexTable) throws DException { 221 return indexedAllColumnPredicate.execute(indexTable); } 223 224 231 232 private _Iterator getTableIterator(Object indexTable) throws DException { 233 return indexPosition != -1 ? 234 ( (_IndexTable) indexTable).getIterator(indexPosition) : 235 ( (_IndexTable) indexTable).getDefaultIterator(); 236 } 237 238 244 245 private _Iterator getNoRecordIterator() throws DException { 246 return new NoRecordIterator(); 247 } 248 249 255 256 public double getEstimatedRow() throws DException { 257 return ETROW; 258 } 259 260 265 266 public void setOrder(_Order order1) throws DException { 267 order = order1; 268 } 269 270 275 276 public _Order getOrder() throws DException { 277 return order; 278 } 279 280 public String toString() { 281 String str = ""; 282 str += "INDEX PREDICATE -> TABLENAME = " + tableDetails; 283 str += "[INDEXED" + indexedAllColumnPredicate + "]"; 284 str += "[NONINDEXED" + nonIndexedAllColumnPredicate + "]"; 285 return str; 286 } 287 288 293 294 public void setTableDetails(TableDetails tableDetails0) throws DException { 295 tableDetails = tableDetails0; 296 if (indexedAllColumnPredicate != null) { 297 indexedAllColumnPredicate.setTableDetails(tableDetails0); 298 } 299 if (nonIndexedAllColumnPredicate != null) { 300 nonIndexedAllColumnPredicate.setTableDetails(tableDetails0); 301 } 302 } 303 304 309 public void setIndex(int indexPosition0) { 310 indexPosition = indexPosition0; 311 } 312 313 317 318 public void setNoRecordIteratorStatus(boolean noRecordIterator) { 319 isNoRecordIterator = noRecordIterator; 320 } 321 322 } 323 | Popular Tags |