}
public double estimate(MinorThan mt) {
final List<Column> columns = ParserUtil.getJSQLColumns(mt);
final Column column = columns.get(0);
final TypeConversion tc = _schema.getType(ParserUtil.getFullSchemaColumnName(column, _tan));
// TODO: assume uniform distribution
final String fullSchemaColumnName = _tan.getFullSchemaColumnName(column);
Object minValue = _schema.getRange(fullSchemaColumnName).getMin();
Object maxValue = _schema.getRange(fullSchemaColumnName).getMax();
// We have to compare the same types
if (tc instanceof DoubleConversion) {
if (minValue instanceof Long)
minValue = longToDouble((Long) minValue);
if (maxValue instanceof Long)
maxValue = longToDouble((Long) maxValue);
} else if (tc instanceof LongConversion) {
if (minValue instanceof Double)
minValue = doubleToLong((Double) minValue);
if (maxValue instanceof Double)
maxValue = doubleToLong((Double) maxValue);
}
final double fullRange = tc.getDistance(maxValue, minValue);
final Expression leftExp = mt.getLeftExpression();
final Expression rightExp = mt.getRightExpression();
Object conditionConstant = findConditionConstant(rightExp);
if (conditionConstant == null)
// maybe the constant is on the left side
conditionConstant = findConditionConstant(leftExp);
if (conditionConstant != null) {
// a constant on one side
// MAKE TPCH-6 WORK WITH NCL OPTIMIZER
if (tc instanceof DoubleConversion) {
if (conditionConstant instanceof Long)
conditionConstant = longToDouble((Long) conditionConstant);
} else if (tc instanceof LongConversion)
if (conditionConstant instanceof Double)
conditionConstant = doubleToLong((Double) conditionConstant);
final double distance = tc.getDistance(conditionConstant, minValue);
return distance / fullRange;
} else
// no constants on both sides; columns within a single table are
// compared
return HardCodedSelectivities.estimate(_queryName, mt);