SOSL vs. SOQL

Curiosity got the best of me, and I decided to run a rudimentary benchmark against a small data set, using both SOSL and SOQL for search. Results below.

First, to run the benchmark, I fired up a fresh dev org and loaded as many records as I could. With a standard dev org and the import schema below, that meant 14,100 account records.

In order to have something to search against, I uploaded just a single field; an incrementing name field.

Testing this in the system log provided the following results.

SOSL Test
List searchList = [find '%99%' in name fields returning Account(Name)];

SOQL Test
List searchList = [select Id from Account where Name like '%99%'];

Findings/Case for SOSL
SOSL came in at 32ms, while SOQL was a full 22% slower at 39ms. Obviously, this was a small data set, but gives you a sense for how SOSL may scale at larger volumes.

Additionally, SOSL has the ability to easy search across all fields, and include multiple objects in the data set, while SOQL would require multiple queries or an object relationship to accomplish the same thing.

SOQL is going to be the stronger general use query tool, but for straight-up search it’s hard to ignore the benefits of SOSL. That is what it was designed for, after all.

What do you think? Thoughts/experiences with SOSL vs. SOQL? Was this a fair test?

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s