Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Might the schema of event_jounal be optimized? #793

Open
Bugsource opened this issue Jan 8, 2024 · 0 comments
Open

Might the schema of event_jounal be optimized? #793

Bugsource opened this issue Jan 8, 2024 · 0 comments

Comments

@Bugsource
Copy link

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
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant