I am creating a simple comparison script and I have some questions for the database structure. Firstly the database will be huge, I am expecting more than 1 million entries in products.
Secondly, there will be a search form that the search term will look into (%$term%) the field name and display the product’s related info and shop’s info.
Below you can see my database structure named products.
id int(10) NOT NULL
name varchar(50) NOT NULL
link varchar(50) NOT NULL
description varchar(50) NOT NULL
image varchar(50) NOT NULL
price varchar(50) NOT NULL
My questions are:
-
Do you suggest me to index a field? Users will not be able to insert or update products, the only query will be SELECT to display the results and I will update the products from XML feeds often for possible products changes.
-
I have to store the shop info like name, shipping, link, image… This gives me two option. a) To create a new table named
shopsand join those two tables with a new field inproductsshopID that will look for the id inshopsand display the info or b) Should I add these info (name, shipping, …) in extra fields inproductsin every single product ? (I think the answer is obvious but I need your suggestion). - Are there any other things I should have in mind, or change?
I am not an advanced programmer and what I learn is through internet, so maybe the questions are too obvious for you, but for me is the ticket for learning.
Thank you for your answers.
LIKEclause (e.g.LIKE 'hello%') but it restricts you from using a wildcard at the beginning of the search phrase. In addition, MyISAM has a FULLTEXT index that allows you to search words in the whole string, not just the beginning of the string. So you could create a FULLTEXT index on the columnsdescriptionandname– but 2 FULLTEXT indexes seem redundant in this case. Maybe you could join those columns and separate the values with a token or a character? If so, you’ll need to create only 1 FULLTEXT index on the joined column, which can save a lot fragmentation and disk space. One of the cons for using MyISAM engine is that when writing to it (UPDATE/DELETE queries) – it locks the entire table. So, if the table is written to many times a minute, it will probably make other queries hang. That’s why you should see if InnoDB engine suits your needs – which enables concurrent read/write operations on the table.priceseems essential, and FULLTEXT indexes doesn’t work together with other indexes.id& a regular index onprice.The most important thing for you to understand is that when writing a code for specific software, you must be well familiar with that software and it’s caveats. You should read High performance MySQL – extremely recommended.
Edit:
If you want to add an indexes in the
productstable, you can do that withALTER TABLE /* etc */when the table is empty or contains small amount of data. If the table has a lot of data, then it’s recommended to create another table that’s similar toproducts, altering that new table and populating it with data from the oldproductstable, e.g.: