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 > Database Server Software > MySQL > Forum Design

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-25-11, 08:16
AGISB AGISB is offline
Registered User
 
Join Date: Mar 2004
Posts: 15
Forum Design

I am designing a database for a small forum. Originally I had a forum table a threat table and a post table. I now have a forum table and a post table as threats can be recognized by a post that has no answers. So my Post table structure is:

`post_id` int(10) unsigned NOT NULL auto_increment,
`thread_id` int(10) unsigned default NULL,
`forum_id` int(11) NOT NULL,
`userid` int(10) unsigned default NULL,
`parentPost` int(11) default NULL,
`post_title` varchar(250) character set latin1 default NULL,
`post_text` text character set latin1,
`post_creation` datetime default NULL,
`isPoll` tinyint(1) NOT NULL default '0',
`pic` varchar(32) collate latin1_german1_ci default NULL,
`thread_flag` enum('0','1') collate latin1_german1_ci NOT NULL default '0' COMMENT '0=normal, 1=sticky
`isOpen` tinyint(1) NOT NULL default '1' COMMENT '0=closed for writing, 1 open for writing',
`post_status` time NOT NULL
`IP` varchar(15) collate latin1_german1_ci NOT NULL,
`hits` int(11) default NULL,
PRIMARY KEY (`post_id`)

Now I am have a problem with getting the threats with a good performance. I got following:

SELECT a .* ,
(SELECT max( b.post_creation ) AS maxi FROM posts AS b WHERE a.post_id = b.post_id OR a.post_id = b.parentPost AND b.post_status = '0' ) AS wert
FROM posts a
WHERE a.parentPost IS NULL
AND a.forum_id = '--id-here--'
ORDER BY thread_flag DESC , wert DESC

I made 800 threats and the performace is at about 1.07 Secs for the query which is way to long but I am stuck thinking of another way. Do I really have to get the max for each threat seperately and resort the enties in an array?

Maybe a better design is necessary ...
Reply With Quote
  #2 (permalink)  
Old 01-25-11, 08:42
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
you have no indexes
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-25-11, 09:31
AGISB AGISB is offline
Registered User
 
Join Date: Mar 2004
Posts: 15
Thanks, unfortunately it didn't help as I have only threats in the post table to check my navigation when I stumbled over the performance.
Reply With Quote
  #4 (permalink)  
Old 01-25-11, 09:34
AGISB AGISB is offline
Registered User
 
Join Date: Mar 2004
Posts: 15
It might just be a good idea to update the threat post entry with the last time stamp every time I post to that threat. Simple update on posting but a simple select were it cost performance ...
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