quadbase icon indicating copy to clipboard operation
quadbase copied to clipboard

Find suitable indices for the database

Open Dantemss opened this issue 13 years ago • 3 comments

To further speed up search.

Dantemss avatar Jun 04 '12 23:06 Dantemss

OK I determined that what needs to be done is simply to manually create indices on ALL foreign keys (use migrations).

Foreign keys are understood as all columns in a table that contain the primary key of some other table (rails does not use foreign key constraints directly). That means anything that belongs_to needs to be indexed pretty much.

If there are any validations on the model that ensure the uniqueness (validates_uniqueness_of) of this column in the entire table, make the index unique.

Dantemss avatar Jun 06 '12 15:06 Dantemss

Furthermore, we should index other numbers and small text fields that can be used in searches (definitely do not index things such as question content). For example, we could index user first and last names, username, email, question types, etc.

Also, I said all foreign keys but some of those are practically unused. For example, do not index license_id in questions, as we really never search for that (Questions.where{license_id == blah})

Dantemss avatar Jun 07 '12 19:06 Dantemss

Hey JP, should I make it a constraint so that the same question can't be in the same project twice (2 different project_questions with the same project_id and question_id)?

Dantemss avatar Jun 11 '12 21:06 Dantemss