Help with index / speed up database query

Hey guys, just started to learn about database indexes, and it looks awesome to speed up db queries! I'm just not sure how to use them in my case, or if there's another way to improve my query's performance.

My main database is called Accounts, which is basically just a user database. My queries are pretty simple, most of the time I just check a condition to verify the "Account_Type" field. I've setup a normal index for this field, which helps greatly as expected.

The issue in speed I'm experiencing comes from an add-on I added to the output of my "Query all records" function. The add-on is enriching data of a field "following_accounts_id", which is using a Table Reference type of the the same main Accounts database. Basically this field is adding information about other accounts connected to "$this" account.

Without the add-on, the "following_accounts_id" is just a list of Accounts ids, the add-on is taking the IDs and adding more data such as the Account name, image, description, etc.


Here's the Add-on, which is really straightforward, simply matching the Account id to $this id.



Without the add-on my query takes about 0.2s, and with the add-on it's often more than 1s.

So far I've only added 1 normal index to my Account_Type field, now I'm wondering how to optimize the following_accounts_id field for faster queries.

Appreciate any help, thanks!

1 reply