我在表中的一个字段包含大量内容(文本或二进制数据)。如果我想知道另一文本是否等于该文本,则可以使用校验和比较这两个文本。我可以将此字段定义为 UNIQUE 以避免重复的内容。
I have a field in a table with large content (text or binary data). If I want to know if another text is equals this one, I can use a checksum to compare the two texts. I can define this field as UNIQUE to avoid repeated content too.
我的疑问是是否创建校验和字段,此比较将加快速度,因此PostgreSQL已经执行了此操作(无需程序员干预)还是我需要手动执行此操作?
My doubt is if I create a checksum field, this comparison will speed up, so PostgreSQL already does this (without need programmer intervention) or I need do this manually?
编辑:更好,为 TEXT 字段创建一个校验和,对其使用校验和还是两种方式相同?
What is better, create a checksum for a TEXT field, use a checksum for it or the two ways are the same thing?
推荐答案PostgreSQL中的大列没有默认的校验和,您必须自己实现一个。
There is no default "checksum" for large columns in PostgreSQL, you will have to implement one yourself.
哈希索引可为平等检查提供快速性能。并且它们会自动更新。但是它们尚未完全集成到PostgreSQL中,因此不鼓励使用-阅读手册。
Hash indexes provide fast performance for equality checks. And they are updated automatically. But they are not fully integrated in PostgreSQL (yet), so their use is discouraged - read the manual.
您将无法查询值并在应用程序中使用它们。您可以使用校验和列来做到这一点,但是如果表很大并需要维护该列,则需要添加性能索引。为此,我将使用触发器在插入或更新之前。
And you cannot query the values and use them in your application for instance. You could do that with a checksum column, but you need to add an index for performance if your table is big and maintain the column. I would use a trigger BEFORE INSERT OR UPDATE for that.
因此,哈希索引可能会也可能不会为了你。 @AH的想法肯定适合这个问题...
So, a hash index may or may not be for you. @A.H.'s idea certainly fits the problem ...
更多推荐
PostgreSQL中的Checksum字段与内容比较
发布评论