Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: (OT) Improving a SQL JOIN statement

by jorg (Friar)
on Apr 10, 2001 at 14:02 UTC ( [id://71330]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to (OT) Improving a SQL JOIN statement

For future diagnostics : it would help a lot if people would includ an 'Explain Plan' output whenever there are database performance issues on certain queries. For Mysql just do a 'EXPLAIN select foobar from tableBar a, tableFoo b where a.foo=b.bar' and it will tell you how the mysql optimizer handles this query.

From what you've told us it looks like mysql is ignoring the indexes :
- make sure you choose your 'driving' table correctly, if you want to group all the ratings per item then your itemtable will be driving the query. (and thus put 'select blah from itemtable, ratingtable where...' instead of 'select blah from ratingtable, itemtable where...'
- looking at the mysql docs: 'MySQL can't (yet) use indexes on columns efficiently if they are declared differently' ie make sure you've declared your join columns in the same way, don't declare one as a char(10) and the other as a char(15)
- you can tell the optimizer to use an index by using hints on which index to use. Mysql docs have all the info on that as well.

Jorg

"Do or do not, there is no try" -- Yoda
  • Comment on Re: (OT) Improving a SQL JOIN statement

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://71330]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.