Like the Comment of a Post

@cmarchan I think @TipLister is providing the same advice you have in the past. I do remember there was a thread we were both part of not too long ago, in which I indicated I’d reach out to Bubble support to get an answer to the question in order to put it to rest. In that thread I posted what Bubble support responded. I will do so here as well. I believe Sergey provided a very insightful post in that thread as well showing actual numbers to back up the concept.

Firstly, the below is the question I posed to Bubble support.

In terms of the amount of data being returned and the potential impacts on the speed of that data retrieval, when a data type that is being searched has related fields on it that relate to other data types, are all of the fields of the related data types being returned and in essence adding to the data ‘load’ which would result in a slower response if compared to simply saving the unique ID of the related data type as a field?

For example, if I have a data type of User and I have a field that is related to a data type of House and the house data type has multiple fields on it, would the search and return of the results be any slower than if I instead on the User data type had a field that was a text field storing the unique ID of the House data type.

Below is the response from Bubble

Thank you very much for your email, that’s a great question! I was able to speak to one of our engineers about this who let me know that we already store the related data type as its unique ID, so making it a text field wouldn’t improve performance.

We only retrieve the nested thing if there are any fields in the nested data type that are being used. So in this example, if there is a text box that says “User’s first name”, we would retrieve the User object only. If it says “User’s House’s address”, then we would retrieve both the User and House object.

So it seems it is not the case that when you have a related type as field that all of the fields of that related type are returned, but it is the case that it is returning only the unique ID of that related type. However, once you request that related type, all the fields are returned. That is basically what Bubble support stated as well as Sergey who provided some insights from browser console with numbers to exemplify how it is working.

So, @ahmed.khodeir.87 consider the insights from Bubble support as omniscient since it is coming ‘from the horses mouth’.

Also, something to consider, every single data type you create has a built in field of ‘Creator’ which is related to the User data type. Bubble is relating to a data type, and not just a text field as a unique ID. I would suspect Bubble would have carefully weighed and considered the option between both approaches, and if it were in fact true that simply having that relation to the actual type caused all fields to be loaded regardless, that they likely wouldn’t have done that since it would have significant performance implications for every app.

Additionally, as Bubble is expressing that moving forward they will continue to focus on improving performance, and one of the ways in which they intend to do so is to expand the cache of data, that using the related type approach is going to continue to be the optimized way of structuring your database.

Consider a hypothetical as well. In the event that you have a data type called ‘Car’ and another called ‘Car Specs’ in which the ‘Car Specs’ has 100 fields on it and the ‘Car’ data type has a field related to ‘Car Specs’, and in the event you want to show a user a repeating group of all cars and perhaps one value from the Car Specs data type, if you have it related, you would in fact be loading all of the 100 fields from Car Specs just to show the one field you want to. So, in this case, it might be wise to put onto the Car data type a field that is a text value that is the single field from Car Specs you wish to show.

Alternatively, doing a related field as a text being the unique ID of car specs, in that repeating group you would need to ‘do a search for car specs’ constrain by the unique id field in the car data type and in the hypothetical of it being in a repeating group, say with 20 cells, you will be performing 20 simultaneous searches (not optimal) and in the results all 100 fields from car specs would be returned from the searches.

You are not getting it wrong. That is what Bubble does.

7 Likes