-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorder tasks columns to optimize row byte alignment
- Loading branch information
1 parent
4eb5c0f
commit fcbbd4e
Showing
1 changed file
with
14 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
CREATE TABLE tasks( | ||
id UUID NOT NULL PRIMARY KEY, | ||
type TEXT NOT NULL, | ||
priority INT NOT NULL DEFAULT 0, | ||
payload JSONB NOT NULL, | ||
created TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
UNIQUE(type, payload) | ||
id BIGINT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY, | ||
state SMALLINT NOT NULL DEFAULT 0, | ||
priority SMALLINT NOT NULL DEFAULT 100 CHECK (priority >= 0), | ||
attempt SMALLINT NOT NULL DEFAULT 0 CHECK (attempt >= 0), | ||
max_attempts SMALLINT NOT NULL CHECK (max_attempts > 0), | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
attempted_at TIMESTAMPTZ, | ||
scheduled_at TIMESTAMPTZ, | ||
queue TEXT NOT NULL DEFAULT 'main' CHECK (char_length(queue) > 0 AND char_length(queue) < 128), | ||
name TEXT NOT NULL CHECK (char_length(name) > 0 AND char_length(name) < 128), | ||
payload JSONB NOT NULL | ||
); | ||
CREATE INDEX tasks_priority_idx ON tasks(priority); | ||
|
||
CREATE UNIQUE INDEX tasks_row_unique_idx ON tasks USING btree(name, payload); | ||
CREATE INDEX tasks_fetch_idx ON tasks USING btree(state, queue, priority, scheduled_at, id); |