Bugfix: Fix query and subquery when  has no conditions.
Added index to the  table for the  column.