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 7519987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:59:26+00:00 2026-05-30T01:59:26+00:00

I got a table like with 10 000 lines. declare @a table ( id

  • 0

I got a table like with 10 000 lines.

declare @a table
(
  id bigint not null,
  nm varchar(100) not null,
  filter bigint
  primary key (id)
)

A select, with 4-5 join, is taking x seconds. If a where clause is added, it’s now taking 3x seconds. The where clause:

filter = @filder or
filter is null

I applied a nonclustered index on the column, but I’m getting only 10% on perfomance.

Any tips?

edit: the perfomance issue happens when the filter column is added. all joins are on primary keys.

  • 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-30T01:59:27+00:00Added an answer on May 30, 2026 at 1:59 am

    I have a few thoughts on this:

    1. Chances are that your joins are joining on table.id – which is a primary key and has an index – bingo – high selectivity (because the values are unique). With it being indexed the optimizer can really optimize access to this table when it is used in joins.

    2. I’m not 100% sure but – either you do not have an index on filter or it is not selective enough. If you do not have an index – the optimizer will use a table scan. If you do have an index, but it is not selective enough, it will use a table scan anyways. Scans are expensive.

    3. Even if you do have an index on filter The optimizer does not like OR predicates. Basically when using an OR the optimizer might end up using an index scan instead of an index seek. Try using this instead: @filder = ISNULL(Filter, @filder as @sut13 suggested.

    So to improve the performance: add an index on filter if you do not have one and adjust your where clause to not use OR as I have suggested.

    Also:

    You shouldn’t expect the query with the where filter to perform equal to or better than the query with 4-5 joins. If the query with the joins is more selective and makes better use of indexes it is going to perform better

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

Sidebar

Related Questions

When I perform SELECT * FROM table I got results like below: 1 item1
I've got a sqlite table actions that looks something like this: uuid varchar (36)
I got a table like this: Id Date1 Date2 Status ---------------------------------------------- 1 01/01/2010 null
I've got a table arranged like this: <table style=width:100% class=ui-widget-content> <tr> <td rowspan=2 style=width:100px;padding:10px>
i've got a table like that : Article Number Last Voucher Number Last Voucher
I've got a table of student information in MySQL that looks like this (simplified):
I've got a table cell that I would always like to be a particular
I've basically got a table with 2 rows and it looks like this: ---------
I've got a situation like this: Table: FunTable ItemKey ItemName ItemPriceEffectiveDate ItemPrice 11 ItemA
I've got a large table in a SQL Server 2005 database and I'd like

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.