Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1958538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:20:37+00:00 2026-05-17T08:20:37+00:00

I have a database containing addresses, one address per Row. Contains every address in

  • 0

I have a database containing addresses, one address per Row. Contains every address in the UK, so ~28 million rows. One of the columns is ‘Street’, which I am using to perform searches. I have a non-unique, non-clustered index on this column.

I’m having inconsistencies with search speeds however.

select * from Postcodes where Street = 'London Road'

Takes ~1s to run.

select * from Postcodes where Street like'London Road%'

Likewise takes about a second.

declare @Street varchar(20) = 'London Road%'
select * from Postcodes where Street like @Street

However, this statement, although apparantly identical to the second, takes about 40 seconds to run.

I’m at a complete loss to what is causing this speed difference. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T08:20:38+00:00Added an answer on May 17, 2026 at 8:20 am

    The problem is that MSSQLServer can’t know in advance what is going to be contained in @Street variable, so it can’t use an index on Street column.

    If your statement is:

    select * from Postcodes where Street = 'London';
    select * from Postcodes where Street like 'London Road%';
    

    It can used an index on Street column because it knows the string starts with London.

    If your statement is:

    select * from Postcodes where Street like @VariableName;
    

    It can’t use the index because with this statement you should be able to do:

    select * from Postcodes where Street like 'London%';
    select * from Postcodes where Street like '%London%';
    

    Or any other valid value for VariableName. It’s a typical problem in precompiled statements.

    What you can do is using the string directly, or not using parameters and change your statement to be a dynamic SQL statement in TSQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a database containing only varchar columns, with strings encoded in Latin-1
I have a database which has records with several fields containing some info. To
Say I have at database table containing information about a news article in each
I have a really big database (running on PostgreSQL) containing a lot of tables
I have a database that contains a date and we are using the MaskedEditExtender
I have a database table and one of the fields (not the primary key)
I have two databases, each containing email addresses of users. I've written a script
I have a database containing 40 pictures. These pictures are displayed using a pager.
I have a database with 1000 records containing a file name and a file
I have a script that appends some rows to a table. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.