2 Replies Latest reply on Oct 9, 2015 6:20 AM by user375

    PHP Performance: getRelatedSet() vs 2nd Query

    user375

      When I want to pull records from one table as well as related records from another table on the same PHP page, is it better to do that as 2 separate queries using 2 separate layouts, or with a portal on a single layout and use getRelatedSet() instead? What is the preferred method in terms of speed and minimizing database load? Thanks.

        • 1. Re: PHP Performance: getRelatedSet() vs 2nd Query
          Mike Duncan

          This is going to depend, in part, on the amount of records that you anticipate getting returned. The bottleneck is likely the verbose xml returned for a large amount of records from portal rows in addition to parent records. Keeping in mind that for every record found, all portal rows for each of those found get included automatically as well, including every field on the layout.

           

          If the record count is reasonable, it can be good to leverage the relationship to return related records. As the record count or number of fields needed goes up, I would consider making 2 separate queries.

           

          Mike

          • 2. Re: PHP Performance: getRelatedSet() vs 2nd Query
            user375

            Thanks Mike, I always try to limit my layouts and portals to only those fields that I will publish online. It is a good point however that ALL portal rows will be pulled by getRelatedSet, where that may not be what is always intended. In those cases where I want ALL portal rows anyway, my assumption is the getRelatedSet will be a little more efficient than a 2nd data query, one database hit being better than two, but I don't have any evidence of the real difference. If there is no discernable difference in performance, the getRelatedSet is at least a little easier to code with IMO.