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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:25:06+00:00 2026-06-13T22:25:06+00:00

This query is generated from a very long dynamic sequel stored procedure — the

  • 0

This query is generated from a very long dynamic sequel stored procedure — the procedure returns the requested number of records starting at a given index to be displayed in a Telerik Radgrid, effectively handling paging. A simplified version of the stored proc’s output:

SELECT r.* FROM (
       SELECT ROW_NUMBER() OVER(ORDER BY InventoryId DESC) as row,
       v.* FROM vInventorySearch v
       ) as R WHERE [ROW] BETWEEN 1 AND 10

When the “BETWEEN” clause is between 1 and 10, it runs in a fraction of a second, but if it’s between something like 10000 and 1010 it takes almost a full minute to execute.

I feel like I may be missing something fundamental here, but it seems to me that it shouldn’t matter which 10 records I’m retrieving, it should take the same amount of time.

Thanks for any input, I’m looking forward to being embarrassed!


Solution, courtesy Martin Smith (below) :

SELECT r.*, inv.* FROM 
(
    SELECT ROW_NUMBER() OVER(ORDER BY InventoryId DESC) as row, v.InventoryID
    FROM vInventorySearch v
    WHERE 1=1 
) as R 
inner join vInventory inv on r.InventoryID = inv.InventoryID
WHERE [ROW] BETWEEN 10001 AND 10010

Thanks for your help!

  • 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-13T22:25:08+00:00Added an answer on June 13, 2026 at 10:25 pm

    Paginating by ROW_NUMBER can indeed be pretty inefficient for higher row numbers.

    Sometimes it is better to break it up a bit and have the ROW_NUMBER query on a narrow index to retrieve the matching PKs with a join back onto the base table to retrieve the missing columns.

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

Sidebar

Related Questions

So basically I have this relatively long stored procedure. The basic execution flow is
This is a query automatically generated by Taggable extension for Doctrine ORM. SELECT t.id
I have an insert query that gets generated like this INSERT INTO InvoiceDetail (LegacyId,InvoiceId,DetailTypeId,Fee,FeeTax,Investigatorid,SalespersonId,CreateDate,CreatedById,IsChargeBack,Expense,RepoAgentId,PayeeName,ExpensePaymentId,AdjustDetailId)
this query SELECT * FROM tblContracts LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id INNER
This query works fine for me: $query = SELECT p.topnode_id, p.param_key, p.param_value FROM tbl_params
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although
This is very puzzling; the generated SQL is perfectly good, and I get correct
Currently I got this type of query generated by programmation (c#) INSERT INTO TableName
I've got a very long query for our SQL Server 2000 database, and I
This Query is giving me an error of #1054 - Unknown column 'totalamount' in

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.