Here are some general tips for improving query performance. Your query may already be near "optimal" and requires a long time to process. But here are some things to check.
1. Most of the time, if you reduce the number of rows the query "scans", you will get your results back faster.
When the database runs a query, it has to read through the tables made of rows. Often this ends up being performed by a set of disk drives that use a mechanical head moving to different regions on a spinning platter. The less you make the heads move, the faster you get your results.
2. Use the LIMIT clause to reduce the number of rows returned.
3. If the query JOINs one or more tables, be sure the columns you are joining on are indexed.
4. If the query JOINs one or more columns, and they are indexed, be sure you do not put a function around the specified joining columns. Otherwise it cannot use the index since it has to perform the function first.
5. If you have a WHERE clause with conditions for ranges (e.g. WHERE g > 5.0 and g < 7.0) and the column is not indexed, see if there is another table named with a "_cs" on the end, for CSTORE. This is a special type of table stored in columnar format instead of rows, and will run much faster for non-indexed columns.