Search code examples
phpmysqlnormalization

MYSQL storing id or descriptive text for performance


Excuse my lack of knowledge. Im creating a a php/mysql website which will store records for adverts for various cars. Each advert record will contain a car model and car make data as well as description, price etc...

On my create advert form I have 2 select fields to lookup car make and model from tables which contain an id and car make for all makes, and an id, car make and car model for all models.

My question is when I am selecting the data on the advert create form is it best to get the id, and car make, then just store the "id" in my advert table, or should I store the actual "car make" and "car model" in my advert table in my database?

im presuming just the id's would be quicker for searching purposes, then when I lookup the data to display, I would then need to get the id and do a join on the car make and model tables to get the car make and model descriptions to display.

Would this be far better for performance? or would it make no difference than just storing the car make and model in every advert record, so I didnt need to do the join to display them later?


Solution

  • What you are talking about is database schema (de)normalization. I would strongly recommend storing IDs and doing JOINs when fetching data. Then somewhen down the line, after you have much much much & much traffic you can start thinking about denormalizing your schema (ie including stuff "inline" ... for performance reasons).