1 21 22 package org.apache.derby.impl.store.access.heap; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 import org.apache.derby.iapi.reference.Property; 26 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 29 import org.apache.derby.iapi.error.StandardException; 30 31 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; 32 33 import org.apache.derby.iapi.types.RowLocation; 34 import org.apache.derby.iapi.store.access.StoreCostController; 35 import org.apache.derby.iapi.store.access.StoreCostResult; 36 37 import org.apache.derby.iapi.store.raw.ContainerHandle; 38 import org.apache.derby.iapi.store.raw.LockingPolicy; 39 import org.apache.derby.iapi.store.raw.RawStoreFactory; 40 import org.apache.derby.iapi.store.raw.Transaction; 41 42 import org.apache.derby.impl.store.access.conglomerate.GenericCostController; 43 import org.apache.derby.impl.store.access.conglomerate.OpenConglomerate; 44 45 import org.apache.derby.iapi.store.access.RowUtil; 46 47 import org.apache.derby.iapi.types.DataValueDescriptor; 48 49 import org.apache.derby.iapi.services.io.FormatableBitSet; 50 import java.util.Properties ; 51 52 53 78 79 public class HeapCostController 80 extends GenericCostController implements StoreCostController 81 { 82 85 long num_pages; 86 long num_rows; 87 long page_size; 88 long row_size; 89 90 91 92 100 public void init( 101 OpenConglomerate open_conglom) 102 throws StandardException 103 { 104 super.init(open_conglom); 105 106 ContainerHandle container = open_conglom.getContainer(); 107 108 num_rows = container.getEstimatedRowCount( 0); 110 111 if (num_rows == 0) 119 num_rows = 1; 120 121 num_pages = container.getEstimatedPageCount( 0); 123 124 Properties prop = new Properties (); 125 prop.put(Property.PAGE_SIZE_PARAMETER, ""); 126 container.getContainerProperties(prop); 127 page_size = 128 Integer.parseInt(prop.getProperty(Property.PAGE_SIZE_PARAMETER)); 129 130 row_size = (num_pages * page_size / num_rows); 131 132 return; 133 } 134 135 136 137 138 139 182 public double getFetchFromRowLocationCost( 183 FormatableBitSet validColumns, 184 int access_type) 185 throws StandardException 186 { 187 double ret_cost; 188 189 ret_cost = row_size * BASE_ROW_PER_BYTECOST; 191 192 long num_pages_per_row = (row_size / page_size) + 1; 193 194 if ((access_type & StoreCostController.STORECOST_CLUSTERED) == 0) 195 { 196 ret_cost += (BASE_UNCACHED_ROW_FETCH_COST * num_pages_per_row); 198 } 199 else 200 { 201 ret_cost += (BASE_CACHED_ROW_FETCH_COST * num_pages_per_row); 202 } 203 204 return(ret_cost); 205 } 206 207 342 public void getScanCost( 343 int scan_type, 344 long row_count, 345 int group_size, 346 boolean forUpdate, 347 FormatableBitSet scanColumnList, 348 DataValueDescriptor[] template, 349 DataValueDescriptor[] startKeyValue, 350 int startSearchOperator, 351 DataValueDescriptor[] stopKeyValue, 352 int stopSearchOperator, 353 boolean reopen_scan, 354 int access_type, 355 StoreCostResult cost_result) 356 throws StandardException 357 { 358 if (SanityManager.DEBUG) 359 { 360 SanityManager.ASSERT( 361 scan_type == StoreCostController.STORECOST_SCAN_NORMAL || 362 scan_type == StoreCostController.STORECOST_SCAN_SET); 363 } 364 365 long estimated_row_count = ((row_count < 0) ? num_rows : row_count); 366 367 371 double cost = (num_pages * BASE_UNCACHED_ROW_FETCH_COST); 373 374 cost += (estimated_row_count * row_size) * BASE_ROW_PER_BYTECOST; 376 377 long cached_row_count = estimated_row_count - num_pages; 382 if (cached_row_count < 0) 383 cached_row_count = 0; 384 385 if (scan_type == StoreCostController.STORECOST_SCAN_NORMAL) 386 cost += cached_row_count * BASE_GROUPSCAN_ROW_COST; 387 else 388 cost += cached_row_count * BASE_HASHSCAN_ROW_FETCH_COST; 389 390 if (SanityManager.DEBUG) 391 { 392 SanityManager.ASSERT(cost >= 0); 393 SanityManager.ASSERT(estimated_row_count >= 0); 394 } 395 396 cost_result.setEstimatedCost(cost); 397 398 cost_result.setEstimatedRowCount(estimated_row_count); 400 401 return; 402 } 403 } 404 | Popular Tags |