Middle
Why do requests take a long time? How many rows were selected last month?
sobes.tech AI
Answer from AI
Long query execution times are usually related to several reasons:
- Absence or inefficient indexes on fields involved in filtering or joins.
- Large volume of data to process.
- Incorrect queries with excessive JOINs or subqueries.
- Locks or high contention for database resources.
To understand how many rows were selected last month, you need to run a query with a date filter, for example:
SELECT COUNT(*) FROM table_name WHERE date_column >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month')
AND date_column < DATE_TRUNC('month', CURRENT_DATE);
In Go, you can use the database/sql package to execute such a query and get the row count.