2017-02-07 29 views
0

我試圖用一個左連接彌合兩個表,並迫使索引只存在於連接表的索引,但我得到了以下錯誤:單力指數拋出錯誤的連接表

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FORCE INDEX (l.sfdcId) WHERE l.sfdcId = '003A000001eR0HsIAK' ORDER BY a.activity' at line 3

這裏的查詢正在運行的輸出(如果我刪除了FORCE INDEX正常工作):

SELECT a.activityDate,a.primaryAttributeValue,a.attributeDescription,l.firstName,l.lastName,l.title,l.email 
FROM activities AS a LEFT JOIN 
    leads AS l 
    ON a.leadId = l.leadId FORCE INDEX (l.sfdcId) 
WHERE l.sfdcId = '003A000001eR0HsIAK' 
ORDER BY a.activityDate DESC 

任何想法,爲什麼會失敗?

+2

https://dev.mysql.com/doc/refman/5.7/en/index-hints.html - *「這在語法上是有效的省略index_list用於USE INDEX,意思是「不使用索引」,省略FORCE INDEX或IGNORE INDEX的index_list是一個語法錯誤。「* --- *」FORCE INDEX提示像USE INDEX(index_list)一樣行爲,假設表掃描非常昂貴,換句話說,只有在無法使用其中一個命名索引來查找表中的行時才使用表掃描。「* –

回答

1

FORCE INDEX表定義後雲:

SELECT a.activityDate,a.primaryAttributeValue,a.attributeDescription, 
     l.firstName,l.lastName,l.title,l .email 
FROM activities a LEFT JOIN 
    leads l FORCE INDEX (sfdcId) 
    ON a.leadId = l.leadId 
WHERE l.sfdcId = '003A000001eR0HsIAK' 
ORDER BY a.activityDate DESC ;