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

  • SEARCH
  • Home
  • 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 117767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:23:18+00:00 2026-05-11T03:23:18+00:00

EDIT: I have added Slug column to address performance issues on specific record selection.

  • 0

EDIT: I have added ‘Slug’ column to address performance issues on specific record selection.

I have following columns in my table.

Id Int - Primary key (identity, clustered by default) Slug varchar(100) ... EntryDate DateTime 

Most of the time, I’m ordering the select statement by EntryDate like below.

Select T.Id, T.Slug, ..., T.EntryDate From (     Select Id, Slug, ..., EntryDate,           Row_Number() Over (Order By EntryDate Desc, Id Desc) AS RowNum     From TableName     Where ... ) As T Where T.RowNum Between ... And ... 

I’m ordering it by EntryDate and Id in case there are duplicate EntryDates.

When I’m selecting A record, I do the following.

Select Id, Slug, ..., EntryDate From TableName Where Slug = @slug And Year(EntryDate) = @entryYear      And Month(EntryDate) = @entryMonth 

I have a unique key of Slug & EntryDate.

What would be a smart choice of keys and indexes in my situation? I’m facing performance issues probably because I’m ordering by a column that is not clustered indexed.

Should I have Id set as non-clustered primary key and EntryDate as clustered index?

I appreciate all your help. Thanks.

EDIT:

I haven’t tried adding non-clustered index on the EntryDate. Data inserted from back-end, so performance for insert isn’t a big deal for me. Also, EntryDate is not always the date when it is inserted. It can be a past date. Back-end user picks the date.

  • 1 1 Answer
  • 2 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. 2026-05-11T03:23:19+00:00Added an answer on May 11, 2026 at 3:23 am

    Based on the current table layout you want some indexes like this.

    CREATE INDEX IX_YourTable_1 ON dbo.YourTable (EntryDate, Id) INCLUDE (SLug) WITH (FILLFACTOR=90)  CREATE INDEX IX_YourTable_2 ON dbo.YourTable (EntryDate, Slug) INCLUDE (Id) WITH (FILLFACTOR=80) 

    Add any other columns you are returning to the INCLUDE line.

    Change your second query to something like this.

    Select Id, Slug, ..., EntryDate From TableName Where Slug = @slug      AND EntryDate BETWEEN CAST(CAST(@EntryYear AS VARCHAR(4) + CAST(@EntryMonth AS VARCHAR(2)) + '01' AS DATE) AND DATEADD(mm, 1, CAST(CAST(@EntryYear AS VARCHAR(4) + CAST(@EntryMonth AS VARCHAR(2)) + '01' AS DATE)) 

    The way your second query is currently written the index will never be used. If you can change the Slug column to a related table it will increase your performance and decrease your storage requirements.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Put the properties files in WEB-INF/classes. Or include them in… May 12, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer For 1: This approach does not fully fit into standard… May 12, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer Use UNION ALL SELECT name, period, value, '1' AS category… May 12, 2026 at 12:26 am

Related Questions

i'm writing a data migration using south... but the question refers to the use
Edit: I apologize everybody. I used the term jagged array when I actually meant
I have declared a generic event handler public delegate void EventHandler(); to which I
I have a filename that has the following format: timestamp-username-1 This file is constantly

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.