From 076679d9f2b761a9e4892e399f1a16f141d85986 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 18 Mar 2026 13:19:42 +0000 Subject: Replace unique constraint on entity value with index on hash UNIQUE CONSTRAINT is limited to 2704 bytes, which prevents inserting large values. Here we swap to a unique index on the MD5 hash of the value. This should more than suffice given we already map to a 32bit for the id and the index size is much much smaller. --- src/schema.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/schema.sql b/src/schema.sql index 140f2a5..789789a 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -37,10 +37,11 @@ CREATE TABLE entities( value text NOT NULL, type entity NOT NULL, detail jsonb, - CONSTRAINT pk_entities PRIMARY KEY (id), - CONSTRAINT uni_entities_value UNIQUE (value) + CONSTRAINT pk_entities PRIMARY KEY (id) ); +CREATE UNIQUE INDEX uni_entities_value ON entities(MD5(value)); + CREATE TABLE access_log( id bigint GENERATED ALWAYS AS IDENTITY, hostname oid NOT NULL, -- cgit v1.3