Table layout for execution (multiple query versus one large query)

I have a simple question.

I am building a web application using MySQL and am currently designing it. I only have a small question about performance.

I would like to know which is more efficient:

Scenario number 1:

Table: Restaurant
    -Name
    -City
    -Province
    -Country
    -Continent

sql =~ select * from restaurant where id = something.

or

Scenario number 2:

Table: Restaurant   
    -Name
    -City
Table: City
    -Name
    -Province
Table: Province
    -Name
    -Country
Table: Country
    -Name
    -Continent
Table: Continent
   -Name

sql =~ [insert multiple sql queries that will output the name and the city,
        with the corresponding province, country, and continent]

Logically, I think scenario # 1 is better (less request), but some people have sworn to me otherwise.

+3
source share
5 answers

, , . : №1 - , JOIN . Randolph , , .

+3

, . . , , .

, . , . :

SELECT *
FROM restaurant
    JOIN city ON city.id=restaurant.city
    JOIN province ON province.id=city.province
    ...

, , , ( ). ORM .

+2

- , , , .. , .

, SELECT * FROM [Table] . .

0

, ( , , ), /, , .

. , ( , , , ). , .

. : , , ( : , , , ). SQL , , , .

, . , , SQL- , , , . , , .

, , .

, ( ), , . (, , ).

0

, , . " ". , , , , .

. ( !) http://en.wikipedia.org/wiki/Database_normalization

Wikipedia , denormalized , , , .

. shits , =).

.

0

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


All Articles