> I'm wondering if there's something else we could do that doesn't involve tuning pg (i.e. make sure it has the right statistics and picks a good plan on its own)
The thing is, the statistics are only going to be useful if PG knows what is the actual timestamp you're filtering by. And that's the whole problem: it uses a generic plan, ignoring the actual values of the parameters.
So as long as we pass the
as a param, that's going to be a problem. The only other option I see is sanitising the timestamp and injecting it into the query dynamically