0

I'm asked to get the information based on a specific ID( here 406f-871b-a3ee71f7038) , like so :

select * from BIG_Session (nolock)
where SessionSID like '%406f-871b-a3ee71f70386%'

is this inefficient? How long is too long to wait for it to finish? I waited 30 seconds and felt that that was too long, and just canceled it.

Caffeinated
  • 11,982
  • 40
  • 122
  • 216

2 Answers2

2

You will be causing a scan with the prefix wildcard character %. If you know that 406f... will be the beginning of the string you can utilize a possible seek:

select * from BIG_Session
where SessionSID like '406f-871b-a3ee71f70386%'

Notice I took out the first percent sign.

How long is too long to wait for it to finish?

That depends on you, your environment, your users, and what is an acceptable duration for your business requirements. 30 seconds is acceptable in certain situations/environments, but detrimental in others.

1

If you're searching for a specific ID, I think = will be more efficient than LIKE:

select * from BIG_Session (nolock)
where SessionSID = '406f-871b-a3ee71f70386'

As regards how long, that's subjective and difficult to quantify without knowing more details of your environment and expectations.

It also may be worth a read of this SO question in regards to your use of NOLOCK: Is the NOLOCK (Sql Server hint) bad practice?

Community
  • 1
  • 1
Barry Kaye
  • 7,682
  • 6
  • 42
  • 64