Untitled attachment
https://eientei.org/media/77/72/d3/7772d33a973b9da2b2d2a05b11eb6427eed626a806a7f5d6656242864f66c5ac.jpg?name=72ff2466cc3cdf7e7196e173f9d7c444.jpg
(1/2)
Migrating pleroma database to partitioned objects/activities tables seems to be possible with some schema and query alterations.
There are two main problems that could prevent meaningful partitioning
Countering P1 is easy - by simply changing the type from bigint to uuid updating all relations:
Pleroma uses time-ordered 128-bit flake ids, which are by default structured as
So inserted_at can be used as a timestamp and original bigint id can be smeared across remaining 64 bits, allowing backward migration.
After dropping all foreign keys on objects-related tables and default sequence generator it's just alter type using, like
Then every objects-related table needs a temporary field to set new uuid alongside their old foreign key bigint and similarly migrated with alter type using that temporary field. Then temporary fields can be dropped and foreign key constraints re-added.
Countering P2 is more complicated, since existing activities/objects tables need to be split further in two: partitioned data table and unpartitioned denormalization/index table.
unpartitioned activities_attributes table must have:
unpartitioned objects_attributes table must have:
fts_content can actually be partitioned without much impact to search queries.
To match current interface, activities_data and activities_attributes can be joined with a table without much impact, since data from both is needed in virtually every query.
Objects can remain as plain table since a lot of times it's just lookup by object id without any need for objects_attributes fields, with manual joins in queries where needed.
Both activities view and objects table would need triggers after insert and before delete (or instead in case of a view) to populate corresponding attributes. With it, separate status_visibility_counter_cache_trigger is also no longer needed and can be incorporated into activity triggers, since both can benefit from shared logic.
A proof of concept based on upstream develop supporting schema above, including up/down migrations and necessary query/test changes:
https://gitlab.eientei.org/eientei/pleroma/-/tree/upstream-flake
migration: https://gitlab.eientei.org/eientei/pleroma/-/blob/upstream-flake/priv/repo/migrations/20250109104615_migrate_objects_to_flake_id.exs
On eientei DB snapshot (~230G combined activities and objects) it takes 3-6 hours.
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.