- getGetStoresSkusBaseSQL对于sku强制使用索引:FORCE INDEX(PRIMARY)

- sku的name_id, spec_quality, spec_unit, deleted_at改为唯一索引
This commit is contained in:
gazebo
2019-06-28 14:18:38 +08:00
parent be0aca2865
commit b0a2a672f9
2 changed files with 4 additions and 4 deletions

View File

@@ -166,14 +166,14 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus boo
func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}) (sql string, sqlParams []interface{}, err error) {
sql = `
FROM sku_name t1
JOIN sku t2 ON t1.id = t2.name_id AND t2.deleted_at = ?/* AND t2.status = ?*/
JOIN sku t2 FORCE INDEX(PRIMARY) ON t1.id = t2.name_id AND t2.deleted_at = ?/* AND t2.status = ?*/
JOIN store t3 ON t3.deleted_at = ?
`
if !isFocus {
sql += " LEFT"
}
sql += `
JOIN store_sku_bind t4 ON t4.sku_id = t2.id AND t4.deleted_at = ? AND t4.store_id = t3.id
JOIN store_sku_bind t4 ON t4.store_id = t3.id AND t4.sku_id = t2.id AND t4.deleted_at = ?
LEFT JOIN sku_name_place_bind t5 ON t1.id = t5.name_id AND t3.city_code = t5.place_code
WHERE t1.deleted_at = ? AND (t1.is_global = 1 OR t5.id IS NOT NULL OR 1 = ?)/* AND t1.status = ?*/
`

View File

@@ -228,9 +228,9 @@ type SkuAndName struct {
// }
// }
func (*Sku) TableIndex() [][]string {
func (*Sku) TableUnique() [][]string {
return [][]string{
[]string{"NameID", "SpecQuality", "SpecUnit", "DeletedAt"}, // todo 先设置为索引,之后应改为唯一索引
[]string{"NameID", "SpecQuality", "SpecUnit", "DeletedAt"},
}
}