php - Which is the best in performance having 1 to many relationships on tables -


i have table company in saving company information , want save n number of company locations particular company (country_id, city_id). 1 company has multiple locations. have save country , city in database in such way if user wants view company filter country or filter city, search fast (indexing applied).

which option give me better performance in terms of fast search, normalization?

option 1: should maintain country id , city id in json , save in company table? no need of new table. every time add or update json based on users selections.

for e.g.

[{"country1" : {city1, city2, city3}},   {"country3" : {city5, city1, city3}}] 

then can (like) query on field -> decode json -> return result

option 2: should create new table , save country's , city's pk along

company_id fk.  company_id (fk) | country id | city id  1 | 25 | 12 1 | 25 | 16 1 | 25 | 19 1 | 30 | 1 1 | 30 | 69 1 | 30 | 14 

then query , return result

normalize if you're using traditional sql.

mongodb , other similar systems storing hierarchical data (marklogic, etc) have ways of making search of json docs fast.

but searching , updating denormalized data unreliable pain in neck in sql. volume have, slow.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -