DEV Community

Discussion on: Speed up your queries with indexes

Collapse
 
nhh profile image
Niklas

Keep in mind, that indexes are only useful if you have a high variance in your data, like username or firstname, lastname. Something that is limited in its variabce, like a enum field - category for example which holds only 5 possible categories isnt the best choice to add an index πŸ˜ŠπŸ‘

Collapse
 
andytower_rus profile image
Andrey Alferov

It's not always true. Selective index is good but if you not index on column in foreign key you may can get big problem with locks.

Collapse
 
nhh profile image
Niklas

Can you explain this a little further? :)

Thread Thread
 
andytower_rus profile image
Andrey Alferov

Of course. For example table2 have column colF and foreign key to table1. If on colF not indexing and while table1 (any data) change we have exclusive table lock on table2. It's true for Oracle.
I have this problems many times.

Thread Thread
 
nhh profile image
Niklas

Cool, thank for sharing! I guess its kind if database agnostic, good to know for oracle! ✌️😊

Collapse
 
helenanders26 profile image
Helen Anderson

Great advice! That’s certainly what I do in the real world and more often than not it will be two or three columns not just one

Collapse
 
say_whaaaaaattt profile image
Hypertext

yeah for that you can use look up table