mysql - Should I duplicate data in my DB? -


i have mysql db containing entry pages of website. let's has fields like:

table pages:  id  |  title  | content | date | author 

each of pages can voted users, have 2 other tables

table users: id  |  name  | etc etc etc  table votes: id  |  id_user | id_page | vote 

now, have page show list of pages (10-50 @ time) various information along average vote of page.

so, wondering if better to:

a) run query display pages (note heavy queries 3 tables) , each entry query calculate mean vote (or add 4th join main query?).

or

b) add "average vote" column pages table, update (along vote table) when user votes page.

nico

use database it's meant for; option far best bet. it's worth noting query isn't particularly heavy, joining 3 tables; sql excels @ sort of thing.

be cautious of sort of attempt @ premature optimization of sql; sql far more efficient @ people think is.

note benefit using option there's less code maintain, , less chance of data diverging code gets updated; it's lifecycle benefit, , they're ignored miniscule optimization benefits.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -