Fix JOINs that have ORDER BY rand()

Previously "Only deterministic expressions may be considered for rewrite" exception was thrown