|
@@ -8,8 +8,6 @@ using namespace NYql::NNodes;
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
|
|
|
|
- THashSet<TString> exprCallables = {"SafeCast"};
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Check if a callable is an attribute of some table
|
|
* Check if a callable is an attribute of some table
|
|
* Currently just return a boolean and cover only basic cases
|
|
* Currently just return a boolean and cover only basic cases
|
|
@@ -22,34 +20,8 @@ namespace {
|
|
return IsAttribute(cast.Cast().Value(), attributeName);
|
|
return IsAttribute(cast.Cast().Value(), attributeName);
|
|
} else if (auto ifPresent = input.Maybe<TCoIfPresent>()) {
|
|
} else if (auto ifPresent = input.Maybe<TCoIfPresent>()) {
|
|
return IsAttribute(ifPresent.Cast().Optional(), attributeName);
|
|
return IsAttribute(ifPresent.Cast().Optional(), attributeName);
|
|
- }
|
|
|
|
-
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Check that the expression is a constant expression
|
|
|
|
- * We use a whitelist of callables
|
|
|
|
- */
|
|
|
|
- bool IsConstant(const TExprBase& input) {
|
|
|
|
- if (input.Maybe<TCoDataCtor>()){
|
|
|
|
- return true;
|
|
|
|
- } else if (input.Ref().IsCallable(exprCallables)) {
|
|
|
|
- if (input.Ref().ChildrenSize() >= 1) {
|
|
|
|
- for (size_t i = 0; i < input.Ref().ChildrenSize(); i++) {
|
|
|
|
- auto callableInput = TExprBase(input.Ref().Child(i));
|
|
|
|
- if (!IsConstant(callableInput)) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- } else {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- } else if (auto op = input.Maybe<TCoBinaryArithmetic>()) {
|
|
|
|
- auto left = op.Cast().Left();
|
|
|
|
- auto right = op.Cast().Right();
|
|
|
|
- return IsConstant(left) && IsConstant(right);
|
|
|
|
|
|
+ } else if (auto just = input.Maybe<TCoJust>()) {
|
|
|
|
+ return IsAttribute(just.Cast().Input(), attributeName);
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
return false;
|
|
@@ -100,7 +72,7 @@ double NYql::NDq::ComputePredicateSelectivity(const TExprBase& input, const std:
|
|
|
|
|
|
TString attributeName;
|
|
TString attributeName;
|
|
|
|
|
|
- if (IsAttribute(right, attributeName) && IsConstant(left)) {
|
|
|
|
|
|
+ if (IsAttribute(right, attributeName) && IsConstantExpr(left.Ptr())) {
|
|
std::swap(left, right);
|
|
std::swap(left, right);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -114,7 +86,7 @@ double NYql::NDq::ComputePredicateSelectivity(const TExprBase& input, const std:
|
|
// In case the right side is a constant that can be extracted, compute the selectivity using statistics
|
|
// In case the right side is a constant that can be extracted, compute the selectivity using statistics
|
|
// Currently, with the basic statistics we just return 1/nRows
|
|
// Currently, with the basic statistics we just return 1/nRows
|
|
|
|
|
|
- else if (IsConstant(right)) {
|
|
|
|
|
|
+ else if (IsConstantExpr(right.Ptr())) {
|
|
if (stats->KeyColumns.size()==1 && attributeName==stats->KeyColumns[0]) {
|
|
if (stats->KeyColumns.size()==1 && attributeName==stats->KeyColumns[0]) {
|
|
if (stats->Nrows > 1) {
|
|
if (stats->Nrows > 1) {
|
|
result = 1.0 / stats->Nrows;
|
|
result = 1.0 / stats->Nrows;
|
|
@@ -141,7 +113,7 @@ double NYql::NDq::ComputePredicateSelectivity(const TExprBase& input, const std:
|
|
auto right = comparison.Cast().Right();
|
|
auto right = comparison.Cast().Right();
|
|
|
|
|
|
TString attributeName;
|
|
TString attributeName;
|
|
- if (IsAttribute(right, attributeName) && IsConstant(left)) {
|
|
|
|
|
|
+ if (IsAttribute(right, attributeName) && IsConstantExpr(left.Ptr())) {
|
|
std::swap(left, right);
|
|
std::swap(left, right);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -152,7 +124,7 @@ double NYql::NDq::ComputePredicateSelectivity(const TExprBase& input, const std:
|
|
}
|
|
}
|
|
// In case the right side is a constant that can be extracted, compute the selectivity using statistics
|
|
// In case the right side is a constant that can be extracted, compute the selectivity using statistics
|
|
// Currently, with the basic statistics we just return 0.5
|
|
// Currently, with the basic statistics we just return 0.5
|
|
- else if (IsConstant(right)) {
|
|
|
|
|
|
+ else if (IsConstantExpr(right.Ptr())) {
|
|
result = 0.5;
|
|
result = 0.5;
|
|
}
|
|
}
|
|
}
|
|
}
|