Postgres 性能:静态行长度?
当表有没有可变宽度列
postgres 有类似的行为吗?向表中添加单个可变宽度列是否会产生重大影响?
Mysql behaves in a special (presumably more performant) manner when a table has no variable-width columns
Does postgres have similar behavior? Does adding a single variable-width column to a table make any major difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
postgres 文档中给出的一般建议(阅读提示)可变长度字段通常性能更好,因为它会产生更少的数据,因此表适合更少的磁盘块并占用更少的高速缓存空间。现代 CPU 的速度比内存和磁盘快得多,因此可变长度字段的开销值得 IO 的减少。
请注意,postgresql 将 NULL 值存储在行开头的位图中,如果值为 NULL,则省略该字段。因此任何可为空的列基本上都有可变的宽度。 postgresql 存储数据的方式(数据库页面布局)表明检索最后一列会比第一列慢。但是,如果您有很多列并且数据主要在缓存中,那么这可能只会产生显着的影响。否则磁盘io将成为主导因素。
The general advice given in the postgres docs (read the tip) is that variable length fields often perform better because it results in less data so the table fits in less disk blocks and takes up less space in cache memory. Modern CPU's are so much faster then the memory and disks that the overhead of variable length field is worth the reduction in IO.
Notice that postgresql stores NULL values in a bitmap at the beginning of the row and omits the field if the value is NULL. So any nullable column has basically a variable width. The way postgresql stores it data (Database page layout) suggests that retrieving the last column would be slower then the first column. But this will probably only have a noticable impact if you have many columns and the data was mostly in cache to start with. Otherwise the disk io will be the dominant factor.
据我所知,不,它不会
检查此链接以获取有关数据类型的一般讨论,我从这篇文章中得出的结论是,无论 mysql 表现出什么特殊行为,postgresql 都没有,这对我来说是好的。 http:// www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/
From what I know, no it doesn't
Check this link out for general talk about datatypes my conclusion from this read is whatever special behavior mysql exhibits, postgresql doesn't which to me is good. http://www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/
我永远不会相信任何“性能神话”,除非我用我自己的数据集和我的应用程序的典型工作负载进行测试。
如果您需要知道您的工作负载在 DBMS X 上是否足够快以及您的数据,那么除了从您的实际基准测试中获得的数字之外,不要查看任何其他内容。具有与生产相匹配的硬件的环境。
任何其他方法都可以通过盯着好的水晶球来代替
I would never ever believe any "performance myth" unless I test it with my own set of data and with a workload that is typical for my application.
If you need to know if your workload is fast enough on DBMS X with your data, don't look at anything else than the numbers you obtain from a realistic benchmark in your environment with hardware that matches production.
Any other approach can be replaced by staring at good crystal ball