473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Returning results while the query is executing

san
Hi,

I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?

Regards,
San
Jul 20 '05 #1
8 3688
"san" <sa****@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
Hi,

I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?

Regards,
San

Use a CURSOR methodology which reads each
or a group of the input rows one at a time, and if
some value is detected, writes the results to a table.

Periodically query the table for updates.
But it is slower.
Much slower.

Is this a one-off task, or is it to be queued
as a repetitive cyclic task?


--
Farmer Brown
Falls Creek
Australia
www.mountainman.com.au/software

Jul 20 '05 #2
san (sa****@hotmail.com) writes:
I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?


Since you cross-posted this to comp.databases.theory, I'm uncertain whether
you actually use MS SQL Server. In any case, this is engine dependent.

If you use MS SQL Server, you can achieve this without any special thrills.
It depends on your context, though. If you run the query from Query
Analyzer, you should have set output to text to see the rows coming in.
Results to grid and you will have to wait until all is done. If you
connect from ADO, you need to use a server-side forward-only cursor.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
San,

You can only get rows of the final result set. It is not possible to
peek at the intermediate results (results after each physical operator).

By default, individual rows of the result set will be sent to the client
whenever they are ready. You might be able to speed up the creation of
the first x rows by adding the hint OPTION (FAST x) where x is the
number of rows you want to have returned as fast as possible. Also,
dropping any ORDER BY clause may help.

Hope this helps,
Gert-Jan
san wrote:

Hi,

I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?

Regards,
San

Jul 20 '05 #4
sa****@hotmail.com (san) wrote in message news:<8e**************************@posting.google. com>...
Hi,

I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?

Regards,
San


i cant speak for all implementations, but I know how to do this with
oracle. Its not 'exactly' peaking. but it has a similiar result. You
optimize to get the first few rows, then you 'page'. Its what
google.com uses when you do a search and you get that bit estimate of
hits? Downside is the query will run slower overall, so its useful
when you have alot of data and your users will look at what comes up
first, then page to the next.

I dont remember the code exactly, its on asktom.oracle.com
select /*+ FIRST_ROWS */ b.*
from ( select a.*, a.rownum
from (your query here) a
where rownum < <<pick max number of rows you want in a batch >>)
where rownum > <<will start with 1 and be max + 1 for each 'page' >>

Rownum is a pseudo-column that can be used as a counter. Its not a
real value. so you cant go:

select blah
from tab
where rownum = 200;

it counts the return value of the result set.

Id assume that many databases can do this. I know google uses oracle
to do this, Id assume other web vendors use other databases to do the
same thing.
Jul 20 '05 #5
san
"mountain man" <hobbit@southern_seaweed.com.op> wrote in message news:<iH********************@news-server.bigpond.net.au>...
"san" <sa****@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
Hi,

I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?

Regards,
San

Use a CURSOR methodology which reads each
or a group of the input rows one at a time, and if
some value is detected, writes the results to a table.

Periodically query the table for updates.
But it is slower.
Much slower.

Is this a one-off task, or is it to be queued
as a repetitive cyclic task?

Hi,

My question is: Are the results of the query returned as they are
processed? That is, as the database engine constructs the result it
returns them (without waiting for the rest of the results to be
generated)?

Regards,
San
Jul 20 '05 #6
san
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn**********************@127.0.0.1>...
san (sa****@hotmail.com) writes:
I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?


Since you cross-posted this to comp.databases.theory, I'm uncertain whether
you actually use MS SQL Server. In any case, this is engine dependent.

If you use MS SQL Server, you can achieve this without any special thrills.
It depends on your context, though. If you run the query from Query
Analyzer, you should have set output to text to see the rows coming in.
Results to grid and you will have to wait until all is done. If you
connect from ADO, you need to use a server-side forward-only cursor.

Hi,

My question is: Are the results of the query returned as they are
processed? That is, as the database engine constructs the result it
returns them (without waiting for the rest of the results to be
generated)?

Regards,
San
Jul 20 '05 #7
san (sa****@hotmail.com) writes:
My question is: Are the results of the query returned as they are
processed? That is, as the database engine constructs the result it
returns them (without waiting for the rest of the results to be
generated)?


I believe so, although I have to admit that I have not conducted any
tests to verify that this is actually the case.

Notice also that it is likely to depend on the query.

If you say "SELECT * FROM big_tbl" you will probably get rows more or
less immediately. But if you say "SELECT * FROM big_tbl ORDER BY col",
you cannot get any rows before SQL Server has sorted the data.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #8
"san" <sa****@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
"mountain man" <hobbit@southern_seaweed.com.op> wrote in message

news:<iH********************@news-server.bigpond.net.au>...
"san" <sa****@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
Hi,

I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like to return the results as they query
executes rather than wait for the whole query to execute.
Basically, I want to get the results as they are prepared
by the database. Any way to do this?

Regards,
San

Use a CURSOR methodology which reads each
or a group of the input rows one at a time, and if
some value is detected, writes the results to a table.

Periodically query the table for updates.
But it is slower.
Much slower.

Is this a one-off task, or is it to be queued
as a repetitive cyclic task?

Hi,

My question is: Are the results of the query returned as they are
processed? That is, as the database engine constructs the result it
returns them (without waiting for the rest of the results to be
generated)?

If you use a CURSOR, and select records in batches,
and write records in batches, how can it not? Have you
looked up 'cursor' in the query language documentation?

The results are returned in batches which correspond to your
use of the cursor. If you wish to see these results incrementally
accumulating then query the table being written.

Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris | last post by:
Hi all - Hope you can help me with this SQL / PHP problem. I have the following tables with (in brackets) the following columns: PLAYER (playerid, forename, surname, birthdate, birthplace)...
1
by: Robin Hammond | last post by:
Can anybody tell me why a) when running a stored proc from an asp page to return a recordset the command succeeds if the sp queries an existing table directly, but b) if the stored proc populates...
3
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of...
3
by: Khurram | last post by:
Hi, Firstly, I will apologise now if I have posted in the wrong discussion group. Please let me know if I have for future reference. Below is the code to a WebMethod that is querying an Access...
2
by: jzogg7272 | last post by:
In my code I am executing a stored procedure to do a single row insert. I check the return value of the execution and I am getting -1, whereas a few weeks ago it was returning 0. Actually, I found...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
1
by: thepresidentis | last post by:
here is my problem, i have a website that compiles concert listings for users to search for shows in their local area, i ran into a problem with returning search results due to an improper format...
0
by: thepresidentis | last post by:
here is my problem, i have a website that compiles concert listings for users to search for shows in their local area, i ran into a problem with returning search results due to an improper format...
5
by: lazy | last post by:
Hi, I want to write a script such that it executes 2 mysql queries on the server. But before executing the second query, I would like to return the results of the first query to the user and then...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.