我有一个简单的问题。
我正在做一个使用 MySQL 的 Web 应用程序,目前正在设计它。我只是有一个关于性能的小问题。
我想知道什么更有效率:
场景 #1:
Table: Restaurant
-Name
-City
-Province
-Country
-Continent
sql =~ select * from restaurant where id = something.
或
场景#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]
从逻辑上讲,我认为场景 #1 更好(查询更少),但有些人向我发誓并非如此。
最佳答案
是的,但问题是哪个选项表现更好。在那种情况下,毫无疑问:选项 # 1 将执行得更好,因为查询不必与任何其他表连接。 Randolph 确实有一个很好的观点,您应该尽可能规范化您的数据库结构。
关于mysql - 性能表布局(多个查询与一个大查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1570648/