public class TableStats
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) static int |
IOCOSTPERPAGE |
(package private) static int |
NUM_HIST_BINS
Number of bins for the histogram.
|
private static java.util.concurrent.ConcurrentHashMap<java.lang.String,TableStats> |
statsMap |
Constructor and Description |
---|
TableStats(int tableid,
int ioCostPerPage)
Create a new TableStats object, that keeps track of statistics on each
column of a table
|
Modifier and Type | Method and Description |
---|---|
double |
avgSelectivity(int field,
Predicate.Op op)
The average selectivity of the field under op.
|
static void |
computeStatistics() |
double |
estimateScanCost()
Estimates the cost of sequentially scanning the file, given that the cost
to read a page is costPerPageIO.
|
double |
estimateSelectivity(int field,
Predicate.Op op,
Field constant)
Estimate the selectivity of predicate field op constant on the
table.
|
int |
estimateTableCardinality(double selectivityFactor)
This method returns the number of tuples in the relation, given that a
predicate with selectivity selectivityFactor is applied.
|
static java.util.Map<java.lang.String,TableStats> |
getStatsMap() |
static TableStats |
getTableStats(java.lang.String tablename) |
static void |
setStatsMap(java.util.HashMap<java.lang.String,TableStats> s) |
static void |
setTableStats(java.lang.String tablename,
TableStats stats) |
int |
totalTuples()
return the total number of tuples in this table
|
private static final java.util.concurrent.ConcurrentHashMap<java.lang.String,TableStats> statsMap
static final int IOCOSTPERPAGE
static final int NUM_HIST_BINS
public TableStats(int tableid, int ioCostPerPage)
tableid
- The table over which to compute statisticsioCostPerPage
- The cost per page of IO. This doesn't differentiate between
sequential-scan IO and disk seeks.public static TableStats getTableStats(java.lang.String tablename)
public static void setTableStats(java.lang.String tablename, TableStats stats)
public static void setStatsMap(java.util.HashMap<java.lang.String,TableStats> s)
public static java.util.Map<java.lang.String,TableStats> getStatsMap()
public static void computeStatistics()
public double estimateScanCost()
public int estimateTableCardinality(double selectivityFactor)
selectivityFactor
- The selectivity of any predicates over the tablepublic double avgSelectivity(int field, Predicate.Op op)
field
- the index of the fieldop
- the operator in the predicate
The semantic of the method is that, given the table, and then given a
tuple, of which we do not know the value of the field, return the
expected selectivity. You may estimate this value from the histograms.public double estimateSelectivity(int field, Predicate.Op op, Field constant)
field
- The field over which the predicate rangesop
- The logical operation in the predicateconstant
- The value against which the field is comparedpublic int totalTuples()