Jump to content

Design Decision / Force MySQL to use Index


roopurt18

Recommended Posts

Here's the scenario.

There are three tables: UpDocs, POs, & DocTracking

UpDocs 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.
Link to comment
Share on other sites

Can you provide an example of doing that?

Here's my actual query (with the fields removed for clarity):
[code]
SELECT
  ...
FROM DocTracking t
LEFT 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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.