# Avoid expensive queries

Some expensive queries can, and should, be avoided.

Two examples:

    SELECT DISTINCT nonIndexedCol FROM HugeTable

    SELECT * FROM HugeTable ORDER BY nonIndexedColumn

See Prevent the user from issuing expensive queries.

Parent topic: Performance tips and tricks
Related concepts
Use prepared statements with substitution parameters
Create indexes, and make sure they are being used
Ensure that table statistics are accurate
Increase the size of the data page cache
Tune the size of database pages
Use the appropriate getXXX and setXXX methods for the type
Tune database booting/class loading
Avoid inserts in autocommit mode if possible
Improve the performance of table functions
Configure Derby to use an in-memory database
Increase the concurrency of sequences
Shut down the system properly
Put Derby first in your classpath