Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
very large result sets
Old 05-24-2007, 04:44 AM very large result sets
Junior Talker

Posts: 3
Name: Martin
Trades: 0
I have a database with several tables with over 100 million rows. One of them has only two indexed attributes: id_document and id_set. Every document may belong to several sets. Then I need ids of all documents that belong to specified set. This result set may be very large, may contain more than 20 million rows and I need portions of 100 rows. So the query could be: select id_document from table limit x, 100. But when x is too high, the query is (of course) slow. I have also tried cursors in PostgreSQL, but it is still slow. Does anybody know, how to make it faster?
banan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-24-2007, 05:25 AM Re: very large result sets
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Depends how you want to use the info coming out of the database, and how often it changes. Can you execute the query once, then on your web server ( I'm assuming it's a web app ) write out an XML file with the results already broken into groups of 100?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 05-24-2007, 12:56 PM Re: very large result sets
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,518
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I have also tried cursors in PostgreSQL, but it is still slow. Does anybody know, how to make it faster?
Not without seeing some of the queries.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-24-2007, 03:04 PM Re: very large result sets
Junior Talker

Posts: 3
Name: Martin
Trades: 0
Quote:
Originally Posted by ForrestCroce View Post
Depends how you want to use the info coming out of the database, and how often it changes. Can you execute the query once, then on your web server ( I'm assuming it's a web app ) write out an XML file with the results already broken into groups of 100?
Unfortunately, it won't solve my problem.
banan is offline
Reply With Quote
View Public Profile
 
Old 05-24-2007, 03:11 PM Re: very large result sets
Junior Talker

Posts: 3
Name: Martin
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Not without seeing some of the queries.
Ok, select id_document where id_set=something limit x, 100 is slow for high x.
Using cursor under PostgreSQL:
CREATE FUNCTION reffunc() RETURNS refcursor AS '
DECLARE
ref refcursor;
BEGIN
OPEN ref FOR select id_document where id_set=something;
RETURN ref;
END;
' LANGUAGE 'plpgsql';[FONT=verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif]

BEGIN;
SELECT reffunc();
FETCH 100 IN "<unnamed cursor 1>";
COMMIT;

This is still slow.
[/FONT]
banan is offline
Reply With Quote
View Public Profile
 
Old 05-24-2007, 06:11 PM Re: very large result sets
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Don't be offended, but did you tried an analyze of your query to see if you could help it a bit by adding indexe(s) on some other fields ?

It may help the engine to limit the number of tuples to select.

Are you doing an ordering too ? This can be a pretty heavy speed penalization, as the engine have to order the datas before going you back the list of them.
If you do, you may have a speed improvement by doing the ordering in the front-end language, or on the result subset.


I haven't worked on pgsql for the last 6 years, so I don't know what changed in the mean time, but at this time it wasn't especially fast (when keeping the atomic transaction log), and I was using a mysql db to "cache" synthetic results of typical select members could run.

Too complex and specific to my previous situation maybe to explain in long upfront, but if you are interested, drop me a msg.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-24-2007, 06:11 PM Re: very large result sets
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Does MySQL or PostgreSQL have anything like Oracle's rownum? Can you select everything into a temporary table and add an identity column? If you can use WHERE ID BETWEEN 100 AND 200, that might run a lot faster.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Reply     « Reply to very large result sets
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31602 seconds with 12 queries