i am working with a table of 10 Million Rows and i am selecting the first 10 or the last 10 rows with this query:


    SELECT * FROM category_member ORDER BY (p::float8/q) DESC LIMIT 10;

I am ordering by (p::float8/q) cause i am using a user specified order with fractions as index ( see: https://wiki.postgresql.org/wiki/User-specified_ordering_with_fractions)

This query takes to long in my eyes 16,135 s to get the first 10 rows of a table with 10 Million rows.

Anyone had the same issue and knows how to improve performance on my query?