Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-1279

Search performance slow with many contacts

    Details

    • Type: Improvement
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Labels:
      None

      Description

      The search query builder uses some terrible operations that will never scale:

      1. Using LOWER() on every name. This immediately drops search performance from O(log(N)) to O(N). LOWER is also redundant when using a LIKE match.
      2. Prefixing a wildcard to the search criteria. This also drops search performance to O(N).

      I've modified the search file /CRM/Contact/BAO/Query.php (attached) for drastic performance increases. Perhaps CiviCRM could at least offer an option to run in a large dataset mode.

      All my changes are in the sortName function.

      I did a few key things:
      1. Removed LOWER from the lefthand side of the LIKE clause
      2. Removed the '%' prefixed to the search
      3. Only activated email search if the criteria contain a '@'

      Now MySQL can use an index. This bumps performance back to around O(log(N)), which is important because we have about 150,000 contacts.

        Attachments

          Activity

            People

            • Assignee:
              sameermare Sameer Mare
              Reporter:
              davidstrauss David Strauss
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1 hour
                1h
                Remaining:
                Remaining Estimate - 1 hour
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified