Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 17th, 2003, 03:40 PM
sad.machine sad.machine is offline
I hate nerds
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 533 sad.machine Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 20 h 48 m 41 sec
Reputation Power: 0
optimizing queries

could creating views greatly optimize the efficiency of a set a queries?

for example, imagine that i have a table with thousands of records that i am self joining. if i did something like this:

SELECT t1.id , t2.id
FROM table t1, table t2
WHERE t1.s= t2.e AND t1.id = $id1 AND t2.id = $id2;

it would take a long time to cross multiply the table.

but what if i did this (forgive the syntax i have never created a view before):

CREATE VIEW t1 (*)
AS SELECT * FROM table WHERE id = $id1;

CREATE VIEW t2 (*)
AS SELECT * FROM table WHERE id = $id2;

SELECT t1.id , t2.id
FROM table t1, table t2
WHERE t1.s= t2.e;


in my case creating the views would eliminate many rows, leaving on average around 20. so joining those two together should a bit better.

am i correct?

i guess the better question would be, does the database system join the tables or eliminate rows first

Last edited by sad.machine : July 17th, 2003 at 03:42 PM.

Reply With Quote
  #2  
Old July 17th, 2003, 11:34 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Views are commonly used to simply complex sql statements and/ or to hide underlying data structure from end users as well as for a number of other reasons. A view will still query the underlying tables and their is still the same cost as if you performed the query on the original table. Depending on your database system you could create heap tables or derived tables that are updated independently of the users query.
...
For optimization you will want to ensure that your tables are indexed, that queries are written to take advantage of existing indexes, that your data types are small as possible that your tables are analyzed and optimized when needed.

Reply With Quote
  #3  
Old July 18th, 2003, 09:17 AM
sad.machine sad.machine is offline
I hate nerds
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 533 sad.machine Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 20 h 48 m 41 sec
Reputation Power: 0
so you are saying that a join statement on a view (that has about 5% the number of rows as the original table) will take as long as a join on the original table?

do you know anythingabout temporary tables?

Reply With Quote
  #4  
Old July 18th, 2003, 10:09 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 21 h 49 m 55 sec
Reputation Power: 19
If you are using Oracle you can use something called a materialized view. It keeps the data pre-summarized, but a normal view does not increase performance. As said above it just hides complexity.

Your sql is just merged with the sql of the view.

Reply With Quote
  #5  
Old July 18th, 2003, 10:11 AM
sad.machine sad.machine is offline
I hate nerds
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 533 sad.machine Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 20 h 48 m 41 sec
Reputation Power: 0
gotcha.

unfortunately this is a homegrown project, and i will be using mysql

do you know anything abuot temporary tables?

Reply With Quote
  #6  
Old July 18th, 2003, 06:14 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
If you are using mysql you could look into using heap tables.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > optimizing queries


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 | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway