title: How can I optimize sql query for count rows with OR in where clause?
body: <p>I have written a SQL query to count the number of rows. I am using IN and OR in WHERE clause.
  The current query is taking a long time (approx 10 sec.) to execute. Please help me to optimize the SQL query.
  I am sharing my code:</p>
  <pre><code>  COUNT(*)
  FROM
    booking_status_journey bs
    INNER JOIN booking_indonesia b ON b.id = bs.booking
  WHERE
    bs.hid IN (
      4,
      5,
      6,
      7,
      11,
      14,
      16,
      17,
      18,
      19,
      23,
      24,
      25,
      26
    )
    AND (
      (
        UNIX_TIMESTAMP(STR_TO_DATE(bs.picked_up_fromwh, '%d/%m/%Y')) &lt;= UNIX_TIMESTAMP('2020-10-15')
        AND UNIX_TIMESTAMP(STR_TO_DATE(bs.picked_up_fromwh, '%d/%m/%Y')) &gt;= UNIX_TIMESTAMP(DATE_SUB('2020-10-15', INTERVAL 5 DAY))
        AND b.no_show_count = 0
        AND bs.rabbit_id1 IS NOT NULL
        AND bs.parcel_picked1 IS NULL
        AND bs.start_delivery1 IS NULL
        AND bs.arrived_at_drop_off1 IS NULL
        AND bs.delivered IS NULL
      )
      OR (
        UNIX_TIMESTAMP(STR_TO_DATE(bs.picked_up_fromwh, '%d/%m/%Y')) &lt;= UNIX_TIMESTAMP('2020-10-15')
        AND UNIX_TIMESTAMP(STR_TO_DATE(bs.picked_up_fromwh, '%d/%m/%Y')) &gt;= UNIX_TIMESTAMP(DATE_SUB('2020-10-15', INTERVAL 5 DAY))
        AND b.no_show_count = 1
        AND bs.rabbit_id2 IS NOT NULL
        AND bs.parcel_picked2 IS NULL
        AND bs.no_show1 IS NOT NULL
        AND bs.start_delivery2 IS NULL
        AND bs.arrived_at_drop_off2 IS NULL
        AND bs.delivered IS NULL
        AND bs.failed IS NULL
        AND bs.returned_after_failed IS NULL
        AND bs.returned_after_no_show1 IS NULL
        AND bs.returned_towh IS NULL
      )
    )```
  
  
  
    [1]: https://i.stack.imgur.com/mPDTG.png
  </code></pre>