php - How to Handle a great number of rows with SQL Queries and take only small amount of data efficiently? -
i'm coding site in php, , site contain messages(like 100.000 , 200.000 or more) users post on site. problem is, messages stored on table called 'site_messages' it's id. means, messages aren't grouped poster, it's grouped id. if want fetch messages posted user 'foo', have query lot of rows, , slow think. or want fetch messages post subject(yes, contain post subject column too, , maybe more column add), must query table again, , unfortunately, less efficient. there speedy solutions that? i'm using php , mysql(and phpmyadmin).
edit: example, table this:
messageid: 1
messagecontent(varchar, message user posts): hi site. bye!
messageposter(varchar): crazyuser
messagepostdate: 12/12/09
messagepostedin(varchar, post subject): how make pizza
messageid: 2
messagecontent(varchar): site reallllly sucks.
messageposter(varchar): top_lel
messagepostdate: 12/12/09
messagepostedin(varchar): hello, have question!
messageid: 3
messagecontent(varchar): admin of site?
messageposter(varchar): creepy2000
messagepostdate: 1/13/10
messagepostedin(varchar): site boring.
etc...
this dbs (especially relationship dbs) built for! mysql , other dbs use things indexes access rows need in efficient way. able write queries select * site_messages subject "news%" order entrydatetime desc limit 10
find latest ten messages starting "news", or select * site_messages, user user.userid='foo' , site_messages.fk_user=user.id
find posts user, , you'll find performs pretty well. these, you'd have (amongst others) index subject column, , index on fk_user column.
work on having table structure (data model). of course if have issues can research db performance , topic of explain
plans help.
yes, each set of columns want, query table again. think of query set of rows. avoid sending large numbers of rows on connections. other commenters have suggested, can't more without more details tables.
Comments
Post a Comment