Removing unused indexes #764

Open
opened 2024-04-28 14:39:34 +00:00 by norm · 19 comments
Contributor

Been discussing with @Oneric in private about this for a bit. There's quite a bit of indexes that are either unused, null, or duplicates of others.

On my instance, this is what Phoenix LiveDashboard reports:

 Unused indexes detected: 'activities_cc_index', 'activities_hosts', 'activities_in_reply_to', 'activities_local_index', 'activities_to_index', 'aa_users_ap_id_COALESCE_follower_address_index', 'users_featured_address_index', 'users_following_address_index', 'objects_likes', 'activities_likes', 'users_last_status_at_index', 'users_is_suggested_index', 'apps_client_id_client_secret_index', 'users_tags_index', 'users_uri_index', 'users_invisible_index' 

Null indexes detected: 'users_email_index', 'users_last_active_at_index' 

Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 20 MB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB' 

Not listed are indices that have a low hit rate, since I don't really know what's a good threshold for those.

Removing unused indices should help with disk space usage and potentially also make write operations faster.

Been discussing with @Oneric in private about this for a bit. There's quite a bit of indexes that are either unused, null, or duplicates of others. On my instance, this is what Phoenix LiveDashboard reports: ``` Unused indexes detected: 'activities_cc_index', 'activities_hosts', 'activities_in_reply_to', 'activities_local_index', 'activities_to_index', 'aa_users_ap_id_COALESCE_follower_address_index', 'users_featured_address_index', 'users_following_address_index', 'objects_likes', 'activities_likes', 'users_last_status_at_index', 'users_is_suggested_index', 'apps_client_id_client_secret_index', 'users_tags_index', 'users_uri_index', 'users_invisible_index' Null indexes detected: 'users_email_index', 'users_last_active_at_index' Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 20 MB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB' ``` Not listed are indices that have a low hit rate, since I don't really know what's a good threshold for those. Removing unused indices should help with disk space usage and potentially also make write operations faster.
Author
Contributor

Apparently the aa_users_ap_id_COALESCE_follower_address_index does get used a lot more in some other instances, so it would be nice to get more data about indexes on other instances that are unused.

Instance admins can get the same info as above by navigating to $INSTANCE_DOMAIN/phoenix/live_dashboard/ecto_stats. Phoenix LiveDashboard is only accessible to admins.

Apparently the `aa_users_ap_id_COALESCE_follower_address_index` does get used a lot more in some other instances, so it would be nice to get more data about indexes on other instances that are unused. Instance admins can get the same info as above by navigating to `$INSTANCE_DOMAIN/phoenix/live_dashboard/ecto_stats`. Phoenix LiveDashboard is only accessible to admins.
Member

Some more details about those listed above:

Null indices

email and last_active_at are only set for local users, so most entries in those indices are just on NULL values and useless. Turning them into partial indices might save some space and perf overhead, but we should ensure relevant queries then also explicitly set WHERE local = 't' and thus can use the partial index.

Duplicate indices

  • user_frontend_setting_profiles_user_id_frontend_name_profile_na really seems redundant with the (implicitly created) primary-key index; we should be able to just drop this
  • notifications_id_desc_nulls_last_index differs in ordering from the primary-key index; if that ordering is actually used or useful i don’t think this duplication can be avoided
  • data_migration stuff is managed by Ecto; we shouldn’t touch that (downstream; we could send a patch after investigating this more) but it also doesn’t take much space in the first place

Unused indices

Those will need more investigation and ideally stats from several real-world instances. Given we already have an optional migration (adopted from Pleroma?) dropping some of the top activities_ contenders, at least those (and likely more) should be safe to purge

Apparently the aa_users_ap_id_COALESCE_follower_address_index does get used a lot more in some other instances

On my tiny local test instance (which has some manually fetched remote posts), this is the most used index and it does get used during activity. Just starting the server, logging in and loading the timeline added about 50 index scans to it. But, for akko.wtf it doesn't seem to get used at all during normal operation. It also wasn’t used during an earlier index rebuild, so it was at actual zero index accesses.

When it was originally added it was noted to still help during normal operation (on a very large instance), but its main selling point was speeding up restores (from 180h to 2h).
Later the index was renamed in migration 20230127143303 to aa_ because

“restoration apparently happens in alphabetical order, so this new index wasn't created yet by the time activities_visibility_index needed it”

(which seems rather fragile; with -j restore can parallelise index creation and there is no stable order. Even in single-threaded mode, PostgreSQL may decide to change up the order at any time)

Some more details about those listed above: ### Null indices `email` and `last_active_at` are only set for local users, so most entries in those indices are just on `NULL` values and useless. Turning them into partial indices might save some space and perf overhead, but we should ensure relevant queries then also explicitly set `WHERE local = 't'` and thus can use the partial index. ### Duplicate indices - `user_frontend_setting_profiles_user_id_frontend_name_profile_na` really seems redundant with the (implicitly created) primary-key index; we should be able to just drop this - `notifications_id_desc_nulls_last_index` differs in ordering from the primary-key index; if that ordering is actually used or useful i don’t think this duplication can be avoided - `data_migration` stuff is managed by Ecto; we shouldn’t touch that (downstream; we could send a patch after investigating this more) but it also doesn’t take much space in the first place ### Unused indices Those will need more investigation and ideally stats from several real-world instances. Given we already have [an optional migration](https://akkoma.dev/AkkomaGang/akkoma/src/commit/21a81e111165bd29ef953d5e51c682f3dd94dfb4/priv/repo/optional_migrations/20230422154018_drop_unused_indexes.exs) (adopted from Pleroma?) dropping some of the top `activities_` contenders, at least those (and likely more) should be safe to purge </details> > Apparently the `aa_users_ap_id_COALESCE_follower_address_index` does get used a lot more in some other instances On my tiny local test instance (which has some manually fetched remote posts), this is _the_ most used index and it does get used during activity. Just starting the server, logging in and loading the timeline added about 50 index scans to it. But, for akko.wtf it doesn't seem to get used at all during normal operation. It also wasn’t used during an earlier index rebuild, so it was at actual zero index accesses. When it was [originally added](https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3664) it was noted to still help during normal operation (on a very large instance), but its main selling point was speeding up restores (from 180h to 2h). Later the index was renamed in migration `20230127143303` to `aa_` because > “restoration apparently happens in alphabetical order, so this new index wasn't created yet by the time activities_visibility_index needed it” *(which seems rather fragile; with `-j` restore can parallelise index creation and there is no stable order. Even in single-threaded mode, PostgreSQL may decide to change up the order at any time)*

as reported by ihba:

public 	users 	users_last_status_at_index 	211.1 MB 	0
public 	activities 	activities_in_reply_to 	114.7 MB 	0
public 	activities 	activities_cc_index 	111.6 MB 	0
public 	activities 	activities_local_index 	95.6 MB 	0
public 	users 	users_featured_address_index 	62.6 MB 	0
public 	activities 	activities_to_index 	59.0 MB 	0
public 	users 	users_following_address_index 	56.9 MB 	0
public 	objects 	objects_likes 	27.8 MB 	0
public 	users 	users_birthday_month_day_index 	22.4 MB 	0
public 	apps 	apps_client_id_client_secret_index 	22.0 MB 	0
public 	activities 	activities_likes 	21.5 MB 	0
public 	users 	users_is_discoverable_index 	7.2 MB 	0
public 	users 	users_invisible_index 	6.6 MB 	0
public 	oban_jobs 	oban_jobs_queue_state_priority_scheduled_at_id_index_ccnew 	6.6 MB 	0
public 	users 	users_show_birthday_index 	6.5 MB 	0
public 	users 	users_tags_index 	2.9 MB 	0
public 	apps 	apps_user_id_index 	1.2 MB 	0
public 	oban_jobs 	oban_jobs_meta_index_ccnew 	616.0 KB 	0
public 	conversation_participation_recipient_ships 	conversation_participation_recipient_ships_user_id_index 	264.0 KB 	0
public 	oban_jobs 	oban_jobs_meta_index 	200.0 KB 	0
public 	user_frontend_setting_profiles 	user_frontend_setting_profiles_user_id_frontend_name_index 	16.0 KB 	0
public 	activities 	activities_hosts 	90.3 MB 	26
public 	users 	users_is_suggested_index 	6.6 MB 	4 

no major indices unused which is positive

as reported by ihba: ``` public users users_last_status_at_index 211.1 MB 0 public activities activities_in_reply_to 114.7 MB 0 public activities activities_cc_index 111.6 MB 0 public activities activities_local_index 95.6 MB 0 public users users_featured_address_index 62.6 MB 0 public activities activities_to_index 59.0 MB 0 public users users_following_address_index 56.9 MB 0 public objects objects_likes 27.8 MB 0 public users users_birthday_month_day_index 22.4 MB 0 public apps apps_client_id_client_secret_index 22.0 MB 0 public activities activities_likes 21.5 MB 0 public users users_is_discoverable_index 7.2 MB 0 public users users_invisible_index 6.6 MB 0 public oban_jobs oban_jobs_queue_state_priority_scheduled_at_id_index_ccnew 6.6 MB 0 public users users_show_birthday_index 6.5 MB 0 public users users_tags_index 2.9 MB 0 public apps apps_user_id_index 1.2 MB 0 public oban_jobs oban_jobs_meta_index_ccnew 616.0 KB 0 public conversation_participation_recipient_ships conversation_participation_recipient_ships_user_id_index 264.0 KB 0 public oban_jobs oban_jobs_meta_index 200.0 KB 0 public user_frontend_setting_profiles user_frontend_setting_profiles_user_id_frontend_name_index 16.0 KB 0 public activities activities_hosts 90.3 MB 26 public users users_is_suggested_index 6.6 MB 4 ``` no major indices unused which is positive
Contributor

Answering to request from chat. This is for ilja.space

btw for all instance admins here: would be great if you could check the “Unused Index” and/or “Diagnostics” tab in the live dashboard and post the results at: #764

Diagnose
Showing 8 entries
Ok
	Check name 	Message
true 	index_cache_hit 	Index cache hit ratio is correct: 0.98877
true 	bloat 	No bloated tables or indexes detected.
false 	table_cache_hit 	Table cache hit ratio is too low: 0.41182
false 	unused_indexes 	Unused indexes detected: 'activities_visibility_index', 'activities_cc_index', 'users_featured_address_index', 'users_following_address_index', 'activities_to_index', 'activities_hosts', 'oban_jobs_meta_index', 'activities_in_reply_to', 'users_last_status_at_index', 'objects_likes', 'apps_client_id_client_secret_index', 'activities_likes', 'users_is_discoverable_index', 'users_invisible_index', 'users_is_suggested_index', 'users_tags_index', 'activities_local_index'
false 	null_indexes 	Null indexes detected: 'users_email_index', 'users_last_status_at_index', 'users_last_active_at_index'
false 	duplicate_indexes 	Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 648 kB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB'
false 	outliers 	Cannot check outliers because 'pg_stat_statements' extension is not enabled.
false 	ssl_used 	Cannot check connection status because 'sslinfo' extension is not enabled. 
Unused indexes
Showing 22 entries
Schema
	Table 	Index 	Index size 	Index scans
public 	activities 	activities_visibility_index 	44.6 MB 	0
public 	activities 	activities_cc_index 	38.1 MB 	0
public 	users 	users_featured_address_index 	34.6 MB 	0
public 	users 	users_following_address_index 	31.3 MB 	0
public 	activities 	activities_to_index 	18.0 MB 	0
public 	activities 	activities_hosts 	13.9 MB 	0
public 	oban_jobs 	oban_jobs_meta_index 	13.0 MB 	0
public 	activities 	activities_in_reply_to 	12.9 MB 	0
public 	users 	users_last_status_at_index 	7.3 MB 	0
public 	objects 	objects_likes 	5.2 MB 	0
public 	apps 	apps_client_id_client_secret_index 	4.5 MB 	0
public 	activities 	activities_likes 	4.0 MB 	0
public 	users 	users_is_discoverable_index 	3.8 MB 	0
public 	users 	users_invisible_index 	3.8 MB 	0
public 	users 	users_is_suggested_index 	3.8 MB 	0
public 	users 	users_tags_index 	1.3 MB 	0
public 	apps 	apps_user_id_index 	304.0 KB 	0
public 	oban_beats 	oban_beats_inserted_at_index 	96.0 KB 	0
public 	conversation_participation_recipient_ships 	conversation_participation_recipient_ships_user_id_index 	32.0 KB 	0
public 	conversation_participations 	conversation_participations_updated_at_desc_index 	32.0 KB 	0
public 	activities 	activities_local_index 	12.5 MB 	1
public 	conversation_participations 	conversation_participations_conversation_id_index 	32.0 KB 	28 

ideally also mention some server stats for reference (total and monthly active users, server age, subscribed to a relay, ...) (since whether or not an index gets used can depend on the size of involved tables)

Total users 15, 6 monthly active. But really only 1 is very relevant (rest are bots or accounts I only use sporadically). Server is running since 2018, last restore was probably years ago (I don't remember restoring since I switched to Akkoma end of 2022, and I don't know how long it was before then). No relays, I do run the prune task from time to time. Total database size is 13 GB (pg_database_size gives 14491308591).

Answering to request from chat. This is for ilja.space > btw for all instance admins here: would be great if you could check the “Unused Index” and/or “Diagnostics” tab in the live dashboard and post the results at: https://akkoma.dev/AkkomaGang/akkoma/issues/764 ``` Diagnose Showing 8 entries Ok Check name Message true index_cache_hit Index cache hit ratio is correct: 0.98877 true bloat No bloated tables or indexes detected. false table_cache_hit Table cache hit ratio is too low: 0.41182 false unused_indexes Unused indexes detected: 'activities_visibility_index', 'activities_cc_index', 'users_featured_address_index', 'users_following_address_index', 'activities_to_index', 'activities_hosts', 'oban_jobs_meta_index', 'activities_in_reply_to', 'users_last_status_at_index', 'objects_likes', 'apps_client_id_client_secret_index', 'activities_likes', 'users_is_discoverable_index', 'users_invisible_index', 'users_is_suggested_index', 'users_tags_index', 'activities_local_index' false null_indexes Null indexes detected: 'users_email_index', 'users_last_status_at_index', 'users_last_active_at_index' false duplicate_indexes Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 648 kB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB' false outliers Cannot check outliers because 'pg_stat_statements' extension is not enabled. false ssl_used Cannot check connection status because 'sslinfo' extension is not enabled. ``` ``` Unused indexes Showing 22 entries Schema Table Index Index size Index scans public activities activities_visibility_index 44.6 MB 0 public activities activities_cc_index 38.1 MB 0 public users users_featured_address_index 34.6 MB 0 public users users_following_address_index 31.3 MB 0 public activities activities_to_index 18.0 MB 0 public activities activities_hosts 13.9 MB 0 public oban_jobs oban_jobs_meta_index 13.0 MB 0 public activities activities_in_reply_to 12.9 MB 0 public users users_last_status_at_index 7.3 MB 0 public objects objects_likes 5.2 MB 0 public apps apps_client_id_client_secret_index 4.5 MB 0 public activities activities_likes 4.0 MB 0 public users users_is_discoverable_index 3.8 MB 0 public users users_invisible_index 3.8 MB 0 public users users_is_suggested_index 3.8 MB 0 public users users_tags_index 1.3 MB 0 public apps apps_user_id_index 304.0 KB 0 public oban_beats oban_beats_inserted_at_index 96.0 KB 0 public conversation_participation_recipient_ships conversation_participation_recipient_ships_user_id_index 32.0 KB 0 public conversation_participations conversation_participations_updated_at_desc_index 32.0 KB 0 public activities activities_local_index 12.5 MB 1 public conversation_participations conversation_participations_conversation_id_index 32.0 KB 28 ``` > ideally also mention some server stats for reference (total and monthly active users, server age, subscribed to a relay, ...) (since whether or not an index gets used can depend on the size of involved tables) Total users 15, 6 monthly active. But really only 1 is very relevant (rest are bots or accounts I only use sporadically). Server is running since 2018, last restore was probably years ago (I don't remember restoring since I switched to Akkoma end of 2022, and I don't know how long it was before then). No relays, I do run the prune task from time to time. Total database size is 13 GB (`pg_database_size` gives 14491308591).
Member

