dongzhuo1498 2015-09-24 00:23
浏览 84
已采纳

在SQL中存储标记,类别和int []的最佳方法

I'm just working on putting together the table for blog posts on my site.

I know how to use SQL, and I know a bit about the different types and lengths, but I'm at a loss as to the best lengths and types for my table.

The way I currently have it setup is:

  • id - BIGINT (20)
  • author_id - BIGINT (20)
  • title - text
  • tags - VARCHAR (50)
  • categories - VARCHAR (50)
  • projects - VARCHAR (50)

Tags is a string array of tags for the post, the same with categories. Projects will be an array of ints, that are the ids for the "projects" that are associated with the post. (projects each have their own page about them, and when you go to the page you can get a list of all the posts about it).

My question is, what is the most optimized way I can setup this table?

UPDATE:

Currently I'm interesting in the best ways to store this and optimize disk usage. Right now I have a free x10hosting server I'm going to be using, which has a 512mb limit. If necessary I can pay for a larger server later on, but I want to stick with the free one till I max out my limits.

  • 写回答

2条回答 默认 最新

  • doupaxia2478 2015-10-11 03:42
    关注

    For a serious space conservation requirement:

    • Compress the title in your client and store in a BLOB.
    • Put tags (etc) in a commalist and use FIND_IN_SET() to check if a tags contains a particular tag. This will be slow, and cannot use any indexes.
    • Use MyISAM (2x-3x smaller disk footprint).
    • Minimize indexes.
    • Use TINYINT/SMALLINT/MEDIUMINT instead of INT or BIGINT.
    • Use UNSIGNED
    • Use latin1 if you don't need utf8; use latin1 on anything (eg zipcode) that does not need utf8.
    • 0.5GB is paltry; check other services.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料