473,471 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HOW TO exit from a query

gauravgmbhr
107 New Member
hi friends
Well i am trying to create a query which uses a subquery in the from clause
I want as soon as the subquery fetches a row the , the subquery should stop executing , beacuse the table used by subquery has 40 million rows



THIS is so far i have been doing
Expand|Select|Wrap|Line Numbers
  1. SELECT column FROM some_table
  2. WHERE EXISTS  (SELECT * FROM some_other_table WHERE date BETWEEN start_date AND end_date) 
if Any row Exists between start date and end date the main query should execute

But the table in subquery has 40 million rows so i need to stop the whole table scan , and exit the subquery as soon as any row comes from the subquery

I have tried usin IN, SOME, And ANY also
Apr 4 '07 #1
4 5354
kershell
11 New Member
Try adding 'LIMIT 1' at the end of the subquery.
Apr 4 '07 #2
gauravgmbhr
107 New Member
Try adding 'LIMIT 1' at the end of the subquery.

WELL buddy milit is applied after the whole query is evaluated

If u have ever used a postgresql query emplain wizard in PGadmin
u will know that limit is applied after the whole query is evaluated


So limit wont work here
Apr 5 '07 #3
kershell
11 New Member
WELL buddy milit is applied after the whole query is evaluated

If u have ever used a postgresql query emplain wizard in PGadmin
u will know that limit is applied after the whole query is evaluated

So limit wont work here
For EXISTS, PostgreSQL documentation clearly says that
The subquery will generally only be executed far enough to determine whether at least one row is returned, not all the way to completion.
So even the LIMIT 1 should not be required. If there is no ORDER BY clause in a query there is no reason for all rows to be accessed.

If i do this

EXPLAIN
SELECT name FROM organisms WHERE EXISTS
(SELECT accession FROM features WHERE id ~ '^SAV' LIMIT 1);
I get
NOTICE: QUERY PLAN:
Result (cost=0.00..20.00 rows=1000 width=32)
InitPlan
-> Limit (cost=0.00..182.71 rows=1 width=32)
-> Seq Scan on features (cost=0.00..27349.21 rows=150 width=32)
-> Seq Scan on organisms (cost=0.00..20.00 rows=1000 width=32)
I interpret it as the limit on the subquery being applied before the main query executes. I could be wrong.
Apr 5 '07 #4
gauravgmbhr
107 New Member
For EXISTS, PostgreSQL documentation clearly says that


So even the LIMIT 1 should not be required. If there is no ORDER BY clause in a query there is no reason for all rows to be accessed.

If i do this



I get


I interpret it as the limit on the subquery being applied before the main query executes. I could be wrong.

YA I GOT IT, i read the manual again before ur message, and exists works as i expected, though i asked the qestion becuase of large execution time
Which was not because of the subquery in exists, there was some other mistake that i had been doing


But thanx for ur valuable TIME
regard Gaurav
Apr 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
3
by: Jon Bosker | last post by:
I have written an application that lives in the systray but when I try to close windows or logout it does not close my application and therefore prevents windows from shutting down or logging me...
4
by: Bob Day | last post by:
Using VS 2003, VB.net... I am confused about the Application.Exit method, where the help states "This method does not force the application to exit." Aside from the naming confusion, how do I...
3
by: jdubey | last post by:
hi i have one asp.net application.from that application i am connecting to sql sever on domain.earlier it was working properly.now i reinstalled sql server and try to connect from asp.net.now it...
1
by: Per | last post by:
Hi, I have a problem that I can't figure out. I have a database application to keep track of boxes that contain files. For data entry, I have a form with a main form section for the box-specific...
5
by: alexia.bee | last post by:
Hi, I my program runs other program(form) by process.start. In some cases the other program gets exception and dies. Can I get the reason of the termination of other program(Stopped by user,...
1
by: Roger Trask | last post by:
Web Server: IIS6 PHP Version: 5.2.5 Database: MS SQLEXPRESS 2005 Loaded PDO Drivers: MSSQL, MySQL, ODBC When executing the following script ($dbName, $username, $pw, $myDSN have been changed in...
4
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages...
3
by: Tim Roberts | last post by:
JRough <jlrough@yahoo.comwrote: More than the syntax problems, you also have a logic problem here. How do you think that "if" statement is ever going to be hit, given the statement immediately...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.