If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Which is better in terms of optimization?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-27-08, 10:24
dele454 dele454 is offline
Registered User
 
Join Date: Jan 2008
Location: Cape town, South Africa
Posts: 11
Which is better in terms of optimization?

I just need your take on which of these two scenarios will yield quicker results with optimization in mind. On the front end there are a lot of pages with counts per category of events e.g Restaurants (40) | Pubs (2) | Gallery (6)

First Scenario:

Which is better in terms of optimization?-events.gif

Having a stored procedure that would count each event per category based on this ER Diagram above or


Second Scenario:

Have the Event & Category tables as it is from above but have a series of Category tables for each individual Category. So Restaurant will have it own table, pub etc and house only the EventID for each event.

On counting instead of running a Stored procedure that scans through the whole event table + Category table like Scenario 1, I'll run one stored procedure that counts all these MyISAM Category table records to count how many records there are in each category table.


I need to know which will yield a faster outcome, which will be more memory intensive. These Categories will hardly change. There might be an additional category but that wont be an issue updating the Category table and creating a new eventcategory table.

Kindly let me have comments
Reply With Quote
  #2 (permalink)  
Old 03-27-08, 10:39
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Scenario 1 with an index on CategoryId would be a much better design, and should perform just as well (though I know nothing of mySQL which I'm guessing you are using).
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 03-27-08, 10:43
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Tony - don't you think an index on category name? In that case the count wouldn't need to touch the leaf level - just the B-Tree (assuming this is applicable to mySQL - I too can claim utter ignorance of this RDBMS).
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #4 (permalink)  
Old 03-27-08, 10:44
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Scratch that. Misread the requirement.....

Although it does link back to a discussion of surrogates and natural keys from the other day of course....
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #5 (permalink)  
Old 03-27-08, 13:54
dele454 dele454 is offline
Registered User
 
Join Date: Jan 2008
Location: Cape town, South Africa
Posts: 11
Quote:
Scenario 1 with an index on CategoryId would be a much better design, and should perform just as well (though I know nothing of mySQL which I'm guessing you are using).
Yes i am using MYSQL.
Reply With Quote
  #6 (permalink)  
Old 03-27-08, 14:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
see also this thread on some other site which will remain unnamed, where you asked the exact same question

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937; 03-27-08 at 15:04.
Reply With Quote
  #7 (permalink)  
Old 03-27-08, 14:49
dele454 dele454 is offline
Registered User
 
Join Date: Jan 2008
Location: Cape town, South Africa
Posts: 11
r937 Can you please delete the link. I am trying to source opinions from 2 seperate forums. Please lets keep sitepoint out of this discussion
Reply With Quote
  #8 (permalink)  
Old 03-27-08, 15:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
sure no problem

i just thought i would save the guys here from taking the time to give you an opinion that someone else has already given you elsewhere
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 03-27-08, 15:25
dele454 dele454 is offline
Registered User
 
Join Date: Jan 2008
Location: Cape town, South Africa
Posts: 11
The intention is sourcing varied opinions. I am being given a different advise here. Can you kindly take the thread out completely it simply doesnt make any sense with the rephrasing. I didnt post a similar thread in some other forum because you are also there posting links about similar questions asked elsewhere. You dont know the intention of the thread poster!

Last edited by dele454; 03-27-08 at 15:30.
Reply With Quote
  #10 (permalink)  
Old 03-29-08, 05:46
ronnyy ronnyy is offline
Registered User
 
Join Date: Feb 2008
Posts: 43
I would see it as Scenario 1 with an index on CategoryID and then a Join on Events and EventsCategory tables with a group by CategoryID

However I don't have the knowledge to tell you if this is a faster way than scenario 2
Reply With Quote
  #11 (permalink)  
Old 03-29-08, 15:55
dele454 dele454 is offline
Registered User
 
Join Date: Jan 2008
Location: Cape town, South Africa
Posts: 11
Thanks for the comment will implement.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On