Package org.h2.command.query
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 AllColumnsForPlan
private Plan
private final Expression
private double
private final TableFilter[]
private static final int
private static final int
private static final int
private Random
private final SessionLocal
private long
private BitSet
private TableFilter
-
Constructor Summary
ConstructorsConstructorDescriptionOptimizer
(TableFilter[] filters, Expression condition, SessionLocal session) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
private void
private void
private void
private boolean
canStop
(int x) (package private) double
getCost()
private static int
getMaxBruteForceFilters
(int filterCount) How many filter to calculate using brute force.(package private) void
optimize
(boolean parse) Calculate the best query plan to use.private void
shuffleAll
(TableFilter[] f) private boolean
shuffleTwo
(TableFilter[] f) private boolean
testPlan
(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()
-