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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:40:49+00:00 2026-05-11T21:40:49+00:00

When I entered my current (employer’s) company a new database schema was designed and

  • 0

When I entered my current (employer’s) company a new database schema was designed and will be the base of a lot of the future tools that are/will be created.
With my limited SQL knowledge I think the table is rather well designed.
My only concern is that almost every table has a multy-part primary key. Every table has at least a CustomerId and key of it’s own. While these are indeed defining for a certain record, I have the feeling that multiple keys (we’re talking quadruple here) are very inefficient.

Today I was seeing some unimaginable CPU usage over a simple, repeated query that joins two tables, selects a single string field from the first and distincts them.

select distinct(f.FIELDNAME) as fieldName
from foo f
inner join bar b
   on f.id = b.fId
where b.cId = @id;

Checking the execution plan (I’m no EP Hero) I noticed that there are three major CPU points. The distinct (as expected) and two seeks over the indeces.
I would personally think that the indices seek should be extremely fast, but they take up 18% of the cost each. Is this normal? Is it due to the (quadruple) clustered indexes?

–UPDATE–
The query is used for creating a Lucene index. It’s a one-time processing that happens about weekly (sounds contradictive, I know). I can’t re-use any results here as far as I see.

  • 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-11T21:40:49+00:00Added an answer on May 11, 2026 at 9:40 pm

    Could you please run the following queries and post their output:

    SELECT  COUNT(*), COUNT(DISTINCT fieldname)
    FROM    foo
    
    SELECT  COUNT(*), COUNT(DISTINCT cId), COUNT(DISTINCT fId)
    FROM    bar
    

    This will help to estimate which indexes best suit your needs.

    Meanwhile make sure you have the following indexes:

    foo (FIELDNAME)
    bar (cId, fId)
    

    and rewrite your query:

    SELECT  DISTINCT(fieldname)
    FROM    foo f
    WHERE   EXISTS (
            SELECT  1
            FROM    bar b
            WHERE   b.fId = f.id
                    AND b.cId = @id
            )
    

    This query should use an index on f.FIELDNAME to build the DISTINCT list and the index on bar to filter out the non-existent values.

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

Sidebar

Related Questions

I have a MySQL database where I am storing information that is entered from
I am validating value entered in textbox against database and wanted to show right
we at our company are trying out some new technologies so thought of redesigning
I have a model with a field that is required but not entered by
is there anyway to findout from which page we entered the current page in
Hi iam using the following code for comparing the entered date with current date...
I use a timestamp field that is set with current time when inserts. It
I want to track the new url being entered in the browser when the
I wrote this very simple function for my current project called insidelabel() that let's
So, my current issue is that I can't find an elegant way to update

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.