Fix row number optimizations for unreferenced outputs