Forwarding diagnostic info from ikkoma on IRC for a ~6 month old single user instance:

# Unused indexes (as ordered by Ecto diagnostics)
activities_in_reply_to
activities_to_index
activities_cc_index
users_last_status_at_index
activities_likes
users_following_address_index
objects_likes
users_invisible_index
users_tags_index
activities_hosts
users_featured_address_index

Ecto’s diagnostics query (part1, part2) excludes indices which are themselves currently too small or belong to a too small table (reasoning being they might only start to get used once bigger).

This might explain why fewer entries show up here, but will need to check.

Forwarding diagnostic info from ikkoma on IRC for a ~6 month old single user instance: ``` # Unused indexes (as ordered by Ecto diagnostics) activities_in_reply_to activities_to_index activities_cc_index users_last_status_at_index activities_likes users_following_address_index objects_likes users_invisible_index users_tags_index activities_hosts users_featured_address_index ``` Ecto’s diagnostics query ([part1](https://github.com/pawurb/ecto_psql_extras/blob/43df6fcfd22eeb7e917b131ffeca29513dbb830d/lib/ecto_psql_extras/diagnose_logic.ex#L89), [part2](https://github.com/pawurb/ecto_psql_extras/blob/43df6fcfd22eeb7e917b131ffeca29513dbb830d/lib/queries/unused_indexes.ex)) excludes indices which are themselves currently too small or belong to a too small table *(reasoning being they might only start to get used once bigger)*. This might explain why fewer entries show up here, but will need to check.
Member

as reported by ihba:

oban_jobs_queue_state_priority_scheduled_at_id_index_ccnew
oban_jobs_meta_index_ccnew

users_birthday_month_day_index
users_show_birthday_index

_ccnew indices are from a currently running or in the past aborted REINDEX (if the latter they can be safely deleted)

birthday stuff are leftovers from Pleroma and even the table field is never used as it doesn't exist in a clean Akkoma install

> as reported by ihba: ``` oban_jobs_queue_state_priority_scheduled_at_id_index_ccnew oban_jobs_meta_index_ccnew users_birthday_month_day_index users_show_birthday_index ``` `_ccnew` indices are from a currently running or in the past aborted REINDEX (if the latter they can be safely deleted) birthday stuff are leftovers from Pleroma and even the table field is never used as it doesn't exist in a clean Akkoma install
Member

The following weren’t listed above in akko.wtf’s diagnostic query, but they show up in the full output with zero scans:

apps_user_id_index
conversation_participation_recipient_ships_user_id_index
conversation_participations_updated_at_desc_index
user_frontend_setting_profiles_user_id_frontend_name_index

Adding those and filtering out ccnew and pleroma-only indices, aggregating all reports so far gives:

                                         activities_cc_index	4	akko.wtf ihba ikkoma ilja
                                            activities_hosts	4	akko.wtf ihba ikkoma ilja
                                      activities_in_reply_to	4	akko.wtf ihba ikkoma ilja
                                            activities_likes	4	akko.wtf ihba ikkoma ilja
                                         activities_to_index	4	akko.wtf ihba ikkoma ilja
                                               objects_likes	4	akko.wtf ihba ikkoma ilja
                                users_featured_address_index	4	akko.wtf ihba ikkoma ilja
                               users_following_address_index	4	akko.wtf ihba ikkoma ilja
                                       users_invisible_index	4	akko.wtf ihba ikkoma ilja
                                  users_last_status_at_index	4	akko.wtf ihba ikkoma ilja
                                            users_tags_index	4	akko.wtf ihba ikkoma ilja
                                      activities_local_index	3	akko.wtf ihba ilja
                          apps_client_id_client_secret_index	3	akko.wtf ihba ilja
                                          apps_user_id_index	3	akko.wtf ihba ilja
    conversation_participation_recipient_ships_user_id_index	3	akko.wtf ihba ilja
                                    users_is_suggested_index	3	akko.wtf ihba ilja
           conversation_participations_updated_at_desc_index	2	akko.wtf ilja
  user_frontend_setting_profiles_user_id_frontend_name_index	2	akko.wtf ihba
                                 users_is_discoverable_index	2	ihba ilja
              aa_users_ap_id_COALESCE_follower_address_index	1	akko.wtf
                                 activities_visibility_index	1	ilja
           conversation_participations_conversation_id_index	1	ilja
                                             users_uri_index	1	akko.wtf

Note:

  • all 4(+1) indices from the optional migration show up in the "(nearly) unused" output of everyone (but ihba has 26 logged scans for activities_hosts)
    (+1 because the migration also drops activities_actor_index which just doesn't exist in a clean Akkoma install; prob something from Pleroma)
  • further 7 indices are also unused by everyone here
  • the unused user_frontend_setting_profiles_user_id_frontend_name_profile_name is just a duplicate of this table’s primary key index
  • Five more indices occur as rarely used or unused in all reports except ikkoma’s — which might just be because they’re relatively small and thus excluded from reports for ikkoma’s young'ish single user instance. One of them is however useful for some (barely used) functionality.

Grepping and glancing over the code, from the 11 always (nearly) unused indices

  • i only spotted users.invisible actually being used as a selector in queries — but it was always combined with several other conditions (e.g. discoverable or suggested) whose indices gets used instead, so this index doesn't prove useful.
  • afaict last_status_at only occurs for sorting — but the index is neither sorted nor is it likely to help if it was since other selectors are applied before.
  • activities_to could in theory be useful for DM timelines, but clearly it’s not actually used atm (and just for this it would probably better be a partial index or tracked some other way; GIN indices over arrays are relatively expensive)
  • activities_hosts however is actually always used when using the ?instance= parameter of the public federated timeline. The thing is though, akkoma-fe and afaik nothing else either has support for this parameter so it’s probably only used on manual API requests.

For the remaining indices:

  • apps_ (the below show up with 0 scans for all but ikkoma but there are more apps indices; almost certainly just excluded due to small size)
    The OAuth plug fetches apps via its primary key, not sure what else fetches it. Since the index didn’t show up here (nor in unfiltered akko.wtf stats for zero-accesses) at least apps_client_id is apparently used in practice

    • apps_client_id_client_secret_index even if a use case shows up at some point this can already use the more useful apps_client_id_index. Surely a single client won't have so many tokens for an index to be necessary
    • apps_user_id_index no known usage
  • activities_local (all but ikkoma) seems like it should be useful and could be used by ActivityPub.restrict_local/ActivityPub.restrict_remote, but clearly it doesn’t. Maybe because other filters are applied first or maybe because activities_id_desc_nulls_last_local_index gets used instead (multicol B-TREE indices are useful for any subset of their columns, but using leading columns is more efficient)
    (though it is also a bit redundant with activities_hosts albeit somewhat faster for the particular usecase)

  • users_is_suggested (all but ikkoma) is used by the api/v2/suggested MastoAPI you mentioned but probably barely anyone uses this (might actually be cleaner and cheaper to implement as a separate table)

  • conversation_participation* not sure about any of them

  • users_is_discoverable_index (ihba and ilja) seems like it should be used in /api/v1/directory and apparently gets used by akko.wtf and maybe ikkoma; prob better keep or investigate more first

  • activities_visibility_index (ilja) not sure but seems useful everywhere else, so prob best to keep

  • users_uri (akko) will iinm rarely be used in search as most of the time something else hits or the URL gets fetched via HTTP before it hits the index lookup; akko.wtf reindexing recent'ish is prob why there just weren’t yet enough logged scans to pull it out of unused

  • aa_users_ap_id_COALESCE_follower_address_index (akko) no idea why this is unused on akko but it’s clearly beneficial everywhere else (even if a bit hacky; might need to update docs to discourage parellelised restore until (if ever) there’s some better way to deal with this)


tl;dr i think it’s safe to promote and extend the optional migration to drop all except activities_hosts from the 11 everywhere unused indices but add apps_client_id_client_secret_index, apps_user_id_index and the duplicate user_frontend_setting_profiles_user_id_frontend_name_profile_name.

Maybe also some conversations_ indices, but i’m not familiar enough with what those tables are used for and how to make a judgment on them with any degree of confidence.

Possible later follow ups (testing and patches welcome i guess):

  • converting users_email_index to a partial index and if necessary update affected queries
  • replacing is_suggested with a separate table (it’s effectively a null index atm, just with false instead of null)
  • whether or not to keep the ?instance=otp.akkoma.dev feature if it apparently is basically unused but adds bloat for everyone (e.g. with 152MiB it’s the tenth largest index on akko.wtf + ofc the CPU overhead to maintain it)
  • investigate activities_local_index further
    Possibly this could use activities_id_desc_nulls_last_local_index instead (but investigate whether it really makes sense to have sorted ids first). Or if it stays activities_hosts. Also investigate why it is unused for 3/4 instances and if queries can be tweaked to reliably use it or an equivalent (will need extensive testing on large'ish real-world instances)
The following weren’t listed above in akko.wtf’s diagnostic query, but they show up in the full output with zero scans: ``` apps_user_id_index conversation_participation_recipient_ships_user_id_index conversation_participations_updated_at_desc_index user_frontend_setting_profiles_user_id_frontend_name_index ``` Adding those and filtering out `ccnew` and pleroma-only indices, aggregating all reports so far gives: ``` activities_cc_index 4 akko.wtf ihba ikkoma ilja activities_hosts 4 akko.wtf ihba ikkoma ilja activities_in_reply_to 4 akko.wtf ihba ikkoma ilja activities_likes 4 akko.wtf ihba ikkoma ilja activities_to_index 4 akko.wtf ihba ikkoma ilja objects_likes 4 akko.wtf ihba ikkoma ilja users_featured_address_index 4 akko.wtf ihba ikkoma ilja users_following_address_index 4 akko.wtf ihba ikkoma ilja users_invisible_index 4 akko.wtf ihba ikkoma ilja users_last_status_at_index 4 akko.wtf ihba ikkoma ilja users_tags_index 4 akko.wtf ihba ikkoma ilja activities_local_index 3 akko.wtf ihba ilja apps_client_id_client_secret_index 3 akko.wtf ihba ilja apps_user_id_index 3 akko.wtf ihba ilja conversation_participation_recipient_ships_user_id_index 3 akko.wtf ihba ilja users_is_suggested_index 3 akko.wtf ihba ilja conversation_participations_updated_at_desc_index 2 akko.wtf ilja user_frontend_setting_profiles_user_id_frontend_name_index 2 akko.wtf ihba users_is_discoverable_index 2 ihba ilja aa_users_ap_id_COALESCE_follower_address_index 1 akko.wtf activities_visibility_index 1 ilja conversation_participations_conversation_id_index 1 ilja users_uri_index 1 akko.wtf ``` Note: - all 4(+1) indices from the optional migration show up in the "(nearly) unused" output of everyone *(but ihba has 26 logged scans for `activities_hosts`)* *(+1 because the migration also drops `activities_actor_index` which just doesn't exist in a clean Akkoma install; prob something from Pleroma)* - further 7 indices are also unused by everyone here - the unused `user_frontend_setting_profiles_user_id_frontend_name_profile_name` is just a duplicate of this table’s primary key index - Five more indices occur as rarely used or unused in all reports except ikkoma’s — which might just be because they’re relatively small and thus excluded from reports for ikkoma’s young'ish single user instance. One of them is however useful for some (barely used) functionality. Grepping and glancing over the code, from the 11 always (nearly) unused indices - i only spotted `users.invisible` actually being used as a selector in queries — but it was always combined with several other conditions (e.g. `discoverable` or `suggested`) whose indices gets used instead, so this index doesn't prove useful. - afaict `last_status_at` only occurs for sorting — but the index is neither sorted nor is it likely to help if it was since other selectors are applied before. - `activities_to` could in theory be useful for DM timelines, but clearly it’s not actually used atm *(and just for this it would probably better be a partial index or tracked some other way; GIN indices over arrays are relatively expensive)* - `activities_hosts` however is actually always used when using the `?instance=` parameter of the public federated timeline. The thing is though, akkoma-fe and afaik nothing else either has support for this parameter so it’s probably only used on manual API requests. For the remaining indices: - `apps_` *(the below show up with 0 scans for all but ikkoma but there are more apps indices; almost certainly just excluded due to small size)* The OAuth plug fetches apps via its primary key, not sure what else fetches it. Since the index didn’t show up here (nor in unfiltered akko.wtf stats for zero-accesses) at least `apps_client_id` is apparently used in practice - `apps_client_id_client_secret_index` even if a use case shows up at some point this can already use the more useful `apps_client_id_index`. Surely a single client won't have so many tokens for an index to be necessary - `apps_user_id_index` no known usage - `activities_local` *(all but ikkoma)* seems like it _should_ be useful and could be used by `ActivityPub.restrict_local`/`ActivityPub.restrict_remote`, but clearly it doesn’t. Maybe because other filters are applied first or maybe because `activities_id_desc_nulls_last_local_index` gets used instead (multicol B-TREE indices are useful for any subset of their columns, but using leading columns is more efficient) *(though it is also a bit redundant with `activities_hosts` albeit somewhat faster for the particular usecase)* - `users_is_suggested` (all but ikkoma) is used by the api/v2/suggested MastoAPI you mentioned but probably barely anyone uses this *(might actually be cleaner and cheaper to implement as a separate table)* - `conversation_participation*` not sure about any of them - `users_is_discoverable_index` *(ihba and ilja)* seems like it should be used in `/api/v1/directory` and apparently gets used by akko.wtf and maybe ikkoma; prob better keep or investigate more first - `activities_visibility_index` *(ilja)* not sure but seems useful everywhere else, so prob best to keep - `users_uri` *(akko)* will iinm _rarely_ be used in search as most of the time something else hits or the URL gets fetched via HTTP before it hits the index lookup; akko.wtf reindexing recent'ish is prob why there just weren’t yet enough logged scans to pull it out of unused - `aa_users_ap_id_COALESCE_follower_address_index` *(akko)* no idea why this is unused on akko but it’s clearly beneficial everywhere else *(even if a bit hacky; might need to update docs to discourage parellelised restore until (if ever) there’s some better way to deal with this)* ---- tl;dr i think it’s safe to promote and extend the optional migration to drop all except `activities_hosts` from the 11 everywhere unused indices but add `apps_client_id_client_secret_index`, `apps_user_id_index` and the duplicate `user_frontend_setting_profiles_user_id_frontend_name_profile_name`. Maybe also some `conversations_` indices, but i’m not familiar enough with what those tables are used for and how to make a judgment on them with any degree of confidence. Possible later follow ups (testing and patches welcome i guess): - converting `users_email_index` to a partial index and if necessary update affected queries - replacing `is_suggested` with a separate table (it’s effectively a null index atm, just with `false` instead of `null`) - whether or not to keep the `?instance=otp.akkoma.dev` feature if it apparently is basically unused but adds bloat for everyone *(e.g. with 152MiB it’s the tenth largest index on akko.wtf + ofc the CPU overhead to maintain it)* - investigate `activities_local_index` further Possibly this could use `activities_id_desc_nulls_last_local_index` instead (but investigate whether it really makes sense to have sorted ids _first_). Or if it stays `activities_hosts`. Also investigate why it is unused for 3/4 instances and if queries can be tweaked to reliably use it or an equivalent *(will need extensive testing on large'ish real-world instances)*
Author
Contributor

since everyone's been posting their full unused index report, here's mine

public 	activities 	activities_cc_index 	176.3 MB 	0
public 	activities 	activities_in_reply_to 	147.0 MB 	0
public 	activities 	activities_local_index 	145.8 MB 	0
public 	activities 	activities_to_index 	133.2 MB 	0
public 	users 	aa_users_ap_id_COALESCE_follower_address_index 	65.3 MB 	0
public 	users 	users_featured_address_index 	46.9 MB 	0
public 	users 	users_following_address_index 	40.3 MB 	0
public 	activities 	activities_likes 	25.7 MB 	0
public 	objects 	objects_likes 	22.8 MB 	0
public 	users 	users_last_status_at_index 	9.3 MB 	0
public 	apps 	apps_client_id_client_secret_index 	2.6 MB 	0
public 	users 	users_tags_index 	1.5 MB 	0
public 	oban_jobs 	oban_jobs_meta_index 	256.0 KB 	0
public 	instances 	instances_unreachable_since_index 	232.0 KB 	0
public 	apps 	apps_user_id_index 	176.0 KB 	0
public 	conversation_participations 	conversation_participations_updated_at_desc_index 	96.0 KB 	0
public 	conversation_participation_recipient_ships 	conversation_participation_recipient_ships_user_id_index 	96.0 KB 	0
public 	user_frontend_setting_profiles 	user_frontend_setting_profiles_user_id_frontend_name_index 	16.0 KB 	0
public 	activities 	activities_hosts 	149.7 MB 	15
public 	users 	users_is_suggested_index 	4.1 MB 	2
public 	users 	users_uri_index 	31.9 MB 	43
public 	users 	users_invisible_index 	4.2 MB 	10 
since everyone's been posting their full unused index report, here's mine ``` public activities activities_cc_index 176.3 MB 0 public activities activities_in_reply_to 147.0 MB 0 public activities activities_local_index 145.8 MB 0 public activities activities_to_index 133.2 MB 0 public users aa_users_ap_id_COALESCE_follower_address_index 65.3 MB 0 public users users_featured_address_index 46.9 MB 0 public users users_following_address_index 40.3 MB 0 public activities activities_likes 25.7 MB 0 public objects objects_likes 22.8 MB 0 public users users_last_status_at_index 9.3 MB 0 public apps apps_client_id_client_secret_index 2.6 MB 0 public users users_tags_index 1.5 MB 0 public oban_jobs oban_jobs_meta_index 256.0 KB 0 public instances instances_unreachable_since_index 232.0 KB 0 public apps apps_user_id_index 176.0 KB 0 public conversation_participations conversation_participations_updated_at_desc_index 96.0 KB 0 public conversation_participation_recipient_ships conversation_participation_recipient_ships_user_id_index 96.0 KB 0 public user_frontend_setting_profiles user_frontend_setting_profiles_user_id_frontend_name_index 16.0 KB 0 public activities activities_hosts 149.7 MB 15 public users users_is_suggested_index 4.1 MB 2 public users users_uri_index 31.9 MB 43 public users users_invisible_index 4.2 MB 10 ```
Contributor

Since norm asked for it on fedi here are my unsued indexes for akko.lightnovel-dungeon.de, a rather small instance with very few users (its not quite single user) also is fairly new since I recently moved it over to a VPS and started fresh on a new domain.

public 	users 	users_last_status_at_index 	18.5 MB 	0
public 	activities 	activities_cc_index 	16.5 MB 	0
public 	users 	users_following_address_index 	13.6 MB 	0
public 	activities 	activities_to_index 	10.3 MB 	0
public 	activities 	activities_in_reply_to 	9.3 MB 	0
public 	oban_jobs 	oban_jobs_args_index 	4.5 MB 	0
public 	objects 	objects_likes 	3.1 MB 	0
public 	activities 	activities_likes 	2.8 MB 	0
public 	users 	users_tags_index 	648.0 KB 	0
public 	apps 	apps_client_id_client_secret_index 	240.0 KB 	0
public 	oban_jobs 	oban_jobs_meta_index 	96.0 KB 	0
public 	users 	users_featured_address_index 	15.5 MB 	1
public 	users 	users_is_moderator_index 	1.8 MB 	2
public 	users 	users_is_admin_index 	1.7 MB 	2
public 	users 	users_is_suggested_index 	1.8 MB 	5
public 	users 	users_is_discoverable_index 	1.7 MB 	5
public 	activities 	activities_hosts 	9.3 MB 	28
public 	users 	users_invisible_index 	1.8 MB 	14
public 	apps 	apps_user_id_index 	48.0 KB 	1
Since norm asked for it on fedi here are my unsued indexes for akko.lightnovel-dungeon.de, a rather small instance with very few users (its not quite single user) also is fairly new since I recently moved it over to a VPS and started fresh on a new domain. ``` public users users_last_status_at_index 18.5 MB 0 public activities activities_cc_index 16.5 MB 0 public users users_following_address_index 13.6 MB 0 public activities activities_to_index 10.3 MB 0 public activities activities_in_reply_to 9.3 MB 0 public oban_jobs oban_jobs_args_index 4.5 MB 0 public objects objects_likes 3.1 MB 0 public activities activities_likes 2.8 MB 0 public users users_tags_index 648.0 KB 0 public apps apps_client_id_client_secret_index 240.0 KB 0 public oban_jobs oban_jobs_meta_index 96.0 KB 0 public users users_featured_address_index 15.5 MB 1 public users users_is_moderator_index 1.8 MB 2 public users users_is_admin_index 1.7 MB 2 public users users_is_suggested_index 1.8 MB 5 public users users_is_discoverable_index 1.7 MB 5 public activities activities_hosts 9.3 MB 28 public users users_invisible_index 1.8 MB 14 public apps apps_user_id_index 48.0 KB 1 ```

As reported by ak.cute.rest (7 month old single user instance)

public 	objects 	objects_fts 	36.8 MB 	0
public 	users 	aa_users_ap_id_COALESCE_follower_address_index 	17.8 MB 	0
public 	users 	users_featured_address_index 	13.0 MB 	0
public 	users 	users_following_address_index 	11.1 MB 	0
public 	activities 	activities_cc_index 	4.9 MB 	0
public 	users 	users_last_status_at_index 	2.9 MB 	0
public 	activities 	activities_to_index 	2.5 MB 	0
public 	activities 	activities_in_reply_to 	2.0 MB 	0
public 	objects 	objects_likes 	888.0 KB 	0
public 	oban_jobs 	oban_jobs_args_index 	704.0 KB 	0
public 	activities 	activities_likes 	680.0 KB 	0
public 	users 	users_tags_index 	536.0 KB 	0
public 	apps 	apps_client_id_client_secret_index 	256.0 KB 	0
public 	oban_jobs 	oban_jobs_meta_index 	64.0 KB 	0
public 	apps 	apps_user_id_index 	48.0 KB 	0
public 	users 	users_is_suggested_index 	1.3 MB 	1
public 	users 	users_is_moderator_index 	1.4 MB 	2
public 	users 	users_is_admin_index 	1.3 MB 	2
public 	users 	users_invisible_index 	1.3 MB 	5
public 	users 	users_is_active_index 	1.6 MB 	25
As reported by ak.cute.rest (7 month old single user instance) ``` public objects objects_fts 36.8 MB 0 public users aa_users_ap_id_COALESCE_follower_address_index 17.8 MB 0 public users users_featured_address_index 13.0 MB 0 public users users_following_address_index 11.1 MB 0 public activities activities_cc_index 4.9 MB 0 public users users_last_status_at_index 2.9 MB 0 public activities activities_to_index 2.5 MB 0 public activities activities_in_reply_to 2.0 MB 0 public objects objects_likes 888.0 KB 0 public oban_jobs oban_jobs_args_index 704.0 KB 0 public activities activities_likes 680.0 KB 0 public users users_tags_index 536.0 KB 0 public apps apps_client_id_client_secret_index 256.0 KB 0 public oban_jobs oban_jobs_meta_index 64.0 KB 0 public apps apps_user_id_index 48.0 KB 0 public users users_is_suggested_index 1.3 MB 1 public users users_is_moderator_index 1.4 MB 2 public users users_is_admin_index 1.3 MB 2 public users users_invisible_index 1.3 MB 5 public users users_is_active_index 1.6 MB 25 ```

Statistics from social.qunn.eu (two years old instance with 5 MAU)

public	users	users_last_status_at_index	43.9 MB	0
public	activities	activities_cc_index	39.0 MB	0
public	activities	activities_hosts	39.0 MB	0
public	activities	activities_in_reply_to	37.1 MB	0
public	users	users_featured_address_index	36.5 MB	0
public	users	users_following_address_index	31.2 MB	0
public	activities	activities_to_index	29.3 MB	0
public	objects	objects_likes	9.4 MB	0
public	activities	activities_likes	9.1 MB	0
public	users	users_invisible_index	3.3 MB	0
public	users	users_tags_index	1.5 MB	0
public	apps	apps_client_id_client_secret_index	1.1 MB	0
public	oban_jobs	oban_jobs_meta_index	80.0 KB	0
public	activities	activities_visibility_index	157.0 MB	18
public	apps	apps_user_id_index	88.0 KB	1
Statistics from social.qunn.eu (two years old instance with 5 MAU) ``` public users users_last_status_at_index 43.9 MB 0 public activities activities_cc_index 39.0 MB 0 public activities activities_hosts 39.0 MB 0 public activities activities_in_reply_to 37.1 MB 0 public users users_featured_address_index 36.5 MB 0 public users users_following_address_index 31.2 MB 0 public activities activities_to_index 29.3 MB 0 public objects objects_likes 9.4 MB 0 public activities activities_likes 9.1 MB 0 public users users_invisible_index 3.3 MB 0 public users users_tags_index 1.5 MB 0 public apps apps_client_id_client_secret_index 1.1 MB 0 public oban_jobs oban_jobs_meta_index 80.0 KB 0 public activities activities_visibility_index 157.0 MB 18 public apps apps_user_id_index 88.0 KB 1 ```
Contributor

Hi, here are mine. This (SingleUser)Instance is nearly 2 years old:
Unused indexes

public 	users 	users_featured_address_index 	41.8 MB 	0
public 	users 	users_following_address_index 	36.0 MB 	0
public 	activities 	activities_cc_index 	21.7 MB 	0
public 	users 	users_last_status_at_index 	15.2 MB 	0
public 	activities 	activities_to_index 	13.6 MB 	0
public 	activities 	activities_hosts 	12.3 MB 	0
public 	activities 	activities_in_reply_to 	11.1 MB 	0
public 	objects 	objects_likes 	5.8 MB 	0
public 	activities 	activities_likes 	4.3 MB 	0
public 	users 	users_is_discoverable_index 	4.2 MB 	0
public 	users 	users_is_suggested_index 	4.0 MB 	0
public 	users 	users_invisible_index 	4.0 MB 	0
public 	apps 	apps_client_id_client_secret_index 	1.9 MB 	0
public 	users 	users_tags_index 	1.7 MB 	0
public 	oban_jobs 	oban_jobs_meta_index 	104.0 KB 	0
public 	activities 	activities_visibility_index 	50.7 MB 	2
public 	activities 	activities_local_index 	11.1 MB 	1
public 	apps 	apps_user_id_index 	136.0 KB 	1 

Null indexes

99371 	apps_user_id_index 	136 kB 	false 	user_id 	99.99% 	136 kB
99398 	instances_unreachable_since_index 	160 kB 	false 	unreachable_since 	99.28% 	159 kB
99411 	oauth_tokens_user_id_index 	192 kB 	false 	user_id 	99.96% 	192 kB
99473 	users_email_index 	13 MB 	true 	email 	100.00% 	13 MB
99474 	users_featured_address_index 	42 MB 	false 	featured_address 	2.88% 	1231 kB
99475 	users_follower_address_index 	35 MB 	false 	follower_address 	1.81% 	640 kB
99476 	users_following_address_index 	36 MB 	false 	following_address 	1.94% 	716 kB
99484 	users_last_active_at_index 	4120 kB 	false 	last_active_at 	100.00% 	4120 kB
99485 	users_last_status_at_index 	15 MB 	false 	last_status_at 	60.83% 	9494 kB
99487 	users_nickname_index 	23 MB 	true 	nickname 	.01% 	1591 bytes
99489 	users_uri_index 	29 MB 	false 	uri 	.13% 	37 kB 

Duplicate indexes

16 kB 	data_migration_failed_ids_pkey 	data_migration_failed_ids_data_migration_id_record_id_index 		
32 kB 	user_frontend_setting_profiles_pkey 	user_frontend_setting_profiles_user_id_frontend_name_profile_na
536 kB 	notifications_pkey 	notifications_id_desc_nulls_last_index 
Hi, here are mine. This (SingleUser)Instance is nearly 2 years old: **Unused indexes** ``` public users users_featured_address_index 41.8 MB 0 public users users_following_address_index 36.0 MB 0 public activities activities_cc_index 21.7 MB 0 public users users_last_status_at_index 15.2 MB 0 public activities activities_to_index 13.6 MB 0 public activities activities_hosts 12.3 MB 0 public activities activities_in_reply_to 11.1 MB 0 public objects objects_likes 5.8 MB 0 public activities activities_likes 4.3 MB 0 public users users_is_discoverable_index 4.2 MB 0 public users users_is_suggested_index 4.0 MB 0 public users users_invisible_index 4.0 MB 0 public apps apps_client_id_client_secret_index 1.9 MB 0 public users users_tags_index 1.7 MB 0 public oban_jobs oban_jobs_meta_index 104.0 KB 0 public activities activities_visibility_index 50.7 MB 2 public activities activities_local_index 11.1 MB 1 public apps apps_user_id_index 136.0 KB 1 ``` **Null indexes** ``` 99371 apps_user_id_index 136 kB false user_id 99.99% 136 kB 99398 instances_unreachable_since_index 160 kB false unreachable_since 99.28% 159 kB 99411 oauth_tokens_user_id_index 192 kB false user_id 99.96% 192 kB 99473 users_email_index 13 MB true email 100.00% 13 MB 99474 users_featured_address_index 42 MB false featured_address 2.88% 1231 kB 99475 users_follower_address_index 35 MB false follower_address 1.81% 640 kB 99476 users_following_address_index 36 MB false following_address 1.94% 716 kB 99484 users_last_active_at_index 4120 kB false last_active_at 100.00% 4120 kB 99485 users_last_status_at_index 15 MB false last_status_at 60.83% 9494 kB 99487 users_nickname_index 23 MB true nickname .01% 1591 bytes 99489 users_uri_index 29 MB false uri .13% 37 kB ``` **Duplicate indexes** ``` 16 kB data_migration_failed_ids_pkey data_migration_failed_ids_data_migration_id_record_id_index 32 kB user_frontend_setting_profiles_pkey user_frontend_setting_profiles_user_id_frontend_name_profile_na 536 kB notifications_pkey notifications_id_desc_nulls_last_index ```

This is from miku.place (around 8 users, running since August of 2023)

Unused indexes:

Schema
	Table 	Index 	Index size 	Index scans
public 	activities 	activities_cc_index 	26.6 MB 	0
public 	users 	users_featured_address_index 	25.8 MB 	0
public 	oban_jobs 	oban_jobs_args_index 	23.0 MB 	0
public 	users 	users_following_address_index 	22.2 MB 	0
public 	activities 	activities_to_index 	21.4 MB 	0
public 	activities 	activities_in_reply_to 	21.1 MB 	0
public 	users 	users_last_status_at_index 	19.4 MB 	0
public 	apps 	apps_client_id_client_secret_index 	17.6 MB 	0
public 	objects 	objects_likes 	9.2 MB 	0
public 	activities 	activities_likes 	7.1 MB 	0
public 	users 	users_invisible_index 	2.2 MB 	0
public 	users 	users_is_suggested_index 	2.2 MB 	0
public 	users 	users_tags_index 	1.1 MB 	0
public 	apps 	apps_user_id_index 	800.0 KB 	0
public 	oban_jobs 	oban_jobs_meta_index 	104.0 KB 	0
public 	activities 	activities_hosts 	23.2 MB 	2 

Null indexes:

Oid
	Index 	Index size 	Unique 	Indexed column 	Null frac 	Expected saving
16652 	users_email_index 	7400 kB 	true 	email 	100.00% 	7400 kB
16743 	users_follower_address_index 	21 MB 	false 	follower_address 	3.78% 	797 kB
16972 	instances_unreachable_since_index 	144 kB 	false 	unreachable_since 	99.78% 	144 kB
17033 	oauth_tokens_user_id_index 	800 kB 	false 	user_id 	99.97% 	800 kB
17127 	users_following_address_index 	22 MB 	false 	following_address 	3.93% 	895 kB
17516 	users_uri_index 	18 MB 	false 	uri 	.18% 	33 kB
17573 	users_last_active_at_index 	2272 kB 	false 	last_active_at 	100.00% 	2272 kB
17574 	users_featured_address_index 	26 MB 	false 	featured_address 	4.87% 	1287 kB
17592 	apps_user_id_index 	800 kB 	false 	user_id 	99.99% 	800 kB
17614 	users_last_status_at_index 	19 MB 	false 	last_status_at 	54.24% 	11 MB 

Duplicate indexes:

Size
	Idx1 	Idx2 	Idx3 	Idx4
16 kB 	data_migration_failed_ids_pkey 	data_migration_failed_ids_data_migration_id_record_id_index 		
32 kB 	user_frontend_setting_profiles_pkey 	user_frontend_setting_profiles_user_id_frontend_name_profile_na 		
760 kB 	notifications_pkey 	notifications_id_desc_nulls_last_index 
This is from miku.place (around 8 users, running since August of 2023) Unused indexes: ``` Schema Table Index Index size Index scans public activities activities_cc_index 26.6 MB 0 public users users_featured_address_index 25.8 MB 0 public oban_jobs oban_jobs_args_index 23.0 MB 0 public users users_following_address_index 22.2 MB 0 public activities activities_to_index 21.4 MB 0 public activities activities_in_reply_to 21.1 MB 0 public users users_last_status_at_index 19.4 MB 0 public apps apps_client_id_client_secret_index 17.6 MB 0 public objects objects_likes 9.2 MB 0 public activities activities_likes 7.1 MB 0 public users users_invisible_index 2.2 MB 0 public users users_is_suggested_index 2.2 MB 0 public users users_tags_index 1.1 MB 0 public apps apps_user_id_index 800.0 KB 0 public oban_jobs oban_jobs_meta_index 104.0 KB 0 public activities activities_hosts 23.2 MB 2 ``` Null indexes: ``` Oid Index Index size Unique Indexed column Null frac Expected saving 16652 users_email_index 7400 kB true email 100.00% 7400 kB 16743 users_follower_address_index 21 MB false follower_address 3.78% 797 kB 16972 instances_unreachable_since_index 144 kB false unreachable_since 99.78% 144 kB 17033 oauth_tokens_user_id_index 800 kB false user_id 99.97% 800 kB 17127 users_following_address_index 22 MB false following_address 3.93% 895 kB 17516 users_uri_index 18 MB false uri .18% 33 kB 17573 users_last_active_at_index 2272 kB false last_active_at 100.00% 2272 kB 17574 users_featured_address_index 26 MB false featured_address 4.87% 1287 kB 17592 apps_user_id_index 800 kB false user_id 99.99% 800 kB 17614 users_last_status_at_index 19 MB false last_status_at 54.24% 11 MB ``` Duplicate indexes: ``` Size Idx1 Idx2 Idx3 Idx4 16 kB data_migration_failed_ids_pkey data_migration_failed_ids_data_migration_id_record_id_index 32 kB user_frontend_setting_profiles_pkey user_frontend_setting_profiles_user_id_frontend_name_profile_na 760 kB notifications_pkey notifications_id_desc_nulls_last_index ```
Contributor

Here are girlth.ing's statistics (mostly single user)

 Unused indexes detected: 'activities_cc_index', 'users_last_status_at_index', 'users_following_address_index', 'activities_to_index', 'activities_in_reply_to', 'activities_hosts', 'objects_likes', 'activities_likes', 'users_invisible_index', 'users_is_suggested_index', 'users_featured_address_index', 'users_is_moderator_index', 'users_is_admin_index' 
 Null indexes detected: 'users_email_index' 
 Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 32 kB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB' 
Here are `girlth.ing`'s statistics (mostly single user) ``` Unused indexes detected: 'activities_cc_index', 'users_last_status_at_index', 'users_following_address_index', 'activities_to_index', 'activities_in_reply_to', 'activities_hosts', 'objects_likes', 'activities_likes', 'users_invisible_index', 'users_is_suggested_index', 'users_featured_address_index', 'users_is_moderator_index', 'users_is_admin_index' Null indexes detected: 'users_email_index' Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 32 kB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB' ```
Member

thanks everyone! i’ll reaggregate and check if anything unexpected shows up later

@tea your data is the only one where activities_hosts is not nearly unused. Do you use or used a frontend or app which actually supports instance-specific federated timelines (which one)?

full unused index report

note, the full report has a higher scan limit than the diagnostic output and does not filter out indices ≤1MB, but it still contains the hardcoded filter for table whose pure data is ≤40KiB. In practice this probably at most affects apps and maybe conversation_* related indices on small instances, basically never the main activities and objects offenders.

thanks everyone! i’ll reaggregate and check if anything unexpected shows up later @tea your data is the only one where `activities_hosts` is not nearly unused. Do you use or used a frontend or app which actually supports instance-specific federated timelines (which one)? > full unused index report note, the full report has a higher scan limit than the diagnostic output and does not filter out indices ≤1MB, but it still contains the hardcoded filter for table whose pure data is ≤40KiB. In practice this probably at most affects `apps` and maybe `conversation_*` related indices on small instances, basically never the main `activities` and `objects` offenders.

Good question, the index also only has a size of 2.7 MB.
I currently use Moshidon but I've tried too many apps to remember…

Good question, the index also only has a size of 2.7 MB. I currently use Moshidon but I've tried too many apps to remember…
Oneric referenced this issue from a commit 2024-05-02 00:39:55 +00:00
Oneric referenced this issue from a commit 2024-05-02 00:41:12 +00:00
Oneric referenced this issue from a commit 2024-05-02 00:43:55 +00:00
Oneric referenced this issue from a commit 2024-05-02 00:47:00 +00:00
Member

Without instances names since otherwise Forgejo’s soft line wrapping impedes readability (full data further below):

                                         activities_cc_index	10
                                      activities_in_reply_to	10
                                            activities_likes	10
                                         activities_to_index	10
                                               objects_likes	10
                                users_featured_address_index	10
                               users_following_address_index	10
                                       users_invisible_index	10
                                  users_last_status_at_index	10
                                            activities_hosts	9
                                            users_tags_index	9
                          apps_client_id_client_secret_index	8
                                          apps_user_id_index	8
                                    users_is_suggested_index	8
                                      activities_local_index	4
                                 users_is_discoverable_index	4
                                 activities_visibility_index	3
    conversation_participation_recipient_ships_user_id_index	3
                                        users_is_admin_index	3
                                    users_is_moderator_index	3
              aa_users_ap_id_COALESCE_follower_address_index	2
           conversation_participations_updated_at_desc_index	2
  user_frontend_setting_profiles_user_id_frontend_name_index	2
           conversation_participations_conversation_id_index	1
                                                 objects_fts	1
                                       users_is_active_index	1
                                             users_uri_index	1

Full stats with instance names
                                         activities_cc_index	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                      activities_in_reply_to	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                            activities_likes	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                         activities_to_index	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                               objects_likes	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                users_featured_address_index	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                               users_following_address_index	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                       users_invisible_index	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                  users_last_status_at_index	10	akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                            activities_hosts	9	akko.wtf girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick
                                            users_tags_index	9	akko.wtf cute ihba ikkoma ilja lndungeon miku.place qunn yokairick
                          apps_client_id_client_secret_index	8	akko.wtf cute ihba ilja lndungeon miku.place qunn yokairick
                                          apps_user_id_index	8	akko.wtf cute ihba ilja lndungeon miku.place qunn yokairick
                                    users_is_suggested_index	8	akko.wtf cute girlthing ihba ilja lndungeon miku.place yokairick
                                      activities_local_index	4	akko.wtf ihba ilja yokairick
                                 users_is_discoverable_index	4	ihba ilja lndungeon yokairick
                                 activities_visibility_index	3	ilja qunn yokairick
    conversation_participation_recipient_ships_user_id_index	3	akko.wtf ihba ilja
                                        users_is_admin_index	3	cute girlthing lndungeon
                                    users_is_moderator_index	3	cute girlthing lndungeon
              aa_users_ap_id_COALESCE_follower_address_index	2	akko.wtf cute
           conversation_participations_updated_at_desc_index	2	akko.wtf ilja
  user_frontend_setting_profiles_user_id_frontend_name_index	2	akko.wtf ihba
           conversation_participations_conversation_id_index	1	ilja
                                                 objects_fts	1	cute
                                       users_is_active_index	1	cute
                                             users_uri_index	1	akko.wtf

The "everywhere unused" indices are basically still the same except for activities_hosts (which will be kept anyway) and users_tags not being listed for girlth.ing; due to instance size+age and this index being close to 1MiB for other small instances, i suspect it was just cut by the 1MiB index limit from the diagnostic summary.
The two apps indices scheduled for removal are also only missing for girlth.ing and ikkoma, both of which likely just hot size filters in the diagnostic output (only the diagnostic summary was provided). Where more detail was provided the only uses were a single access of apps_user_id_index for yokairick, lightnovel-dungeon.de and qunn.eu each.

There’s also a clear cut between "user_is_suggested + the 13 to-be-dropped indices" and all other indices by going from being reported on 8/10 instances to 4/10.

So this confirmed previous results (thx) and i think it’s safe to go ahead with the 13 trivial drops and opened a PR: #767.
Possible later followups to clean up even more (but requiring some effort) is still the same as before but (i now fixed an inconsistency where the followup list was referring to an activites_local removal eventhough this wasn't planned anymore already and) additionally i think, since activities_hosts is only used for querying remote local timelines; if we keep this feature we should still be able to reduce overhead by turning it into a partial index on data->>'type' = 'Create'.

Possible later follow ups (testing and patches welcome i guess):

  • converting users_email_index to a partial index and if necessary update affected queries
  • replacing is_suggested with a separate table (it’s effectively a null index atm, just with false instead of null)
  • whether or not to keep the ?instance=otp.akkoma.dev feature if it apparently is basically unused but adds bloat for everyone (e.g. with 152MiB it’s the tenth largest index on akko.wtf + ofc the CPU overhead to maintain it)
  • ofc the CPU overhead to maintain it)*
  • investigate activities_local_index further
    Possibly this could use activities_id_desc_nulls_last_local_index instead (but investigate whether it really makes sense to have sorted ids first). Or if it stays activities_hosts. Also investigate why it is unused for 3/4 instances and if queries can be tweaked to reliably use it or an equivalent (will need extensive testing on large'ish real-world instances)

(and look into whether we actually need the ordering for the otherwise duplicated notifications_id_desc_nulls_last_index)


I currently use Moshidon but I've tried too many apps to remember…

welp, guess some more research is needed then to decide what to do with ?instance=. And to avoid possible confusion later: Moshidon has a feature for adding public timelines of remote servers, but afaict it doesn’t use the *oma specific ?instance= to query it from the homeserver, but directly polls the remote target server. (which allows it to work with Mastodon home servers)

Without instances names since otherwise Forgejo’s soft line wrapping impedes readability *(full data further below)*: ``` activities_cc_index 10 activities_in_reply_to 10 activities_likes 10 activities_to_index 10 objects_likes 10 users_featured_address_index 10 users_following_address_index 10 users_invisible_index 10 users_last_status_at_index 10 activities_hosts 9 users_tags_index 9 apps_client_id_client_secret_index 8 apps_user_id_index 8 users_is_suggested_index 8 activities_local_index 4 users_is_discoverable_index 4 activities_visibility_index 3 conversation_participation_recipient_ships_user_id_index 3 users_is_admin_index 3 users_is_moderator_index 3 aa_users_ap_id_COALESCE_follower_address_index 2 conversation_participations_updated_at_desc_index 2 user_frontend_setting_profiles_user_id_frontend_name_index 2 conversation_participations_conversation_id_index 1 objects_fts 1 users_is_active_index 1 users_uri_index 1 ``` <details> <summary>Full stats with instance names</summary> ``` activities_cc_index 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick activities_in_reply_to 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick activities_likes 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick activities_to_index 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick objects_likes 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick users_featured_address_index 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick users_following_address_index 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick users_invisible_index 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick users_last_status_at_index 10 akko.wtf cute girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick activities_hosts 9 akko.wtf girlthing ihba ikkoma ilja lndungeon miku.place qunn yokairick users_tags_index 9 akko.wtf cute ihba ikkoma ilja lndungeon miku.place qunn yokairick apps_client_id_client_secret_index 8 akko.wtf cute ihba ilja lndungeon miku.place qunn yokairick apps_user_id_index 8 akko.wtf cute ihba ilja lndungeon miku.place qunn yokairick users_is_suggested_index 8 akko.wtf cute girlthing ihba ilja lndungeon miku.place yokairick activities_local_index 4 akko.wtf ihba ilja yokairick users_is_discoverable_index 4 ihba ilja lndungeon yokairick activities_visibility_index 3 ilja qunn yokairick conversation_participation_recipient_ships_user_id_index 3 akko.wtf ihba ilja users_is_admin_index 3 cute girlthing lndungeon users_is_moderator_index 3 cute girlthing lndungeon aa_users_ap_id_COALESCE_follower_address_index 2 akko.wtf cute conversation_participations_updated_at_desc_index 2 akko.wtf ilja user_frontend_setting_profiles_user_id_frontend_name_index 2 akko.wtf ihba conversation_participations_conversation_id_index 1 ilja objects_fts 1 cute users_is_active_index 1 cute users_uri_index 1 akko.wtf ``` </details> The "everywhere unused" indices are basically still the same except for `activities_hosts` (which will be kept anyway) and `users_tags` not being listed for `girlth.ing`; due to instance size+age and this index being close to 1MiB for other small instances, i suspect it was just cut by the 1MiB index limit from the diagnostic summary. The two apps indices scheduled for removal are also only missing for `girlth.ing` and ikkoma, both of which likely just hot size filters in the diagnostic output (only the diagnostic summary was provided). Where more detail was provided the only uses were a single access of `apps_user_id_index` for yokairick, lightnovel-dungeon.de and qunn.eu each. There’s also a clear cut between "`user_is_suggested` + the 13 to-be-dropped indices" and all other indices by going from being reported on 8/10 instances to 4/10. So this confirmed previous results (thx) and i think it’s safe to go ahead with the 13 trivial drops and opened a PR: #767. Possible later followups to clean up even more (but requiring some effort) is still the same [as before](https://akkoma.dev/AkkomaGang/akkoma/issues/764#issuecomment-11906) but *(i now fixed an inconsistency where the followup list was referring to an `activites_local` removal eventhough this wasn't planned anymore already and)* additionally i think, since `activities_hosts` is only used for querying remote local timelines; if we keep this feature we should still be able to reduce overhead by turning it into a partial index on `data->>'type' = 'Create'`. > Possible later follow ups (testing and patches welcome i guess): > - converting `users_email_index` to a partial index and if necessary update affected queries > - replacing `is_suggested` with a separate table (it’s effectively a null index atm, just with `false` instead of `null`) > - whether or not to keep the `?instance=otp.akkoma.dev` feature if it apparently is basically unused but adds bloat for everyone *(e.g. with 152MiB it’s the tenth largest index on akko.wtf + ofc the CPU overhead to maintain it)* > - ofc the CPU overhead to maintain it)* > - investigate `activities_local_index` further > Possibly this could use `activities_id_desc_nulls_last_local_index` instead (but investigate whether it really makes sense to have sorted ids _first_). Or if it stays `activities_hosts`. Also investigate why it is unused for 3/4 instances and if queries can be tweaked to reliably use it or an equivalent *(will need extensive testing on large'ish real-world instances)* (and look into whether we actually need the ordering for the otherwise duplicated `notifications_id_desc_nulls_last_index`) --- > I currently use Moshidon but I've tried too many apps to remember… welp, guess some more research is needed then to decide what to do with `?instance=`. And to avoid possible confusion later: Moshidon has a feature for adding public timelines of remote servers, but afaict it doesn’t use the \*oma specific `?instance=` to query it from the homeserver, but directly polls the remote target server. (which allows it to work with Mastodon home servers)
Oneric referenced this issue from a commit 2024-05-03 05:30:27 +00:00
Oneric referenced this issue from a commit 2024-05-03 05:31:30 +00:00

Not sure if still needed, but here are mine from junimo.party:

Unused indexes detected: 'users_last_status_at_index', 'activities_cc_index', 'activities_in_reply_to', 'activities_to_index', 'oban_jobs_args_index', 'users_following_address_index', 'objects_likes', 'activities_likes', 'users_invisible_index', 'users_is_discoverable_index', 'users_featured_address_index', 'activities_hosts', 'users_is_suggested_index' 
Null indexes detected: 'users_email_index', 'users_last_active_at_index' 
Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 416 kB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB' 

Oh, also, I might still be a version behind...

Not sure if still needed, but here are mine from junimo.party: ``` Unused indexes detected: 'users_last_status_at_index', 'activities_cc_index', 'activities_in_reply_to', 'activities_to_index', 'oban_jobs_args_index', 'users_following_address_index', 'objects_likes', 'activities_likes', 'users_invisible_index', 'users_is_discoverable_index', 'users_featured_address_index', 'activities_hosts', 'users_is_suggested_index' ``` ``` Null indexes detected: 'users_email_index', 'users_last_active_at_index' ``` ``` Duplicate indexes detected: 'notifications_pkey' - 'notifications_id_desc_nulls_last_index' size 416 kB', 'user_frontend_setting_profiles_pkey' - 'user_frontend_setting_profiles_user_id_frontend_name_profile_na' size 32 kB', 'data_migration_failed_ids_pkey' - 'data_migration_failed_ids_data_migration_id_record_id_index' size 16 kB' ``` Oh, also, I might still be a version behind...
Member

This fits well with the other results, thanks!

This fits well with the other results, thanks!
Sign in to join this conversation.
No Milestone
No project
No Assignees
11 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: AkkomaGang/akkoma#764
No description provided.