-
Notifications
You must be signed in to change notification settings - Fork 1
Creating Indexes
Also there are these things called indexes. If a column or columns are often filtered or sorted against, you might want to consider creeating an index for them. They often make queries much faster.
An index can be created using the CreateIndex
method in the SQLiteDatabase
class.
For example, since we made a VIEW to join Album
s and Track
s, it would be a good idea to create an index on the AlbumId
column of the Track
table.
The generic argument is the model class used for the table.
The first argument is the name of the index.
The second argument whether the index is unique. (In this case it is false because multiple Track
s can have the same AlbumId
).
The third argument is a lambda describing the columns to be included in the index.
CreateIndex<Track>("Track_AlbumId", false, t => t.AlbumId);
Just in case you were wondering, I didn't create an index on the AlbumId
column on the Album
table because SQLite implicitly creates an index for PRIMARY KEY columns and columns declared as UNIQUE.
Also indexes can take up a lot of space, so don't go creating one for every combination of columns you have...... unless you need to. :D
- Getting Started
- Creating the Schema
- Updating data
- Querying data
- Data Types Support