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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:55:35+00:00 2026-06-12T14:55:35+00:00

Tables TEST_RUNS (ID int, Date_Time datetime, Row1 int, Row2 int, Row3 int, Row4 int)

  • 0

Tables

  • TEST_RUNS (ID int, Date_Time datetime, Row1 int, Row2 int, Row3 int, Row4 int)
  • ADMIN_TIME_FILTER (ID int, Name varchar(20), Start_Date datetime, End_Date datetime)

ADMIN_TIME_FILTER holds a small list of shifting date ranges that get updated frequently via automation. We have common date ranges (ThisYear, ThisDay, etc) and some more esoteric ranges. This table exists strictly as a way to filter data out of TEST_RUNS in a join.

TEST_RUNS holds actual data we care about, and has millions of rows. We have a bunch of defined views joining these two tables together, so we can just update the ADMIN_TIME_FILTER table and have the changes propagate to the views. Aside from date, there are no rows that link these two tables together.

Queries

The problem is that the estimated row count is widly off, resulting in poor performing queries. Here’s a simple query the exhibits the bad estimate:

with test as (
    SELECT a.* FROM TEST_RUNS a
    INNER JOIN ADMIN_TIME_FILTER b ON b.ID = 5 -- ID for ThisYear range
       AND a.date_time BETWEEN b.start_date AND b.end_date
)
select count(*) from test 

Here’s the query plan:

queryplan

Statistics aren’t the problem. I can run the following query and get an accurate row estimate

with test as (
    select tr.* from test_runs tr
    where tr.date_time between '2012-01-01 00:00:00' and '2012-12-31 00:00:00'
)
select count(*) from test

Help

Switching away from our join methodology isn’t a simple task, so I’m looking for an alternative to improve the row estimate.

Indexed views don’t appear to be a viable option due to the performance implications.

  • 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-12T14:55:36+00:00Added an answer on June 12, 2026 at 2:55 pm

    The problem isn’t the row count. Your query is set up as a non-equijoin. There is really no other way for SQL Server to handle the join other than by using nested loops.

    If you have an id in the “a” table, the following might help:

    with test as (
        SELECT a.*
        FROM TEST_RUNS a INNER JOIN
             ADMIN_TIME_FILTER b
             ON a.id = b.id and b.ID = 5 and -- ID for ThisYear range
                a.date_time BETWEEN b.start_date AND b.end_date
    )
    select count(*) from test 
    

    By matching on the “id” between the tables, SQL Server can consider other join algorithms, such as merge joins or hash joins.

    I suspect that there might be another way to fix this. What is the index on B using? I would suggest (id, start_date, end_date). The engine might be deciding to using an index on the dates to satisfy the query.

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

Sidebar

Related Questions

Assume I have two tables, Student Test Id Name TestId Type StudentId -- ----
With this table: CREATE TABLE test_insert ( col1 INT, col2 VARCHAR(10), col3 DATE )
Is there a free utility that will fill up your database tables with test
I have a query that displays columns from multiple tables in a test dbase.
I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31
I have two Tables: Table 1: Questions : QuestionId NUMERIC Title TEXT Test Data
According to the docs: A TestCase, on the other hand, does not truncate tables
I am trying to query data from two tables into one tables using OUTER
Here's a procedure that I'm trying to run. It inserts into two tables -
Table: CREATE TABLE `test` ( `uid` int(11) unsigned NOT NULL AUTO_INCREMENT, `rating` smallint(5) unsigned

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.