dongnuo3749 2010-02-05 18:44
浏览 35
已采纳

MySQL头痛,我应该或不应该?

I have a classifieds website. I am using SOLR for indexing and storing data. Then I also have a MySQL db with some more information about the classified which I dont store or index.

Now, I have a pretty normalized db with 4 tables.

Whenever ads are searched on the website, SOLR does the searching and returns an array of ID_numbers which will then be used to query mysql. So solr returns id:s, which are then used to get all ads from the mysql db with THOSE id:s.

Now, all the JOIN and relations between my tables gives me a headache.

What except for maintanance-ease do I get for having a normalized db?

I could you know, store all info into one table with some 50 columns.

So instead of this for finding one ad and displaying it:

SELECT 
  category_option.option_name,
  option_values.value 
FROM classified, category_option, option_values 
WHERE classified.classified_id=?id 
AND classified.cat_id=category_options.cat_id 
AND option_values.option_id=category_options.option_id

I could use this:

SELECT * FROM table_name WHERE classified_id = $classified_id

Isn't the last one actually faster? Or does a normalized db permform faster?

Thanks

  • 写回答

3条回答 默认 最新

  • doutai1509 2010-02-05 19:49
    关注

    I would advise against denormalizing in your situation. You'll get better with joins as you use them more and they start to become clearer in your head, and maintenance ease is a good benefit for the future.

    Here's a pretty good link about normalization (and denormalization). Here's a question about denormalization. One answer suggests creating a view using joins to get the data you need, and using that like your SELECT * FROM table_name WHERE classified_id = $classified_id query. A normalized DB will likely be slower, but it's unlikely you'll want to denormalize for that reason. I hope this provides some help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值