Genie.jl icon indicating copy to clipboard operation
Genie.jl copied to clipboard

Add note on what `add_index` does in the database table

Open logankilpatrick opened this issue 3 years ago • 7 comments

Right now, the add index part of the database table creation is unclear. What does it do?

logankilpatrick avatar Feb 01 '22 15:02 logankilpatrick

Indexes are used to retrieve data from the database very fast. The users cannot see the indexes, they are just used to speed up searches/queries

AbhimanyuAryan avatar Feb 01 '22 16:02 AbhimanyuAryan

Why would every column not have an index?

logankilpatrick avatar Feb 01 '22 16:02 logankilpatrick

@logankilpatrick because it's expensive. Indexing every column in every table will tax the DBMS too much in terms of index- maintenance processing, especially if the table has many attributes, many rows, and/or requires many inserts, updates, and/or deletes

AbhimanyuAryan avatar Feb 01 '22 16:02 AbhimanyuAryan

Makes sense, so what is the rule of thumb for which to index?

logankilpatrick avatar Feb 01 '22 16:02 logankilpatrick

Also, this should explain more clearly: https://stackoverflow.com/a/5448055/4417582

AbhimanyuAryan avatar Feb 01 '22 16:02 AbhimanyuAryan

That helps! Thank you :)

logankilpatrick avatar Feb 01 '22 16:02 logankilpatrick

?

It depends: https://stackoverflow.com/questions/107132/what-columns-generally-make-good-indexes

can be unique, the one that you accesses frequently, also depends what speeds up your query

AbhimanyuAryan avatar Feb 01 '22 17:02 AbhimanyuAryan