1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.compile.CostEstimate; 25 import org.apache.derby.iapi.sql.compile.JoinStrategy; 26 import org.apache.derby.iapi.sql.compile.OptimizableList; 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.OptimizerFactory; 30 import org.apache.derby.iapi.sql.compile.RequiredRowOrdering; 31 32 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 33 34 import org.apache.derby.iapi.store.access.TransactionController; 35 36 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 37 38 import org.apache.derby.iapi.services.monitor.ModuleControl; 39 import org.apache.derby.iapi.services.context.ContextManager; 40 import org.apache.derby.iapi.services.property.PropertyUtil; 41 42 import org.apache.derby.iapi.services.sanity.SanityManager; 43 44 import org.apache.derby.iapi.error.StandardException; 45 46 import org.apache.derby.iapi.reference.Property; 47 48 import java.util.Properties ; 49 50 53 54 public class OptimizerFactoryImpl 55 implements ModuleControl, OptimizerFactory { 56 57 protected String optimizerId = null; 58 protected boolean ruleBasedOptimization = false; 59 protected boolean noTimeout = false; 60 protected boolean useStatistics = true; 61 protected int maxMemoryPerTable = 1048576; 62 63 68 protected JoinStrategy[] joinStrategySet; 69 70 74 public void boot(boolean create, Properties startParams) 75 throws StandardException { 76 77 83 ruleBasedOptimization = 84 Boolean.valueOf( 85 PropertyUtil.getSystemProperty(Optimizer.RULE_BASED_OPTIMIZATION) 86 ).booleanValue(); 87 88 93 noTimeout = 94 Boolean.valueOf( 95 PropertyUtil.getSystemProperty(Optimizer.NO_TIMEOUT) 96 ).booleanValue(); 97 98 104 String maxMemValue = PropertyUtil.getSystemProperty(Optimizer.MAX_MEMORY_PER_TABLE); 105 if (maxMemValue != null) 106 { 107 int intValue = Integer.parseInt(maxMemValue); 108 if (intValue >= 0) 109 maxMemoryPerTable = intValue * 1024; 110 } 111 112 String us = PropertyUtil.getSystemProperty(Optimizer.USE_STATISTICS); 113 if (us != null) 114 useStatistics = (Boolean.valueOf(us)).booleanValue(); 115 116 121 } 122 123 public void stop() { 124 } 125 126 130 135 public Optimizer getOptimizer(OptimizableList optimizableList, 136 OptimizablePredicateList predList, 137 DataDictionary dDictionary, 138 RequiredRowOrdering requiredRowOrdering, 139 int numTablesInQuery, 140 LanguageConnectionContext lcc) 141 throws StandardException 142 { 143 152 if (joinStrategySet == null) 153 { 154 JoinStrategy[] jss = new JoinStrategy[2]; 155 jss[0] = new NestedLoopJoinStrategy(); 156 jss[1] = new HashJoinStrategy(); 157 joinStrategySet = jss; 158 } 159 160 return getOptimizerImpl(optimizableList, 161 predList, 162 dDictionary, 163 requiredRowOrdering, 164 numTablesInQuery, 165 lcc); 166 } 167 168 173 public CostEstimate getCostEstimate() 174 throws StandardException 175 { 176 return new CostEstimateImpl(); 177 } 178 179 182 public boolean supportsOptimizerTrace() 183 { 184 return false; 185 } 186 187 public OptimizerFactoryImpl() { 191 } 192 193 protected Optimizer getOptimizerImpl(OptimizableList optimizableList, 194 OptimizablePredicateList predList, 195 DataDictionary dDictionary, 196 RequiredRowOrdering requiredRowOrdering, 197 int numTablesInQuery, 198 LanguageConnectionContext lcc) 199 throws StandardException 200 { 201 202 return new OptimizerImpl( 203 optimizableList, 204 predList, 205 dDictionary, 206 ruleBasedOptimization, 207 noTimeout, 208 useStatistics, 209 maxMemoryPerTable, 210 joinStrategySet, 211 lcc.getLockEscalationThreshold(), 212 requiredRowOrdering, 213 numTablesInQuery); 214 } 215 216 219 public int getMaxMemoryPerTable() 220 { 221 return maxMemoryPerTable; 222 } 223 } 224 225 | Popular Tags |