# Query optimization

**URL:** <https://forums.percona.com/t/query-optimization/6582>\
**Category:** Percona Server for MySQL 5.7\
**Created:** [September 18, 2018, 3:32am UTC](https://forums.percona.com/t/query-optimization/6582 "2018-09-18T03:32:22Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Ceri\_Williams](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ceri_williams/32/1218_2.png) [@Ceri\_Williams](https://forums.percona.com/u/Ceri_Williams)\
**Post date:** [September 21, 2018, 6:51am UTC](https://forums.percona.com/t/query-optimization/6582/10 "2018-09-21T06:51:39Z")

</div>

Hi, judging by the query response time that you had concerns about, setting

```auto
long_query_time = 10

```

will show you nothing. Try something like the following:

```auto
long_query_time=0
log_slow_rate_limit=100
log_slow_rate_type=query
log_slow_verbosity=full
log_slow_admin_statements=ON
log_slow_slave_statements=ON
slow_query_log_always_write_time=1
slow_query_log_use_global_control=all
innodb_monitor_enable=all
userstat=1

```

For the query that you have posted here

```auto
FROM_UNIXTIME(delivery_at, GET_FORMAT(DATE,"ISO")) = FROM_UNIXTIME(1537561200, GET_FORMAT(DATE,"ISO")) 

```

If this is aiming to look for an order that is for delivery on the current day then you would be better to check that delivery\_at is within a range with constants, e.g.

```auto
mysql> SET &#64;ts := UNIX_TIMESTAMP(), &#64;day_start_ts := UNIX_TIMESTAMP(CURDATE()), &#64;day_end_ts := UNIX_TIMESTAMP(CURDATE() + INTERVAL 86399 SECOND);
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT &#64;ts BETWEEN &#64;day_start_ts AND &#64;day_end_ts, &#64;ts, &#64;day_start_ts, &#64;day_end_ts;
+-------------------------------------------+------------+---------------+-------------+
| &#64;ts BETWEEN &#64;day_start_ts AND &#64;day_end_ts | &#64;ts | &#64;day_start_ts | &#64;day_end_ts |
+-------------------------------------------+------------+---------------+-------------+
| 1 | 1537532265 | 1537484400 | 1537570799 |
+-------------------------------------------+------------+---------------+-------------+
1 row in set (0.00 sec)

```

The use of variables here is just to demonstrate, but you would use delivery\_at and could just use the functions in the comparison, i.e.:

```auto
delivery_at BETWEEN UNIX_TIMESTAMP(CURDATE()) AND UNIX_TIMESTAMP(CURDATE() + INTERVAL 86399 SECOND)

```

Hopefully that will help you find the queries.

Ceri

---

_[View the full topic](https://forums.percona.com/t/query-optimization/6582)._
