1
0
Fork 0

rules have names

This commit is contained in:
Jan Steemann 2014-08-27 23:53:53 +02:00
parent 2628afb426
commit b10ae65d58
2 changed files with 13 additions and 14 deletions

View File

@ -42,26 +42,26 @@ Optimizer::Optimizer () {
// List all the rules in the system here: // List all the rules in the system here:
// try to find sort blocks which are superseeded by indexes // try to find sort blocks which are superseeded by indexes
registerRule (useIndexForSort, 2000); registerRule("use-index-for-sort", useIndexForSort, 2000);
// try to find a filter after an enumerate collection and find an index . . . // try to find a filter after an enumerate collection and find an index . . .
registerRule(useIndexRange, 999); registerRule("use-index-range", useIndexRange, 999);
// remove filters from the query that are not necessary at all // remove filters from the query that are not necessary at all
// filters that are always true will be removed entirely // filters that are always true will be removed entirely
// filters that are always false will be replaced with a NoResults node // filters that are always false will be replaced with a NoResults node
registerRule(removeUnnecessaryFiltersRule, 100); registerRule("remove-unnecessary-filters", removeUnnecessaryFiltersRule, 100);
// move calculations up the dependency chain (to pull them out of inner loops etc.) // move calculations up the dependency chain (to pull them out of inner loops etc.)
registerRule(moveCalculationsUpRule, 1000); registerRule("move-calculations-up", moveCalculationsUpRule, 1000);
// move filters up the dependency chain (to make result sets as small as possible // move filters up the dependency chain (to make result sets as small as possible
// as early as possible) // as early as possible)
registerRule(moveFiltersUpRule, 1010); registerRule("move-filters-up", moveFiltersUpRule, 1010);
// remove calculations that are never necessary // remove calculations that are never necessary
registerRule(removeUnnecessaryCalculationsRule, 1020); registerRule("remove-unnecessary-calculations", removeUnnecessaryCalculationsRule, 1020);
// Now sort them by level: // Now sort them by level:
std::stable_sort(_rules.begin(), _rules.end()); std::stable_sort(_rules.begin(), _rules.end());
@ -112,15 +112,13 @@ int Optimizer::createPlans (ExecutionPlan* plan) {
newPlans.push_back(p, level); // nothing to do, just keep it newPlans.push_back(p, level); // nothing to do, just keep it
} }
else { // some rule needs applying else { // some rule needs applying
Rule r(dummyRule, level); Rule r("dummy", dummyRule, level);
auto it = std::upper_bound(_rules.begin(), _rules.end(), r); auto it = std::upper_bound(_rules.begin(), _rules.end(), r);
TRI_ASSERT(it != _rules.end()); TRI_ASSERT(it != _rules.end());
std::cout << "Trying rule " << &(it->func) << " with level " std::cout << "Trying rule " << it->name << " (" << &(it->func) << ") with level "
<< it->level << " on plan " << count++ << it->level << " on plan " << count++
<< std::endl; << std::endl;
try { try {
// keep should have a default value so rules that forget to set it
// have a deterministic behavior
res = it->func(this, p, it->level, newPlans); res = it->func(this, p, it->level, newPlans);
} }
catch (...) { catch (...) {

View File

@ -187,11 +187,12 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
struct Rule { struct Rule {
std::string name;
RuleFunction func; RuleFunction func;
int level; int level;
Rule (RuleFunction f, int l) Rule (std::string const& name, RuleFunction f, int l)
: func(f), level(l) { : name(name), func(f), level(l) {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -298,8 +299,8 @@ namespace triagens {
/// @brief registerRule /// @brief registerRule
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void registerRule (RuleFunction f, int level) { void registerRule (std::string const& name, RuleFunction f, int level) {
_rules.emplace_back(f, level); _rules.emplace_back(name, f, level);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////