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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:30:45+00:00 2026-06-09T08:30:45+00:00

I have this query which only runs once per request. SELECT SUM(numberColumn) AS total,

  • 0

I have this query which only runs once per request.

SELECT SUM(numberColumn) AS total, groupColumn
FROM myTable
WHERE dateColumn < ? AND categoryColumn = ?
GROUP BY groupColumn
HAVING total > 0

myTable has less than a dozen columns and can grow up to 5 millions of rows, but more likely about 2 millions in production. All columns used in the query are numbers, except for dateColumn, and there are indexes on dateColumn and categoryColumn.

Would it be reasonble to expect this query to run in under 5 seconds with 5 million rows on most modern servers if the database is properly optimized?

The reason I’m asking is that we don’t have 5 millions of data and we won’t even hit 2 millions within the next few years, if the query doesn’t run in under 5 seconds then, it’s hard to know where the problem lies. Would it be because the query is not suitable for a large table, or the database isn’t optimized, or the server isn’t powerful enough? Basically, I’d like to know whether using SUM() and GROUP BY over a large table is reasonable.

Thanks.

  • 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-06-09T08:30:46+00:00Added an answer on June 9, 2026 at 8:30 am

    As people in comments under your question suggested, the easiest way to verify is to generate random data and test query execution time. Please note that using clustered index on dateColumn can significantly change execution times due to the fact, that with “<” condition only subset of continuous disk data is retrieved in order to calculate sums.

    If you are at the beginning of the process of development, I’d suggest concentrating not on the structure of table and indexes that collects data – but rather what do you expect to need to retrieve from the table in the future. I can share my own experience with presenting website administrator with web usage statistics. I had several webpages being requested from server, each of them falling into one on more “categories”. My first approach was to collect each request in log table with some indexes, but the table grew much larger than I had at first estimated. 🙂 Due to the fact that statistics where analyzed in constant groups (weekly, monthly, and yearly) I decided to create addidtional table that was aggregating requests in predefined week/month/year grops. Each request incremented relevant columns – columns were refering to my “categories” . This broke some normalization rules, but allowed me to calculate statistics in a blink of an eye.

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

Sidebar

Related Questions

I have a query which looks like this: SELECT LossCost, CoverageID FROM BGILossCost] WHERE
I have this query which groups the results by ORDER#. SELECT ORDER#, MAX(SHIPDATE -
This one has me rather confused. I've written a query which runs fine from
I have this query which on executing in my sql command line client executes
I have this query which is a dependant query and taking much execution time
I have this query which works correctly in MySQL. More background on it here
I have this query which returns a result set with Date(column) as nvarchar datatype.
Right now I have this SQL query which is valid but always times out:
I have this query, which is giving me some problems... I am trying to
I have this query. It matches anything which has South in its name. But

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.