Package org.h2.command.query
Class Optimizer
- java.lang.Object
-
- org.h2.command.query.Optimizer
-
class Optimizer extends java.lang.Object
The optimizer is responsible to find the best execution plan for a given query.
-
-
Field Summary
Fields Modifier and Type Field Description private AllColumnsForPlan
allColumnsSet
private Plan
bestPlan
private Expression
condition
private double
cost
private TableFilter[]
filters
private static int
MAX_BRUTE_FORCE
private static int
MAX_BRUTE_FORCE_FILTERS
private static int
MAX_GENETIC
private java.util.Random
random
private SessionLocal
session
private long
startNs
private java.util.BitSet
switched
private TableFilter
topFilter
-
Constructor Summary
Constructors Constructor Description Optimizer(TableFilter[] filters, Expression condition, SessionLocal session)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
calculateBestPlan()
private void
calculateBruteForceAll()
private void
calculateBruteForceSome()
private void
calculateFakePlan()
private void
calculateGenetic()
private boolean
canStop(int x)
(package private) double
getCost()
private static int
getMaxBruteForceFilters(int filterCount)
How many filter to calculate using brute force.TableFilter
getTopFilter()
(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 Detail
-
MAX_BRUTE_FORCE_FILTERS
private static final int MAX_BRUTE_FORCE_FILTERS
- See Also:
- Constant Field Values
-
MAX_BRUTE_FORCE
private static final int MAX_BRUTE_FORCE
- See Also:
- Constant Field Values
-
MAX_GENETIC
private static final int MAX_GENETIC
- See Also:
- Constant Field Values
-
startNs
private long startNs
-
switched
private java.util.BitSet switched
-
filters
private final TableFilter[] filters
-
condition
private final Expression condition
-
session
private final SessionLocal session
-
bestPlan
private Plan bestPlan
-
topFilter
private TableFilter topFilter
-
cost
private double cost
-
random
private java.util.Random random
-
allColumnsSet
private final AllColumnsForPlan allColumnsSet
-
-
Constructor Detail
-
Optimizer
Optimizer(TableFilter[] filters, Expression condition, SessionLocal session)
-
-
Method Detail
-
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
private boolean testPlan(TableFilter[] list)
-
shuffleAll
private void shuffleAll(TableFilter[] f)
-
shuffleTwo
private boolean shuffleTwo(TableFilter[] f)
-
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
public TableFilter getTopFilter()
-
getCost
double getCost()
-
-