roopurt18 Posted January 17, 2007 Share Posted January 17, 2007 Here's the scenario.There are three tables: UpDocs, POs, & DocTrackingUpDocs stores information about uploaded documents.POs stores information about imported documents from another software system.DocTracking records visits by users to these pages.Within DocTracking there is a DocID (INT) field that references UpDocs.ID (INT) or POs.PONum (VARCHAR). There is a query within the site that is being dragged down by:LEFT JOIN POs p ON (DocTracking.DocID=p.PONum)Basically a VARCHAR field is being compared to an INT field. There is an index within POs on the PONum VARCHAR field. Is there any way I can force the query to use this index? I know I can use FORCE INDEX ([i]idx_name[/i]), however that doesn't appear to work due to the type differences in the fields.I can circumvent this problem by adding an INT column to POs, call it iPONum (INT), and creating an index on it. However I'd rather not add an extra column to the table if I can avoid it. Quote Link to comment https://forums.phpfreaks.com/topic/34488-design-decision-force-mysql-to-use-index/ Share on other sites More sharing options...
btherl Posted January 17, 2007 Share Posted January 17, 2007 Ouch. Is it practical to convert it to a subquery including an explicit cast? That'll get you use of the index. Quote Link to comment https://forums.phpfreaks.com/topic/34488-design-decision-force-mysql-to-use-index/#findComment-162659 Share on other sites More sharing options...
roopurt18 Posted January 17, 2007 Author Share Posted January 17, 2007 Can you provide an example of doing that?Here's my actual query (with the fields removed for clarity):[code]SELECT ...FROM DocTracking tLEFT JOIN wv_user u ON (t.User=u.login)LEFT JOIN wssubc s ON (u.subname=s.subname)LEFT JOIN webview_docs d ON (t.DocID=d.doc_wvid)LEFT JOIN POOptions p ON (t.DocID=p.PONum)WHERE t.Module=2 LIMIT 0,25[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34488-design-decision-force-mysql-to-use-index/#findComment-162942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.