我是mysql的初学者,我需要一些帮助来加速以下查询。对于INDEXES,我也是初学者,我不太明白如何添加和使用它们。 如果有人能帮我加快这个问题,我会非常感激。 目前,查询需要大约10秒才能加载。
显示行0 - 0(总共1行,查询占用10.2243秒)
SELECT `location2` AS `location` , '2' AS `number`
FROM `properties`
WHERE `price_from`
BETWEEN 0
AND 999999
AND `country` = 'france'
UNION SELECT `location3` AS `location` , '3' AS `number`
FROM `properties`
WHERE `price_from`
BETWEEN 0
AND 999999
AND `location2` = 'france'
UNION SELECT `location4` AS `location` , '4' AS `number`
FROM `properties`
WHERE `price_from`
BETWEEN 0
AND 999999
AND `location3` = 'france'
UNION SELECT `location5` AS `location` , '5' AS `number`
FROM `properties`
WHERE `price_from`
BETWEEN 0
AND 999999
AND `location4` = 'france'
UNION SELECT `location6` AS `location` , '6' AS `number`
FROM `properties`
WHERE `price_from`
BETWEEN 0
AND 999999
AND `location5` = 'france'
答案 0 :(得分:0)
不要跨列显示数组。相反,请根据需要使用另一个包含多行的表。
通过此更改,您可以避开UNION
,我们可以讨论如何优化所需的JOIN
。