[Rt-commit] rt branch 5.0/pg-attachments-index-primary-key created. rt-5.0.5-83-gd8ffad7a8a

BPS Git Server git at git.bestpractical.com
Wed Dec 20 21:44:50 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/pg-attachments-index-primary-key has been created
        at  d8ffad7a8af7c8d1fd4bc4bed80825a3a11734cf (commit)

- Log -----------------------------------------------------------------
commit d8ffad7a8af7c8d1fd4bc4bed80825a3a11734cf
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Dec 15 06:51:21 2023 -0500

    Set id as the PRIMARY KEY of AttachmentsIndex for Pg
    
    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
    
    Mainly to support customized fulltext table name, we implement the
    upgrade in Perl instead of SQL. Use "indexes" instead of "content"
    considering the database handle "content" uses usually doesn't have the
    permission to alter tables, not mentioning that it's more like an index
    change.

diff --git a/etc/upgrade/5.0.6/indexes b/etc/upgrade/5.0.6/indexes
new file mode 100644
index 0000000000..f1cb38e7d2
--- /dev/null
+++ b/etc/upgrade/5.0.6/indexes
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+if ( RT->Config->Get('DatabaseType') eq 'Pg' ) {
+    my $fulltext = RT->Config->Get('FullTextSearch');
+    if ( my $table = $fulltext->{Table} ) {
+        my $handle = RT->DatabaseHandle;
+        if ( my $indexes = { $handle->Indexes }->{ lc $table } ) {
+            if ( !grep { $_ eq lc "${table}_pkey" } @$indexes ) {
+                my $res = $handle->dbh->do("ALTER TABLE IF EXISTS $table ADD PRIMARY KEY(id)");
+                if ( !$res ) {
+                    RT->Logger->error("Could not add PRIMARY KEY to table $table");
+                }
+            }
+        }
+    }
+}
+
+1;
diff --git a/sbin/rt-setup-fulltext-index.in b/sbin/rt-setup-fulltext-index.in
index 4e75e7eda7..d079ab4092 100644
--- a/sbin/rt-setup-fulltext-index.in
+++ b/sbin/rt-setup-fulltext-index.in
@@ -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

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list