The snippet you've quoted is a template, not a specific SQL statement, and you are a bit vague on the parameters you've used ('for a period of a month or longer').
And of course, individually observed times would depend on hardware as well as database sizes.
When running this for a 600 seconds interval for the last 30 days, it takes just over a second on my ARMv7 machine, serving the db from an sdcard, with ~150,000 queries for that interval.
But as you refer to api_db.php, I wonder whether your observations would be referring to responsiveness of Pi-hole's UI, rather then raw SQL statements?
The major impact on times observed when using Pi-hole's web UI would be the web UI itself, not the database.
Note that Pi-hole v5 uses PHP for rendering the results, which adds its own overhead, especially since v5 does not support server-side pagination. The most recent 30 days take about 13 seconds on my machine, so a good dozen times longer than direct SQL.
For large result sets, that may even fail completely, if data would exceed PHPs memory limits.
This will change in the upcoming Pi-hole v6 (currently in beta), which will support server-side pagination and won't use PHP any more.
If you'd like to propose specific, concrete SQL improvements, you are most welcome to join the current Pi-hole V6 Beta Testing and contribute your improvements.