469,269 Members | 1,004 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

temporary tables...

Hi, just a quick question regarding performance and speed.

Q. Run a complicated query three times or create a TEMPORARY table and
access it as needed?

I have a page where it will be accessed 10,000+ a day.

In that page I have an SQL query where it involves 3 different tables
(approximate table sizes T1) 200,000 T2) 900,000 T3) 20 records)

I'll be running that query 3 times in that page...

One to retrieve the content and display it on the page.

Second to count the number of records (using COUNT(*) function)

And third to retrieve the content regions. (using DISTINCT function)

What would be the best way of doing...

Running the SQL query 3 times

Or

Create a temporary table and access it as many time as I need

Regards,


Jul 20 '05 #1
4 4534

"gonzal" <k2***@dodo.com.au> wrote in message
news:3f********@news.comindico.com.au...
Hi, just a quick question regarding performance and speed.

Q. Run a complicated query three times or create a TEMPORARY table and
access it as needed?

I have a page where it will be accessed 10,000+ a day.

In that page I have an SQL query where it involves 3 different tables
(approximate table sizes T1) 200,000 T2) 900,000 T3) 20 records)
I'll be running that query 3 times in that page...

One to retrieve the content and display it on the page.

Second to count the number of records (using COUNT(*) function)

And third to retrieve the content regions. (using DISTINCT function)

What would be the best way of doing...


In the case of an ASP application, using ADO and a client side cursor you
could just fetch the records, and then check the recorcount of the
recordset. That combines your first two steps into one. I don't understand
your third step.
--
BV.
WebPorgmaster - www.IHeartMyPond.com
Work at Home, Save the Environment - www.amothersdream.com
Jul 20 '05 #2

Thanks BV

Basically what I was planning to do is to open a table 3 times to
retrieve the following:
1) Content list, which will be displayed on to the client screen
2) Count the number of records retrieved
3) Retrieve properties region (eg. Postcodes 43554, 5543Ö) (using the
DISTINCT function when querying the table to eliminate duplicate values)

The table that Iím querying has to be INNER JOINT with 3 different
tables.

My question was:
Is it better to:
a) query the tables three times or;
b) run the query one time and insert the results into a local temporary
table that will contain a maximum of 200 records, then access the
temporary table as many times as needed?

After some more research I think the answer to that question should be
(b).
If anybody know a better way or think that Iím wrong, please replay...

PS: In your previous email you have mention about client side cursor.
I have posted another message title: "CursorLocation: Client Side Cursor
(How does it work?)" if you would not mind to share a bit more
knowledge, I would really appreciates that...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
You can probably wrap it all into 1 stored proc assuming you're using
SQL server. The first two parts can be done quite easily as BV
suggests, what is the third bit? Is it to do with grouping?

How about some sample results? And/Or the webpage?

"gonzal" <k2***@dodo.com.au> wrote in message news:<3f********@news.comindico.com.au>...
Hi, just a quick question regarding performance and speed.

Q. Run a complicated query three times or create a TEMPORARY table and
access it as needed?

I have a page where it will be accessed 10,000+ a day.

In that page I have an SQL query where it involves 3 different tables
(approximate table sizes T1) 200,000 T2) 900,000 T3) 20 records)

I'll be running that query 3 times in that page...

One to retrieve the content and display it on the page.

Second to count the number of records (using COUNT(*) function)

And third to retrieve the content regions. (using DISTINCT function)

What would be the best way of doing...

Running the SQL query 3 times

Or

Create a temporary table and access it as many time as I need

Regards,

Jul 20 '05 #4

"gonzal" <no****@abc.abc> wrote in message
news:3f***********************@news.frii.net...

Thanks BV

Basically what I was planning to do is to open a table 3 times to
retrieve the following:
1) Content list, which will be displayed on to the client screen
2) Count the number of records retrieved
3) Retrieve properties region (eg. Postcodes 43554, 5543.) (using the
DISTINCT function when querying the table to eliminate duplicate values)

The table that I'm querying has to be INNER JOINT with 3 different
tables.

My question was:
Is it better to:
a) query the tables three times or;
b) run the query one time and insert the results into a local temporary
table that will contain a maximum of 200 records, then access the
temporary table as many times as needed?

After some more research I think the answer to that question should be
(b).
If anybody know a better way or think that I'm wrong, please replay...

PS: In your previous email you have mention about client side cursor.
I have posted another message title: "CursorLocation: Client Side Cursor
(How does it work?)" if you would not mind to share a bit more
knowledge, I would really appreciates that...


So you want to get a bunch of columns, present them, get a count, and then
get a list of distinct values from the total data set? If I am understanding
you correctly, I'd use ADO, and get the data in a recordset. You can then
present it and count as I mentioned before to answer 1 & 2. The third option
can be answered by using the recordset and a quick loop to get your distinct
values. I think this would be better then hitting the database a second time
for the distinct values. You can use the recordset.sort property to quickly
sort and fetch the distinct values.
--
BV.
WebPorgmaster - www.IHeartMyPond.com
Work at Home, Save the Environment - www.amothersdream.com
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Zlatko Matiś | last post: by
1 post views Thread by Stefan van Roosmalen | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.