|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.farrago.ddl.DdlStmt net.sf.farrago.ddl.DdlAnalyzeStmt
public class DdlAnalyzeStmt
DdlAnalyzeStmt is a Farrago statement for computing the statistics of a relational expression and storing them in repository.
The following data are collected:
Nested Class Summary | |
---|---|
private class |
DdlAnalyzeStmt.ColumnDetail
ColumnDetail stores details about a column being analyzed. |
private class |
DdlAnalyzeStmt.ColumnHistogramBar
Class used to store column histogram bar information |
private class |
DdlAnalyzeStmt.Histogram
Class used to store column histogram information |
private class |
DdlAnalyzeStmt.IndexDetail
IndexDetails stores details about an index being analyzed. |
Constructor Summary | |
---|---|
DdlAnalyzeStmt(CwmTable table)
|
Method Summary | |
---|---|
private List<DdlAnalyzeStmt.ColumnHistogramBar> |
buildBars(ResultSet resultSet,
long rowsPerBar,
FarragoCardinalityEstimator estimator)
Given a result set from a column distribution query, compute the bars in the Histogram. |
private DdlAnalyzeStmt.Histogram |
buildEstimatedHistogram(DdlAnalyzeStmt.ColumnDetail column,
long tableRowCount,
ResultSet resultSet,
boolean isUnique,
boolean isUniqueNullable)
Iterate over the sample given in the result set and generate a histogram for the column. |
private void |
buildFemBars(DdlAnalyzeStmt.Histogram histogram,
List<FemColumnHistogramBar> femBars)
Convert the DdlAnalyzeStmt.ColumnHistogramBar instances in the given DdlAnalyzeStmt.Histogram into FemColumnHistogramBar instances. |
private DdlAnalyzeStmt.Histogram |
buildHistogram(DdlAnalyzeStmt.ColumnDetail column,
long tableRowCount,
ResultSet resultSet)
Iterate over the given result set and generate a histogram for the column. |
private List<FemAbstractColumn> |
checkCatalogTypes()
Verifies that statistics can be estimated for the given table. |
private void |
checkColumnDistributionQuery()
Validate that the RelDataType of the current stmtContext
matches what's expected from a column distribution query. |
private void |
checkRowCountQuery()
Validate that the RelDataType of the current stmtContext
matches a table row count query. |
private void |
chooseSamplePercentage(long rowCount)
Choose an appropriate sampling percentage for a table with the given row count. |
void |
completeAfterExecuteUnlocked(FarragoSessionDdlValidator ddlValidator,
FarragoSession session,
boolean success)
Provides access to the repository after execution of the DDL. |
boolean |
completeRequiresWriteTxn()
Checks whether the DdlMultipleTransactionStmt.completeAfterExecuteUnlocked(
FarragoSessionDdlValidator, FarragoSession, boolean) method requires a
repository write transaction. |
private void |
computeColumnStats(Map<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms,
DdlAnalyzeStmt.ColumnDetail column,
long tableRowCount)
Build a complete histogram and calculate cardinality for the given column by querying it. |
private long |
computeRowCount()
Executes a query against the table to compute the row count. |
private long |
computeRowsLastHistogramBar(long rowCount,
long rowsPerBar)
Compute the number of rows in the last histogram bar based on the DEFAULT_HISTOGRAM_BAR_COUNT . |
private long |
computeRowsPerHistogramBar(long rowCount)
Compute the number of rows per histogram bar based on the DEFAULT_HISTOGRAM_BAR_COUNT . |
private void |
estimateColumnStats(Map<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms,
DdlAnalyzeStmt.ColumnDetail column,
long tableRowCount,
boolean isUnique,
boolean isUniqueNullable)
Build sampled histogram and estimate cardinality for the given column by querying it. |
private void |
estimateEmptyTableStats(List<DdlAnalyzeStmt.ColumnDetail> columnDetails,
LinkedHashMap<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms)
Iterate over the given FemAbstractColumn instances and generate
histograms for an empty table. |
private void |
estimateStats(List<DdlAnalyzeStmt.ColumnDetail> columnDetails,
long rowCount,
LinkedHashMap<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms)
Iterate over the given FemAbstractColumn instances and compute
histograms and cardinality from sampled data. |
private void |
executeAnalyzeIndexes(FarragoSessionDdlValidator ddlValidator,
long rowCount,
long deletedRowCount,
LinkedHashMap<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms)
Analyzes the table's indexes. |
void |
executeUnlocked(FarragoSessionDdlValidator ddlValidator,
FarragoSession session)
Executes long-running DDL actions. |
private String |
getColumnDistributionQuery(SqlIdentifier columnName)
Generate a query to generate a columns distribution. |
private long |
getRowCount()
Retrieve the table's row count. |
private String |
getRowCountQuery()
Generate a query to count a table's rows. |
private boolean |
personalityManagesRowCount(FarragoSessionDdlValidator ddlValidator)
Returns true if the personality maintains an accurate row count and deleted row count in FemAbstractColumnSet . |
private void |
prepareIndexDetails()
Prepares for analyzing table indexes. |
void |
prepForExecuteUnlocked(FarragoSessionDdlValidator ddlValidator,
FarragoSession session)
Provides access to the repository in preparation for the execution of DdlStmt. |
void |
setColumns(List<CwmColumn> columnList)
Sets the list of columns to be analyzed |
void |
setEstimateOption(boolean estimate)
|
void |
setSamplePercent(SqlNumericLiteral percent)
|
private void |
setSampleRepeatableSeed(FarragoSessionDdlValidator ddlValidator)
Looks up the current session variables
and sets sampleRepeatableSeed to the repeatable seed value that
may be stored there for testing purposes. |
private void |
updateStats(FarragoRepos repos,
long rowCount,
boolean updateRowCount,
Collection<DdlAnalyzeStmt.Histogram> histograms,
List<DdlAnalyzeStmt.IndexDetail> indexDetails)
Updates catalog records with new statistical data, all within a single MDR write txn. |
void |
visit(DdlVisitor visitor)
Invokes a visitor on this statement. |
Methods inherited from class net.sf.farrago.ddl.DdlStmt |
---|
getModelElement, isDropRestricted, postCommit, postExecute, preExecute, preValidate, requiresCommit, runsAsDml |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.farrago.session.FarragoSessionDdlStmt |
---|
getModelElement, isDropRestricted, postCommit, postExecute, preExecute, preValidate, requiresCommit, runsAsDml |
Field Detail |
---|
private static final int DEFAULT_HISTOGRAM_BAR_COUNT
private static final int MAX_HISTOGRAM_BAR_COUNT
private static final long MIN_SAMPLE_SIZE
public static final String REPEATABLE_SEED
EigenbaseTimingTracer timingTracer
private CwmTable table
private List<CwmColumn> columnList
private boolean estimate
private boolean computeRowCount
private SqlNumericLiteral samplePercent
private Integer sampleRepeatableSeed
private FemAbstractColumnSet femTable
private Long femTableRowCount
private long femTableDeletedRowCount
private FarragoSessionStmtContext stmtContext
private SqlPrettyWriter writer
private SqlIdentifier tableName
private List<DdlAnalyzeStmt.ColumnDetail> columnDetails
private Map<FemAbstractColumn,DdlAnalyzeStmt.ColumnDetail> columnMap
private List<DdlAnalyzeStmt.IndexDetail> indexDetails
private FarragoRepos repos
private long statsRowCount
private LinkedHashMap<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms
private BitSet singleUniqueCols
private BitSet singleUniqueColsNullable
Constructor Detail |
---|
public DdlAnalyzeStmt(CwmTable table)
Method Detail |
---|
public void setColumns(List<CwmColumn> columnList)
columnList
- list of CwmColumn
repository objectspublic void setEstimateOption(boolean estimate)
public void setSamplePercent(SqlNumericLiteral percent)
public void visit(DdlVisitor visitor)
DdlStmt
visit
in class DdlStmt
visitor
- DdlVisitor to invokepublic void prepForExecuteUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session)
DdlMultipleTransactionStmt
prepForExecuteUnlocked
in interface DdlMultipleTransactionStmt
ddlValidator
- DDL validator for this statementFarragoReposTxnContext
public void executeUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session)
DdlMultipleTransactionStmt
executeUnlocked
in interface DdlMultipleTransactionStmt
ddlValidator
- DDL validator for this statementsession
- reentrant Farrago session which may be used to execute DML
statementspublic boolean completeRequiresWriteTxn()
DdlMultipleTransactionStmt
DdlMultipleTransactionStmt.completeAfterExecuteUnlocked(
FarragoSessionDdlValidator, FarragoSession, boolean)
method requires a
repository write transaction.
completeRequiresWriteTxn
in interface DdlMultipleTransactionStmt
public void completeAfterExecuteUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session, boolean success)
DdlMultipleTransactionStmt
DdlMultipleTransactionStmt.executeUnlocked(FarragoSessionDdlValidator, FarragoSession)
.
This method is invoked in a locked
repository
transaction. The method DdlMultipleTransactionStmt.completeRequiresWriteTxn()
controls
whether the transaction read-only or not. This method may not access
and/or modify repository objects loaded in a previous transaction unless
they are reloaded by MOF ID. Be aware that objects may have been modified
by another session unless some external mechanism (for instance, the
"table-in-use" collection) guarantees that they have not been modified by
another statement.
Note that any repository modifications made during the execution of
this method will not be post-processed by DdlValidator
.
For instance, DdlValidator.checkJmiConstraints(RefObject)
is not
called, and therefore any mandatory default primitives are not
automatically set, which will cause errors later if the attributes have
not been explicitly initialized. See JmiObjUtil.setMandatoryPrimitiveDefaults(javax.jmi.reflect.RefObject)
.
completeAfterExecuteUnlocked
in interface DdlMultipleTransactionStmt
ddlValidator
- DDL validator for this statementsession
- reentrant Farrago session which may be used to execute DML
statementssuccess
- whether the execution succeeded; detection of failure can
be used to recoverprivate List<FemAbstractColumn> checkCatalogTypes()
FemAbstractColumn
instances if the table can be
analyzed
RuntimeException
- if analyze is not support for the tableprivate boolean personalityManagesRowCount(FarragoSessionDdlValidator ddlValidator)
FemAbstractColumnSet
.
private long getRowCount() throws SQLException
computeRowCount
is true, otherwise uses the value stored in femTable
.
SQLException
- if there's an error querying the tableprivate long computeRowCount() throws SQLException
SQLException
- if there's an error querying the tableprivate String getRowCountQuery()
private void checkRowCountQuery()
RelDataType
of the current stmtContext
matches a table row count query.
private void setSampleRepeatableSeed(FarragoSessionDdlValidator ddlValidator)
session variables
and sets sampleRepeatableSeed
to the repeatable seed value that
may be stored there for testing purposes.
private void chooseSamplePercentage(long rowCount)
samplePercent
.
private void estimateStats(List<DdlAnalyzeStmt.ColumnDetail> columnDetails, long rowCount, LinkedHashMap<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms) throws SQLException
FemAbstractColumn
instances and compute
histograms and cardinality from sampled data. Passes information about a
column gleaned from its constraints to the single-column estimation
method.
columnDetails
- collection of columns to analyzerowCount
- row count of the tablehistograms
- a map of columns to histograms with predictable
iteration order
SQLException
- if a sampling query failsprivate void estimateColumnStats(Map<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms, DdlAnalyzeStmt.ColumnDetail column, long tableRowCount, boolean isUnique, boolean isUniqueNullable) throws SQLException
histograms
- map in which to store generated Histogramcolumn
- the column to generate a histogram fortableRowCount
- number of rows in the tableisUnique
- if true, the column has a uniqueness constraint that
applies to it only (e.g. single-column primary key or single-column
unique constraint)isUniqueNullable
- if true, the column allows nulls (ignored if
isUnique is false)
SQLException
- if there's an error executing the sampling queryprivate DdlAnalyzeStmt.Histogram buildEstimatedHistogram(DdlAnalyzeStmt.ColumnDetail column, long tableRowCount, ResultSet resultSet, boolean isUnique, boolean isUniqueNullable) throws SQLException
column
- the column to generate a histogram fortableRowCount
- number of rows in the tableresultSet
- containing column samples aggregated by valueisUnique
- if true, the column has a uniqueness constraint that
applies to it only (e.g. single-column primary key or single-column
unique constraint)isUniqueNullable
- if true, the column allows nulls (ignored if
isUnique is false)
SQLException
- if there's an error reading the sampleprivate void estimateEmptyTableStats(List<DdlAnalyzeStmt.ColumnDetail> columnDetails, LinkedHashMap<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms)
FemAbstractColumn
instances and generate
histograms for an empty table.
columnDetails
- a list of columnshistograms
- a map of columns to histograms with predictable
iteration orderprivate void computeColumnStats(Map<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms, DdlAnalyzeStmt.ColumnDetail column, long tableRowCount) throws SQLException
histograms
- map in which to store generated Histogramcolumn
- the column to generate a histogram fortableRowCount
- number of rows in the table
SQLException
- if there's an error executing the queryprivate DdlAnalyzeStmt.Histogram buildHistogram(DdlAnalyzeStmt.ColumnDetail column, long tableRowCount, ResultSet resultSet) throws SQLException
column
- the column to generate a histogram fortableRowCount
- number of rows in the tableresultSet
- containing column data aggregated by value
SQLException
- if there's an error reading the sampleprivate String getColumnDistributionQuery(SqlIdentifier columnName)
estimate
flag is set, the query uses the TABLESAMPLE keyword to sample
the column's data.
private void checkColumnDistributionQuery()
RelDataType
of the current stmtContext
matches what's expected from a column distribution query.
private long computeRowsPerHistogramBar(long rowCount)
DEFAULT_HISTOGRAM_BAR_COUNT
.
rowCount
- number of rows from the table that will be represented by
the histogramprivate long computeRowsLastHistogramBar(long rowCount, long rowsPerBar)
DEFAULT_HISTOGRAM_BAR_COUNT
.
rowCount
- number of rows from the table that will be represented by
the histogramrowsPerBar
- the result of computeRowsPerHistogramBar(long)
private List<DdlAnalyzeStmt.ColumnHistogramBar> buildBars(ResultSet resultSet, long rowsPerBar, FarragoCardinalityEstimator estimator) throws SQLException
resultSet
- column distribution query result setrowsPerBar
- the number of rows per barestimator
- an estimator to populate with data from the result set;
may be null
DdlAnalyzeStmt.ColumnHistogramBar
instances
SQLException
- if there's an error reading the result setprivate void buildFemBars(DdlAnalyzeStmt.Histogram histogram, List<FemColumnHistogramBar> femBars)
DdlAnalyzeStmt.ColumnHistogramBar
instances in the given DdlAnalyzeStmt.Histogram
into FemColumnHistogramBar
instances.
private void prepareIndexDetails()
private void executeAnalyzeIndexes(FarragoSessionDdlValidator ddlValidator, long rowCount, long deletedRowCount, LinkedHashMap<DdlAnalyzeStmt.ColumnDetail,DdlAnalyzeStmt.Histogram> histograms)
ddlValidator
- used to execute index statistics gatheringrowCount
- table's row countdeletedRowCount
- number of deleted rows in the table store (usually
zero outside LucidDb)histograms
- previously gathered column histogramsprivate void updateStats(FarragoRepos repos, long rowCount, boolean updateRowCount, Collection<DdlAnalyzeStmt.Histogram> histograms, List<DdlAnalyzeStmt.IndexDetail> indexDetails)
repos
- repositoryrowCount
- table rowcountupdateRowCount
- if true, update the catalog row counthistograms
- column histogramsindexDetails
- index details, including index statistics
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |