How can I tune this query? It got even slower when I created the index for (state_id, order_id desc). The following explain analyze output is without an index. It takes 13 seconds if I create that index. Could you help me?
Thank you so much for your help.
SELECT DISTINCT ON (order_history.order_id) order_id, order_history.creation_date AS c_date FROM work.order_history WHERE (order_history.state_id = ANY (ARRAY[30, 51, 63, 136, 195, 233, 348])) AND order_history.is_false = 0 ORDER BY order_history.order_id DESC;