Skip to content

Commit

Permalink
Set id as the PRIMARY KEY of AttachmentsIndex for Pg
Browse files Browse the repository at this point in the history
This is consistent with mysql's fulltext table. As id is the primary
key, DB automatically indexes the column which helps performance
especially for the following SQL that is called quite frequently when
indexing data:

    SELECT MAX(id) FROM AttachmentsIndex
  • Loading branch information
sunnavy committed Dec 15, 2023
1 parent 2ee360a commit ebbbf7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions etc/upgrade/5.0.6/schema.Pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE IF EXISTS AttachmentsIndex DROP CONSTRAINT IF EXISTS attachmentsindex_pkey;
ALTER TABLE IF EXISTS AttachmentsIndex ADD PRIMARY KEY(id);
3 changes: 2 additions & 1 deletion sbin/rt-setup-fulltext-index.in
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ elsif ( $DB{'type'} eq 'Pg' ) {
push @schema, split /;\n+/, <<SCHEMA;
CREATE TABLE $table (
id BIGSERIAL,
$column tsvector
$column tsvector,
PRIMARY KEY (id)
);
GRANT SELECT, INSERT, UPDATE, DELETE ON $table TO "$DB{user}"
SCHEMA
Expand Down

0 comments on commit ebbbf7e

Please sign in to comment.