Commit 488148dd authored by Monty's avatar Monty Committed by Sergei Petrunia

Added checking of arguments to COST_ADD and COST_MULT

These functions don't work with negative values and should never be
called with negative values. Added an assert to ensure this will
not happen.
parent 07df2029
......@@ -179,8 +179,18 @@ static inline double cache_hit_ratio(uint ratio)
#define COST_MAX (DBL_MAX * (1.0 - DBL_EPSILON))
#define COST_ADD(c,d) (COST_MAX - (d) > (c) ? (c) + (d) : COST_MAX)
static inline double COST_ADD(double c, double d)
{
DBUG_ASSERT(c >= 0);
DBUG_ASSERT(d >= 0);
return (COST_MAX - (d) > (c) ? (c) + (d) : COST_MAX);
}
#define COST_MULT(c,f) (COST_MAX / (f) > (c) ? (c) * (f) : COST_MAX)
static inline double COST_MULT(double c, double f)
{
DBUG_ASSERT(c >= 0);
DBUG_ASSERT(f >= 0);
return (COST_MAX / (f) > (c) ? (c) * (f) : COST_MAX);
}
#endif /* OPTIMIZER_COSTS_INCLUDED */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment