mysql - How does a database loop through rows? -
this question has answer here:
- how database indexing work? 10 answers
i'll start explaining scenario: creating mmorpg , want better understanding of efficient way store items in inventory. research, found games have inventory table rows have item_id, item_quantity, user_id, , slot_id.
i'm thinking table potentially have millions of rows.
so if use simple statement such as:
select item_id inventory user_id = 25;
then how database "find" result return? have "loop" through every single record until finds match? concern that, if in fact way done, wouldn't select statements take forever?
thanks, ian
you need follow basic principles of table creation.
- have id column
- keep table normalized(check out table normalization online. find lots of stuff).
- add indexes on column. ex: in inventory table can have index on user_id column if using on conditions often. index on user_id groups table data user_id , leads faster query exection.
Comments
Post a Comment