I've got a function which is doing simple sqlx.Select(...):
func filteredEntities(ex sqlx.Ext, baseStmt string, res interface{}, f entities.UserProjectTimeFilter) error {
finalStmt, args, err := filteredStatement(baseStmt, f)
if err != nil {
return err
}
err = sqlx.Select(ex, res, finalStmt, args...)
return errors.Wrap(err, "db query failed")
}
Most of queries are going well (10-20ms), but one of them, such as:
"
\tSELECT * FROM Productivity
\t WHERE user_id IN (?) AND (tracker_id, project_id) IN ((?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?...
The query was taken from logs and not formatted. It is executing more than 10 seconds (sometimes even more than 20). However, from a dump of the database, it is executing less than 1 second. The selection has less than 100 rows. A query even doesn't have "joins" and etc. Just simple "select" with conditions.
Which might be slower? All time was measured by default time.Now() and time.Since().
The table has these columns:
+---------+-------------+---------+-------------+----------+------------+------------+------------+--------+
| id | planning_id | user_id | activity_id | duration | project_id | tracker_id | created_at | useful |
+---------+-------------+---------+-------------+----------+------------+------------+------------+--------+