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条)

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