Skip to content

Commit df0d47c

Browse files
[Wasm] Adapt the cost function of Filter.
`Filter` must be more expensive than `LazyDisjunctiveFilter` on disjunctive predicates.
1 parent 7d84718 commit df0d47c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/backend/WasmOperator.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ ConditionSet Filter<Predicated>::adapt_post_condition(const Match<Filter>&, cons
458458
return post_cond;
459459
}
460460

461+
template<bool Predicated>
462+
double Filter<Predicated>::cost(const Match<Filter> &M)
463+
{
464+
const cnf::CNF &cond = M.filter.filter();
465+
const unsigned cost = std::accumulate(cond.cbegin(), cond.cend(), 0U, [](unsigned cost, const cnf::Clause &clause) {
466+
return cost + clause.size();
467+
});
468+
return cost * (Predicated ? 2.0 : 1.0);
469+
}
470+
461471
template<bool Predicated>
462472
void Filter<Predicated>::execute(const Match<Filter> &M, setup_t setup, pipeline_t pipeline, teardown_t teardown)
463473
{
@@ -490,7 +500,7 @@ double LazyDisjunctiveFilter::cost(const Match<LazyDisjunctiveFilter> &M)
490500
{
491501
const cnf::CNF &cond = M.filter.filter();
492502
M_insist(cond.size() == 1, "disjunctive filter condition must be a single clause");
493-
return cond[0].size(); // number of predicates in the clause
503+
return cond[0].size() / 2.0; // on avg. half the number of predicates in the clause XXX consider selectivities
494504
}
495505

496506
void LazyDisjunctiveFilter::execute(const Match<LazyDisjunctiveFilter> &M, setup_t setup, pipeline_t pipeline,

src/backend/WasmOperator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ template<bool Predicated>
106106
struct Filter : PhysicalOperator<Filter<Predicated>, FilterOperator>
107107
{
108108
static void execute(const Match<Filter> &M, setup_t setup, pipeline_t pipeline, teardown_t teardown);
109-
static double cost(const Match<Filter>&) { return M_CONSTEXPR_COND(Predicated, 2.0, 1.0); }
109+
static double cost(const Match<Filter>&);
110110
static ConditionSet adapt_post_condition(const Match<Filter> &M, const ConditionSet &post_cond_child);
111111
};
112112

0 commit comments

Comments
 (0)