473,372 Members | 1,157 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,372 software developers and data experts.

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 4607

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Soefara | last post by:
Dear Sirs, I have been developing an application on Windows with MySQL 3.23, making use of temporary tables. Now when I try to port the application to a Unix box running also MySQL 3.23, I...
2
by: Ryan | last post by:
Just a quicky about temporarary tables. If using QA, when you create a temporary table, it gets dropped if you close the query. Otherwise you need to state 'DROP TABLE myTable' so that you can...
11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
1
by: Sampath Reddy | last post by:
Hi Everybody, We are using UDB v8.1 I will explain about my Stored procedures which we are executing in UDB AIX box. We have 3 millions(apporox) of data in 22 tables. By applying the business...
2
by: Keith Watson | last post by:
Hi, we are currently implementing an application running on DB2 V7 on Z/OS using largely COBOL stored procedures, managed using WLM. Some of these stored procedures declared global temporary...
2
by: Chuck Crews | last post by:
I am interested in declaring a global temporary table within an application. The application processes 1 set of 600 or less rows each iteration. Multiple programs can and do call this one...
3
by: Mike Ridley | last post by:
I have 2 databases called (for example) "progs.mdb" and "files.mdb". Both these databases reside on computer "myserver". The progs database has links to the tables in the files database....
0
by: Zlatko Matiś | last post by:
I tried to work with postgres temporary tables from MS Access, but unsuccessfully... I was able to create temporary table by pass-through query, also I succeeded in creating linked table through...
1
by: Stefan van Roosmalen | last post by:
Hi there, Is there a way to list the TEMPORATY tables? I have tried SHOW TABLES, but this command only list the regular tables. Thank you very much for your answer. Regards, Stefan.
5
by: Rahul B | last post by:
Hi, I have very little knowledge about creating Procedures/functions in DB2. When i tried to create the test function like CREATE FUNCTION GET_TEST (P_TEST_ID INTEGER, P_SEL_OR_SORT...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.