mysql - How does a database loop through rows? -


this question has answer here:

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.

  1. have id column
  2. keep table normalized(check out table normalization online. find lots of stuff).
  3. 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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -