Top Description Fields Constructors Methods
org.h2.command.query

pack-priv Class Optimizer

extends Object
Class Inheritance
Imports
java.util.BitSet, .Random, org.h2.engine.SessionLocal, org.h2.expression.Expression, org.h2.table.Plan, .PlanItem, .TableFilter, org.h2.util.Permutations

The optimizer is responsible to find the best execution plan for a given query.

Field Summary

Modifier and TypeField and Description
private 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

AccessConstructor and Description
pack-priv
Optimizer(TableFilter[] filters, Expression condition, SessionLocal session)

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private void
private void
private boolean
canStop(int x)

pack-priv double
private static int

Returns:

the number of filters to calculate using brute force
getMaxBruteForceFilters
(int
the number of filters total
filterCount
)

How many filter to calculate using brute force.

public TableFilter
pack-priv void
optimize(boolean
If we do not need to really get the best plan because it is a view parsing stage.
parse
)

Calculate the best query plan to use.

private void
private boolean
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allColumnsSetback to summary
private final AllColumnsForPlan allColumnsSet
bestPlanback to summary
private Plan bestPlan
conditionback to summary
private final Expression condition
costback to summary
private double cost
filtersback to summary
private final TableFilter[] filters
MAX_BRUTE_FORCEback to summary
private static final int MAX_BRUTE_FORCE
MAX_BRUTE_FORCE_FILTERSback to summary
private static final int MAX_BRUTE_FORCE_FILTERS
MAX_GENETICback to summary
private static final int MAX_GENETIC
randomback to summary
private Random random
sessionback to summary
private final SessionLocal session
startNsback to summary
private long startNs
switchedback to summary
private BitSet switched
topFilterback to summary
private TableFilter topFilter

Constructor Detail

Optimizerback to summary
pack-priv Optimizer(TableFilter[] filters, Expression condition, SessionLocal session)

Method Detail

calculateBestPlanback to summary
private void calculateBestPlan()
calculateBruteForceAllback to summary
private void calculateBruteForceAll()
calculateBruteForceSomeback to summary
private void calculateBruteForceSome()
calculateFakePlanback to summary
private void calculateFakePlan()
calculateGeneticback to summary
private void calculateGenetic()
canStopback to summary
private boolean canStop(int x)
getCostback to summary
pack-priv double getCost()
getMaxBruteForceFiltersback to summary
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:int

the number of filters total

Returns:int

the number of filters to calculate using brute force

getTopFilterback to summary
public TableFilter getTopFilter()
optimizeback to summary
pack-priv void optimize(boolean parse)

Calculate the best query plan to use.

Parameters
parse:boolean

If we do not need to really get the best plan because it is a view parsing stage.

shuffleAllback to summary
private void shuffleAll(TableFilter[] f)
shuffleTwoback to summary
private boolean shuffleTwo(TableFilter[] f)
testPlanback to summary
private boolean testPlan(TableFilter[] list)