Firebird SQL Development
 
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 ForumsDatabasesFirebird SQL Development

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 August 22nd, 2011, 05:00 AM
Unspoken Unspoken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 6 Unspoken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 14 sec
Reputation Power: 0
Slow query when using UNION and VIEWs.

Hi guys.

I am having such query:

SELECT * FROM
(SELECT * FROM Archive_data
LEFT JOIN MyView
ON Archive_Data.ID = MyView.ID)
UNION ALL
SELECT * FROM Data
LEFT JOIN MyView
ON Data.ID = MyView.ID

The query is executing in 45 sec when using UNION and MyView VIEW.

If I separate query onto two queries then each of the queries is executing below one second.

Why UNION has such impact on the query when I am using views?

Thanks for the answer.

Reply With Quote
  #2  
Old November 19th, 2011, 01:53 PM
rapgame rapgame is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 74 rapgame User rank is Private First Class (20 - 50 Reputation Level)rapgame User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 14 h 12 m 41 sec
Reputation Power: 4
Because it has to search * data

What is the size of your database?

Are your indexes OK?

In my opinion a SELECT * FROM X is always slow in case of huge amount of data.

Simply the difference between a cheap query and an expensive one, right?.

Try to limit your output:

http://scott.yang.id.au/2004/01/limit-in-select-statements-in-firebird/

Reply With Quote
  #3  
Old November 19th, 2011, 06:48 PM
Unspoken Unspoken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 6 Unspoken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by rapgame
Because it has to search * data

What is the size of your database?

Are your indexes OK?

In my opinion a SELECT * FROM X is always slow in case of huge amount of data.

Simply the difference between a cheap query and an expensive one, right?.

Try to limit your output:

http://scott.yang.id.au/2004/01/limit-in-select-statements-in-firebird/


Thanks rapgame, but I do not think that selecting ALL columns is the problem here. (I could be always wrong). But if separated queries are executing 1 second each and UNION is simply adding one result set to the other than how can it slow down the whole operation 20 times? This is simply not logical. Unless UNION is diong something more that adding one result to the other...

Reply With Quote
  #4  
Old November 21st, 2011, 03:53 AM
mIRCata mIRCata is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: Plovdiv. Bulgaria
Posts: 200 mIRCata User rank is Corporal (100 - 500 Reputation Level)mIRCata User rank is Corporal (100 - 500 Reputation Level)mIRCata User rank is Corporal (100 - 500 Reputation Level)mIRCata User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 6 h 50 m 4 sec
Reputation Power: 11
Quote:
Originally Posted by Unspoken
Thanks rapgame, but I do not think that selecting ALL columns is the problem here. (I could be always wrong). But if separated queries are executing 1 second each and UNION is simply adding one result set to the other than how can it slow down the whole operation 20 times? This is simply not logical. Unless UNION is diong something more that adding one result to the other...

UNION removes the duplicate records from the both queries. So it's like GROUP BY all of your fields. Just for the test - how long takes if you use UNION ALL( UNION ALL doesn't remove duplicates)

Last edited by mIRCata : November 21st, 2011 at 03:55 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Slow query when using UNION and VIEWs.

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