14827 items (1495 unread) in 26 feeds
Database
(1495 unread)
When you're storing text of significant size in the table it often makes sense to keep it compressed. Unfortunately MySQL does not provide compressed BLOB/TEXT columns (I would really love to have COMPRESSED attribute for the BLOB/TEXT columns which would make them transparently compressed) but you well can do it yourself by using COMPRESS/UNCOMPRESS functions or compressing/decompressing things on the client.
This choice of server side vs client size compression depends on the queries you have. If you just retrieve these BLOB/TEXT columns for say displaying it in application compressing on application is typically better idea because you will save CPU on database box and move it to the Web box which is typically easier to scale, plus you save on network traffic a bit, though this is not generally the problem.
Compression on the server gives you ability to do some server side filtering (which however would not be overly fast as each row will need to be decompressed) it also makes data easier to work with with console MySQL tools.
Some people get best of both worlds by taking COMPRESS/UNCOMPRESS functions from the MySQL code and having them work on the application side as well which gives you best of both approaches.
One thing you should aware with compression - result of COMPRESS function is always binary, which means even if you're compressing data from TEXT column you should pick BLOB type for compressed data storage.
Before going ahead with compression I usually run some checks to see how much compression will benefit you.
SELECT AVG(LENGTH(body)) FROM data vs SELECT AVG(LENGTH(COMPRESS(body))) FROM data gives good data point. However it may not present you with true data size and performance gains, especially for Innodb tables.
With Innodb tables BLOB gets its own page (allocated outside of clustered index) if the whole row does not fit in the page (longer than about 8000 bytes in size). The whole page is allocated even if you're just a bit short plus BLOB retrieval unless it is in cache will require an extra disk seek. Also remember each BLOB which does not fit in the main row page is given its own page or set of pages potentially requiring a lot of disk seeks for row retrieval and a lot of space wasted.
So compressing BLOB/TEXT you should also think about how many rows you will be able to shrink down so they fit back to the page or at least reduce number of BLOBs on the row which need to be stored externally.
As an example in one case I've seen the compression showing row sizes will reduce about 3 times after compression (some XML data) while in practice table size reduced over 5 times and performance gains were even better because much fewer rows required external storage now.
The BLOB/TEXT column compression is not for all workloads. When your database is small enough to mostly fit in the cache it can cause CPU waste if compressing on database size with almost no gains. Small BLOBs is another case when compression may not give any gains and sometimes even increase the data size rather than reducing it. However it works great for many standard Web application needs - storing blog posts, product descriptions, forum posts (if they are generally long enough) and other data sets.
Entry posted by peter | 15 comments
作者:Fenng 发布在 dbanotes.net. 订阅 DBA notes
最近做项目稍有点累,每到睡前睡不着,只得看一会儿小说转移一下注意力,缓冲一下压力。用这些空隙时间把《德川家康》的第二部《崛起三河》也看完了。看第一部的时候还是比较费力的,毕竟历史背景一点不熟悉,第二本总算熟悉了一些(毕竟咱也查了好几回维基百科嘛)。
竹千代 --> 松平元信 --> 松平元康 --> 松平家康,这套 13 部又厚又长的大作到了第二本总算出现了”家康“这个名字,战国时代的日本人名字可真挺多的,贵圈够乱,这明显不利于 SEO 嘛。哪像咱们三国时候的人名,如曹操曹孟德,一个用到底,个人品牌。当然,这或多或少说明了日本就那么个弹丸之地,而一个大名的领地基本上也就是相当于一个村或者乡那么大,改了名街头巷尾吼几嗓子大家也就知道了。
说每个大名的地盘小,用数字或许能说明,号称当时最有实力进京、领有俊河、远江、三河的今川义元伐织田信长,出动了多少兵力? 两万五千! 自己的主力仅有五千, 而信长连五千都没,最后用急就章似的集合的千把人偷袭居然得手。这一仗今川一方死了武将 500 多,兵士 2500,这个比例着实让我费解,难道日本人在那个时代就已经掌握了管理学的方法:一个管理者最多只带几个兵,否则沟通上有问题...
相比家康的隐忍, 织田信长狂放更令人神往,的确是那个时代的一个怪才。不过胜今川义元的整个过程在这本书里会让人产生"误打误撞"之感,历史就是充满了巧合,短短几个时辰胜负已分。下一部信长"天下布武”,相信会有更多笔墨给描述信长。
织田信长最喜欢唱的这段《敦盛》词我找到了好几个版本:
人生五十年,--《织田信长》书中翻译的版本
如梦亦如幻。
有生斯有死,
壮士何所憾?
人间五十年,跟下天比起来,如梦似幻,人生一度得生,焉有长生不灭者?--百度百科上看到的版本
人生五十年(载),--网上最多的版本。"复何憾"的确更有味道一些。
如梦亦如幻。
有生斯有死,
壮士复何憾
--EOF--
相关文章|Related Articles
评论数量(8)|Add Comments
本文网址:[www.dbanotes.net]
最近作者还说了什么? Follow Twitter / Fenng