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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:15:25+00:00 2026-05-23T14:15:25+00:00

I have been running some speed tests on a query where I insert 10,000

  • 0

I have been running some speed tests on a query where I insert 10,000 records into a table that has millions (over 24mil) of records. The query (below) will not insert duplicate records.

MERGE INTO [dbo].[tbl1] AS tbl
USING (SELECT col2,col3, max(col4) col4, max(col5) col5, max(col6) col6 FROM #tmp group by col2, col3) AS src
ON (tbl.col2 = src.col2 AND tbl.col3 = src.col3)
WHEN NOT MATCHED THEN 
INSERT (col2,col3,col4,col5,col6)
VALUES (src.col2,src.col3,src.col4,src.col5,src.col6);

The execution times of the above query are sporadic; ranging anywhere from 0:02 seconds to 2:00 minutes.

I am running these tests within SQL Server Studio via a script that will create the 10,000 rows of data (into the #tmp table), then the MERGE query above is fired. The point being, the same exact script is executing for each test that I run.

The execution times bounce around from seconds to minutes as in:

  • Test #1: 0:10 seconds
  • Test #2: 1:13 minutes
  • Test #3: 0:02 seconds
  • Test #4: 1:56 minutes
  • Test #5: 0:05 seconds
  • Test #6: 1:22 minutes

One metric that I find interesting is that the seconds/minutes alternating sequence is relatively consistent – i.e. every other test the results are in seconds.

Can you give me any clues as to what may be causing this query to have such sporadic execution times?

  • 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-23T14:15:26+00:00Added an answer on May 23, 2026 at 2:15 pm

    I wish I could say what the cause of the sporadic execution times was, but I can say what I did to work around the problem…

    I created a new database and target table and added 25 million records to the target table. Then I ran my original tests on the new database/table by repeatedly inserting 10k records into the target table. The results were consistent execution times of aprox 0:07 seconds (for each 10k insert).

    For kicks I did the exact same testing on a machine that has twice as much CPU/Memory than my dev laptop. The results were consistent execution times of 0:00 seconds (It’s time for a new dev machine ;))

    I dislike not discovering the cause to the problem, but in this case I’m going to have to call it good and move on. Hopefully, someday, a StackO die-hard can update this question with a good answer.

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

Sidebar

Related Questions

I have been trying to learn Erlang and have been running into some problems
I have been running some small tests in PHP on loops. I do not
I am reading up on subrepos, and have been running some tests locally, seems
I have been running into some issues with animating multiple CALayers at the same
I have been running into some troubles recently and I think I need your
I have an application that has been running fine since its launch over a
I've been running some experiments with ASP.NET MVC2 and have run into an interesting
I have been running Visual Studio 2008 Team Edition for some time now and
I have been having some problems trying to get my PHP running. When I
I have some code which is been running by a backgroundworker I'd like some

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.