when should separate field for
- filtering search?
EDIT: 2. in general when should I separate them (at least in example below brand, country, type, operation system are candidate and capable of being in separate table)
for example I have product table and I want to have filter on :
- screen size
- brand
- color
- country build
- type (tablet, smartphone, simple,)
- operation system
- camera pixel
- price
- and so on..
for what fields I should have separate table with many to one relation?
If you want to completely normalize everything and avoid redundant data, and simply use foreign key references in your main table, then create separate tables for all repetitive product properties. Which would be pretty much everything except "price" in the sample list you mention.
Otherwise, just for purposes of search filtering, you don't necessarily need to have any of them in separate tables. Just stack up
WHERE
conditions that you match against a single table. What you're on about is less of a search issue and more of a general database and back-end design matter.Also be aware that if you need to match many search conditions at once, then your queries may end up becoming expensive with multiple joins, if you've separated your data into many tables. You can only create multiple-column indexes inside a single table, and you'll probably want to have joint indexes for the most common types of product property combo queries.