- getGetStoresSkusBaseSQL对于sku强制使用索引:FORCE INDEX(PRIMARY)
- sku的name_id, spec_quality, spec_unit, deleted_at改为唯一索引
This commit is contained in:
@@ -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) {
|
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 = `
|
sql = `
|
||||||
FROM sku_name t1
|
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 = ?
|
JOIN store t3 ON t3.deleted_at = ?
|
||||||
`
|
`
|
||||||
if !isFocus {
|
if !isFocus {
|
||||||
sql += " LEFT"
|
sql += " LEFT"
|
||||||
}
|
}
|
||||||
sql += `
|
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
|
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 = ?*/
|
WHERE t1.deleted_at = ? AND (t1.is_global = 1 OR t5.id IS NOT NULL OR 1 = ?)/* AND t1.status = ?*/
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -228,9 +228,9 @@ type SkuAndName struct {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (*Sku) TableIndex() [][]string {
|
func (*Sku) TableUnique() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"NameID", "SpecQuality", "SpecUnit", "DeletedAt"}, // todo 先设置为索引,之后应改为唯一索引
|
[]string{"NameID", "SpecQuality", "SpecUnit", "DeletedAt"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user