您认为哪种设计在 PostgreSQL 上运行得更快?
制作一个 15 列的 varchars 等表,但将所有 TEXT 列放在一个单独的表中,并使用返回此表的 fkey 链接。假设您想要搜索 ID 为“4”的记录,然后将所有行拉回,包括连接表中 TEXT 列的内容。让我们假设这些表有 500,000 行。
制作一个 15 列的 varchars 等表,并将您的 TEXT 列包含在同一个表中。同样,假设与上面相同——抓取记录 ID 4 并拉取完整记录,表中有 500,000 行。
我的意思是,在大多数数据库中,按照我的理解,当你深入了解这些 TEXT 列如何工作的物理层时,它们实际上在每一行的表列中保留一个小 ID,并且该 ID 转到数据库中单独的排他页 block (或其他命名法)。所以,对我来说,似乎选项 B 会运行得更快,因为不需要 fkey 连接的开销,并且因为 TEXT 列实际上占用的空间不超过给定表中该列的整数空间 -并且该整数是数据库中其他地方的页面 block 的键。
最佳答案
PostgreSQL 处理 TEXT 列的方式与其他 DBMS 不同。
来自他们的文档:
Tip: There are no performance differences between these three types, apart from increased storage size when using the blank-padded type, and a few extra cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, it has no such advantages in PostgreSQL. In most situations text or character varying should be used instead.
关于performance - 在 PostgreSQL 中,在同一个表中包含 TEXT 列比在单独的表中包含更快吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/348416/