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
https://forums.phpfreaks.com/topic/34488-design-decision-force-mysql-to-use-index/
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.