# Avoiding table scans of large tables

Derby is fast and efficient, but when tables are huge, scanning tables might take longer than a user would expect. It's even worse if you then ask Derby to sort this data.

Things that you can do to avoid table scans fall into two categories.

- Always create indexes
  Useful indexes prevent Derby from having to read an entire table to retrieve the data you need.
- Prevent the user from issuing expensive queries
  Some applications have complete control over the queries that they issue; the queries are built into the applications. Other applications allow users to construct queries by filling in fields on a form.

Parent topic: Application and database design issues
Related concepts
Avoiding compiling SQL statements
Shielding users from Derby class-loading events