MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 16th, 2012, 10:55 AM
strtline strtline is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 8 strtline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 29 m 53 sec
Reputation Power: 0
Scrolling/Paging through large database

Hello:
My client has a very large database (5.3 million records). These records are indexed by ownername, which can be duplicates. They want to be able to display 25 records at a time with the ability to display the next 25 or previous 25 and scroll through the table. I have tried SELECT * FROM table ORDER BY ownername LIMIT 0,25, increasing/decreasing the offset by 25 each time they click a previous/next button. Works great at 1st but as the offset increases the query takes forever. ie LIMIT 1000000,25.
Can anyone assist on a way to allow paging what works efficiently?
Thanks in advance

Reply With Quote
  #2  
Old June 16th, 2012, 12:41 PM
strtline strtline is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 8 strtline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 29 m 53 sec
Reputation Power: 0
Paging through large database

Hello:

My client has a very large database (5.3 million records). These records are indexed by ownername, which can be duplicates. They want to be able to display 25 records at a time with the ability to display the next 25 or previous 25 and scroll through the table. I have tried SELECT * FROM table ORDER BY ownername LIMIT 0,25, increasing/decreasing the offset by 25 each time they click a previous/next button. Works great at 1st but as the offset increases the query takes forever. ie LIMIT 1000000,25.
Can anyone assist on a way to allow paging what works efficiently?

Thanks in advance

Reply With Quote
  #3  
Old June 17th, 2012, 03:03 AM
sr sr is offline
Problem Solver
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2001
Location: Stockholm, Sweden
Posts: 4,424 sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 6 h 39 m 58 sec
Reputation Power: 532
This is a classic problem.

The ORDER BY humpty LIMIT x,y internally needs the data in sorted order and needs to scan through all x records before it can return the y amount of them.

So if x starts to become large you will pay a penalty.

Usually you can circumvent it by in some way limit the amount of rows with a WHERE clause. Of course you can have a hard time to know what that WHERE is if you have duplicates etc etc. Best of all is numeric primary key like an INT. It makes the index size small, you have a fairly predictable amount of values (although you can have "holes" in the sequence in the form of deleted rows), etc.

But in your case you could perhaps get the customer to first choose the first letter in the ownername before they start to page through the data. That way you have split the load to work with by 26 or maybe the first two letters and split it by 676.

You could even handle it in some elaborate way in your own code.

But the point is that a query like:
Code:
SELECT
  ...
FROM
  humpty
WHERE
  ownername LIKE 'a%'
ORDER BY
  ownerename
LIMIT x,y

with a sensible WHERE on an indexed column is much faster than one without the where where all rows needs to be in sorted order and scanned.

Good luck!
__________________
/Stefan

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Scrolling/Paging through large database

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap