查看多个表格会使网站变慢
view of multiple tables makes site slow
我开发了一个门户网站,其中有多个表格。
为了获得搜索结果,我创建了一个视图,该视图从多个 tables.While 搜索中获取数据,加载数据需要太多时间。我不知道如何解决它。请帮助我。
这是我创建的视图
CREATE VIEW `salontrip`.`view_search_result` AS (
SELECT
`salontrip`.`tbl_salon_info`.`salon_id` AS `salon_id`,
`salontrip`.`tbl_salon_info`.`salon_name` AS `salon_name`,
`salontrip`.`tbl_salon_info`.`land_mark` AS `land_mark`,
`salontrip`.`tbl_salon_info`.`salon_address` AS `salon_address`,
`salontrip`.`tbl_salon_info`.`gender` AS `gender`,
`salontrip`.`tbl_salon_city`.`city_name` AS `city_name`,
`salontrip`.`tbl_salon_locality`.`local_name` AS `local_name`,
`salontrip`.`tbl_salon_cashback`.`cashback_title` AS `cashback_title`,
`salontrip`.`tbl_salon_cashback`.`satrt_date` AS `cashback_start_date`,
`salontrip`.`tbl_salon_cashback`.`end_date` AS `cashback_end_date`,
(SUM(`salontrip`.`tbl_salon_rating`.`rating_value`) / COUNT(`salontrip`.`tbl_salon_rating`.`rating_value`)) AS `avg_rating`,
GROUP_CONCAT(DISTINCT `view_salon_categories`.`sub_cat_name` SEPARATOR ', ') AS `categories`,
GROUP_CONCAT(DISTINCT `salontrip`.`tbl_salon_services`.`service_cat` SEPARATOR ', ') AS `service_category`,
CONCAT('',IFNULL(GROUP_CONCAT(DISTINCT `salontrip`.`tbl_salon_brands`.`brand_name` SEPARATOR ' '),'')) AS `brands`,
MIN(`salontrip`.`tbl_salon_services`.`price_value`) AS `min_price`,
MAX(`salontrip`.`tbl_salon_services`.`price_value`) AS `max_price`
FROM (((((((`salontrip`.`tbl_salon_info`
JOIN `salontrip`.`tbl_salon_city`
ON ((`salontrip`.`tbl_salon_city`.`city_id` = `salontrip`.`tbl_salon_info`.`city_id`)))
JOIN `salontrip`.`tbl_salon_locality`
ON ((`salontrip`.`tbl_salon_locality`.`local_id` = `salontrip`.`tbl_salon_info`.`local_id`)))
LEFT JOIN `salontrip`.`view_salon_categories`
ON ((`view_salon_categories`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_services`
ON ((`salontrip`.`tbl_salon_services`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_brands`
ON ((`salontrip`.`tbl_salon_brands`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_cashback`
ON ((`salontrip`.`tbl_salon_cashback`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_rating`
ON ((`salontrip`.`tbl_salon_rating`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
WHERE (`salontrip`.`tbl_salon_info`.`is_trashed` = 0)
GROUP BY `salontrip`.`tbl_salon_info`.`salon_id`)
这里是之前运行的查询。
SELECT *
FROM (`view_search_result`)
WHERE (`salon_name` like '%%' or `service_category` like '%%' or `brands` like '%%' or `local_name` like '%%' or `salon_address` like '%%' or `land_mark` like '%%')
AND `city_name` LIKE '%Gurgaon%'
AND `local_name` LIKE '%%'
AND `service_category` LIKE '%%'
AND `brands` LIKE '%%'
AND `categories` LIKE '%%'
任何解决问题的想法将不胜感激。
提前致谢。
确保所有链接的和用于过滤的字段都已编入索引。这将加快查询速度,1000 倍。
我开发了一个门户网站,其中有多个表格。 为了获得搜索结果,我创建了一个视图,该视图从多个 tables.While 搜索中获取数据,加载数据需要太多时间。我不知道如何解决它。请帮助我。
这是我创建的视图
CREATE VIEW `salontrip`.`view_search_result` AS (
SELECT
`salontrip`.`tbl_salon_info`.`salon_id` AS `salon_id`,
`salontrip`.`tbl_salon_info`.`salon_name` AS `salon_name`,
`salontrip`.`tbl_salon_info`.`land_mark` AS `land_mark`,
`salontrip`.`tbl_salon_info`.`salon_address` AS `salon_address`,
`salontrip`.`tbl_salon_info`.`gender` AS `gender`,
`salontrip`.`tbl_salon_city`.`city_name` AS `city_name`,
`salontrip`.`tbl_salon_locality`.`local_name` AS `local_name`,
`salontrip`.`tbl_salon_cashback`.`cashback_title` AS `cashback_title`,
`salontrip`.`tbl_salon_cashback`.`satrt_date` AS `cashback_start_date`,
`salontrip`.`tbl_salon_cashback`.`end_date` AS `cashback_end_date`,
(SUM(`salontrip`.`tbl_salon_rating`.`rating_value`) / COUNT(`salontrip`.`tbl_salon_rating`.`rating_value`)) AS `avg_rating`,
GROUP_CONCAT(DISTINCT `view_salon_categories`.`sub_cat_name` SEPARATOR ', ') AS `categories`,
GROUP_CONCAT(DISTINCT `salontrip`.`tbl_salon_services`.`service_cat` SEPARATOR ', ') AS `service_category`,
CONCAT('',IFNULL(GROUP_CONCAT(DISTINCT `salontrip`.`tbl_salon_brands`.`brand_name` SEPARATOR ' '),'')) AS `brands`,
MIN(`salontrip`.`tbl_salon_services`.`price_value`) AS `min_price`,
MAX(`salontrip`.`tbl_salon_services`.`price_value`) AS `max_price`
FROM (((((((`salontrip`.`tbl_salon_info`
JOIN `salontrip`.`tbl_salon_city`
ON ((`salontrip`.`tbl_salon_city`.`city_id` = `salontrip`.`tbl_salon_info`.`city_id`)))
JOIN `salontrip`.`tbl_salon_locality`
ON ((`salontrip`.`tbl_salon_locality`.`local_id` = `salontrip`.`tbl_salon_info`.`local_id`)))
LEFT JOIN `salontrip`.`view_salon_categories`
ON ((`view_salon_categories`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_services`
ON ((`salontrip`.`tbl_salon_services`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_brands`
ON ((`salontrip`.`tbl_salon_brands`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_cashback`
ON ((`salontrip`.`tbl_salon_cashback`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
LEFT JOIN `salontrip`.`tbl_salon_rating`
ON ((`salontrip`.`tbl_salon_rating`.`salon_id` = `salontrip`.`tbl_salon_info`.`salon_id`)))
WHERE (`salontrip`.`tbl_salon_info`.`is_trashed` = 0)
GROUP BY `salontrip`.`tbl_salon_info`.`salon_id`)
这里是之前运行的查询。
SELECT *
FROM (`view_search_result`)
WHERE (`salon_name` like '%%' or `service_category` like '%%' or `brands` like '%%' or `local_name` like '%%' or `salon_address` like '%%' or `land_mark` like '%%')
AND `city_name` LIKE '%Gurgaon%'
AND `local_name` LIKE '%%'
AND `service_category` LIKE '%%'
AND `brands` LIKE '%%'
AND `categories` LIKE '%%'
任何解决问题的想法将不胜感激。
提前致谢。
确保所有链接的和用于过滤的字段都已编入索引。这将加快查询速度,1000 倍。