Class Optimizer
java.lang.Object
org.h2.command.query.Optimizer
The optimizer is responsible to find the best execution plan
for a given query.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AllColumnsForPlanprivate Planprivate final Expressionprivate doubleprivate final TableFilter[]private static final intprivate static final intprivate static final intprivate Randomprivate final SessionLocalprivate longprivate BitSetprivate TableFilter -
Constructor Summary
ConstructorsConstructorDescriptionOptimizer(TableFilter[] filters, Expression condition, SessionLocal session) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidprivate voidprivate voidprivate voidprivate booleancanStop(int x) (package private) doublegetCost()private static intgetMaxBruteForceFilters(int filterCount) How many filter to calculate using brute force.(package private) voidoptimize(boolean parse) Calculate the best query plan to use.private voidshuffleAll(TableFilter[] f) private booleanshuffleTwo(TableFilter[] f) private booleantestPlan(TableFilter[] list)
-
Field Details
-
MAX_BRUTE_FORCE_FILTERS
private static final int MAX_BRUTE_FORCE_FILTERS- See Also:
-
MAX_BRUTE_FORCE
private static final int MAX_BRUTE_FORCE- See Also:
-
MAX_GENETIC
private static final int MAX_GENETIC- See Also:
-
startNs
private long startNs -
switched
-
filters
-
condition
-
session
-
bestPlan
-
topFilter
-
cost
private double cost -
random
-
allColumnsSet
-
-
Constructor Details
-
Optimizer
Optimizer(TableFilter[] filters, Expression condition, SessionLocal session)
-
-
Method Details
-
getMaxBruteForceFilters
private static int getMaxBruteForceFilters(int filterCount) How many filter to calculate using brute force. The remaining filters are selected using a greedy algorithm which has a runtime of (1 + 2 + ... + n) = (n * (n-1) / 2) for n filters. The brute force algorithm has a runtime of n * (n-1) * ... * (n-m) when calculating m brute force of n total. The combined runtime is (brute force) * (greedy).- Parameters:
filterCount- the number of filters total- Returns:
- the number of filters to calculate using brute force
-
calculateBestPlan
private void calculateBestPlan() -
calculateFakePlan
private void calculateFakePlan() -
canStop
private boolean canStop(int x) -
calculateBruteForceAll
private void calculateBruteForceAll() -
calculateBruteForceSome
private void calculateBruteForceSome() -
calculateGenetic
private void calculateGenetic() -
testPlan
-
shuffleAll
-
shuffleTwo
-
optimize
void optimize(boolean parse) Calculate the best query plan to use.- Parameters:
parse- If we do not need to really get the best plan because it is a view parsing stage.
-
getTopFilter
-
getCost
double getCost()
-