Allow the ability to use Tenant_ID in SQL indexes
712
Views
2
Comments
New
Database

Currently when you are using a multi tenant entity Outsystems automatically adds the tenant_id to the end of any user index that it creates. This however is not always the best ordering for an index.

For example if you have a DateTime field in an index the actual created index would be [StartDateTime],[Tenant_ID]. In this scenario SQL would first have to search though the StartDateTime order across all tenants and then the Tenant_ID. The more efficient ordering would be [Tenant_ID],[StartDateTime] which would allow SQL to pre filter out all other tenants and then just filter through what’s left in the StartDateTime index.

Of cause this won't be the best case for ALL index's, for example [isActive],[Tenant_ID] is probably a perfectly valid order as SQL could pre filter out ½ the data quickly and then filter down the tenant.

So what I would like to see is that when creating an index for a multi tenant entity is to have Tenant_ID show as one of the available index fields which will allow the developer to choose. If you wanted to ensure that Tenant_ID was always used somewhere then you could make it compulsory to have it at some point in the index field list but just allow the dev to control the order.



To give a bit more of an example for the use case. The below screenshot was actually provided by Outsystems support showing an SQL query plan advice to add an index of [Tenant_ID],[ENDDATETIME] which is currently not actually possible with the way indexes are created on an Entity.

I already asked this in https://www.outsystems.com/forums/discussion/54210/why-is-tenant-id-the-last-field-in-the-fysically-generated-index/ .

In my opinion the tenant_ID should always be the first field in the index, because it's always there.


The only way to implement this at this moment is to check 'Show Tenant Identifier' in the advanced tab of the entity (and only in the module where the entity is defined). Now it's possible to create the index yourself. 

Changed the category to
Database