MySql: is it wise to use a "view", or would I rather denormalize my DB?

There is a table "team_sector" with the following fields: Id, team_id, sect_id, size, level

It contains several entries for each "team" object (link to the "team_id" field). Each entry represents a sector of the team stadium (a total of 8 sectors).

Now you need to complete several queries:

  • total stadium size (SUM (size));
  • best quality (SUM (level) / COUNT (*)).

I could create a query something like this:

SELECT TS.team_id, SUM(TS.size) as OverallSize, SUM(TS.Level)/COUNT(TS.Id) AS QualityLevel
FROM team_sector
GROUP BY team_id
ORDER BY OverallSize DESC / ORDER BY QualityLevel DESC

But my concern here is that the calculation for each team will be performed every time the request is executed. This is not too much overhead (at least for now), but I would like to avoid performance issues later.

2 .

1- 2 "team" () WholeSize QualityLevel. , "" , (, , ).

- , .

, / .

Q1: ? , ?

Q2: , ( )? - ?

Q3: (1- ).

P.S. MySql 5.1, 1-2 , - 6-8 . , , .

+3
2

() - , .

:

  • ,
  • ""
  • , ,
  • .

, SUM() , /, , .

, , - , , ( ) .

, "" , , .

+1

. , . " ", , .. ( PK PK ).

- , , - . , , , , cron. , , . , , " ", , , .

+2

Source: https://habr.com/ru/post/1783126/


All Articles