Might the schema of event_jounal be optimized?
Bugsource opened this issue · 0 comments
Bugsource commented
unique index degenerate
As stated in this issue, the foreign key of event_tag
has been changed from ordering
to primary key of event_journal
for performance.
So i guess that the unique index on ordering
may be somehow simplified? I scanned the source code and found that the field ordering
had been used in where
and order by
clauses. If this unique constraint of ordering
is not necessary, then can this unique index degenerate into a normal index?
Details
CREATE TABLE IF NOT EXISTS public.event_journal (
ordering BIGSERIAL,
persistence_id VARCHAR(255) NOT NULL,
sequence_number BIGINT NOT NULL,
deleted BOOLEAN DEFAULT FALSE NOT NULL,
writer VARCHAR(255) NOT NULL,
write_timestamp BIGINT,
adapter_manifest VARCHAR(255),
event_ser_id INTEGER NOT NULL,
event_ser_manifest VARCHAR(255) NOT NULL,
event_payload BYTEA NOT NULL,
meta_ser_id INTEGER,
meta_ser_manifest VARCHAR(255),
meta_payload BYTEA,
PRIMARY KEY(persistence_id, sequence_number)
);
CREATE UNIQUE INDEX event_journal_ordering_idx ON public.event_journal(ordering);
CREATE TABLE IF NOT EXISTS public.event_tag(
event_id BIGINT,
persistence_id VARCHAR(255),
sequence_number BIGINT,
tag VARCHAR(256),
PRIMARY KEY(persistence_id, sequence_number, tag),
CONSTRAINT fk_event_journal
FOREIGN KEY(persistence_id, sequence_number)
REFERENCES event_journal(persistence_id, sequence_number)
ON DELETE CASCADE
);