Automatically selection of retention policy based on range(), and requirement for now()

I don’t want to manually select the best retention bucket for my query, and I certainly don’t want the users of my grafana ui to have to.
I want influx to automatically select the bucket with the best granularity of data, that contains data with the range I have specified.

talek’s excellent attempt to work around the issue is here:

However it only works if your end time $__to happens to be now.
taleks example can however be placed into mysql instead of influx in order to use it’s now() function to achieve the desired result from grafana (Since you can have a mix of datasources).

i.e.

so instead of having to hunt

from(bucket:"my_db/autogen")
|> range(start: a_long_time_ago, end: some_time_after_that)

NO DATA

from(bucket:"my_db/a_while_back")
|> range(start: a_long_time_ago, end: some_time_after_that)

THE TAIL END OF THE DATA!

from(bucket:"my_db/a_long_while_back")
|> range(start: a_long_time_ago, end: some_time_after_that)

DATA!

Instead
from(bucket:"my_db", range(start: a_long_time_ago, end: some_time_after_that))

should work out the the shortest retention policy that encompasses the range specified
i.e.
the a_long_while_back policy.