Optimizations for row_number() window functions
Fix CROSS JOIN bug

Fixes #1548