I would like to optimize the following query in postgres
SELECT(MIN("products"."shipping") AS minimal FROM "products" WHERE "products"."tag_id" IN (?)
with an index like
CREATE INDEX my_index ON products (tag_id, shipping DESC);
Unfortunately this one is only used when it's just one tag. Almost alwayst it is queried for a handful of tags at the same time, but then postgres uses the index products (shipping DESC)
which is quite slow.
What could I do to speed up my query?
It turned out (please see comments), that this query:
is able to deceive PostgreSQL in such a way, that it performs better because, as I guess, it uses the index in this case.