What database are you using? Oracle [1] and MySQL [2] for example let you embed hints in the query in order to change the execution plan. I think that PostreSQL doesn't have such a feature though (at least it did not a few years ago).
[1] https://docs.oracle.com/cd/B19306_01/server.102/b14211/hints...
[2] https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html