performance - Slow Execution of MySQL Select Query -


i have following query…

select distinct *  vpas_posts_users  (post_user_id =:id , post_type != 4)  , post_updated >:updated  group post_post_id  union  select distinct vpas_posts_users.* pas_follow  join vpas_posts_users on  ( pas_follow.folw_followed_user_id = vpas_posts_users.post_user_id )  (( pas_follow.folw_follower_user_id =:id , pas_follow.folw_deleted = 0 )  or ( post_type = 4 , post_passed_on_by = pas_follow.folw_follower_user_id  , post_user_id !=:id ))  , post_updated >:updated  group post_post_id order post_posted_date desc limit :limit 

where :id = 7, :updated = 0.0 , :limit=40 example

my issue query taking minute return results. there in query can speed result?

i using rds

********edit*********

i asked run query explain result below

explain result query

********edit********** view definitition

create algorithm=undefined definer=`mysqluser`@`%` sql security definer view `vpas_posts_users` select    `pas_user`.`user_user_id` `user_user_id`,    `pas_user`.`user_country` `user_country`,    `pas_user`.`user_city` `user_city`,    `pas_user`.`user_company` `user_company`,    `pas_user`.`user_account_type` `user_account_type`,    `pas_user`.`user_account_premium` `user_account_premium`,    `pas_user`.`user_sign_up_date` `user_sign_up_date`,    `pas_user`.`user_first_name` `user_first_name`,    `pas_user`.`user_last_name` `user_last_name`,    `pas_user`.`user_avatar_url` `user_avatar_url`,    `pas_user`.`user_cover_image_url` `user_cover_image_url`,    `pas_user`.`user_bio` `user_bio`,    `pas_user`.`user_telephone` `user_telephone`,    `pas_user`.`user_dob` `user_dob`,    `pas_user`.`user_sector` `user_sector`,    `pas_user`.`user_job_type` `user_job_type`,    `pas_user`.`user_unique` `user_unique`,    `pas_user`.`user_deleted` `user_deleted`,    `pas_user`.`user_updated` `user_updated`,    `pas_post`.`post_post_id` `post_post_id`,    `pas_post`.`post_language_id` `post_language_id`,    `pas_post`.`post_type` `post_type`,    `pas_post`.`post_promoted` `post_promoted`,    `pas_post`.`post_user_id` `post_user_id`,    `pas_post`.`post_posted_date` `post_posted_date`,    `pas_post`.`post_latitude` `post_latitude`,    `pas_post`.`post_longitude` `post_longitude`,    `pas_post`.`post_location_name` `post_location_name`,    `pas_post`.`post_text` `post_text`,    `pas_post`.`post_media_url` `post_media_url`,    `pas_post`.`post_image_height` `post_image_height`,    `pas_post`.`post_link` `post_link`,    `pas_post`.`post_link_title` `post_link_title`,    `pas_post`.`post_unique` `post_unique`,    `pas_post`.`post_deleted` `post_deleted`,    `pas_post`.`post_updated` `post_updated`,    `pas_post`.`post_original_post_id` `post_original_post_id`,    `pas_post`.`post_original_type` `post_original_type`,    `pas_post`.`post_passed_on_by` `post_passed_on_by`,    `pas_post`.`post_passed_on_caption` `post_passed_on_caption`,    `pas_post`.`post_passed_on_fullname` `post_passed_on_fullname`,    `pas_post`.`post_passed_on_avatar_url` `post_passed_on_avatar_url` (`pas_user` join `pas_post` on((`pas_user`.`user_user_id` = `pas_post`.`post_user_id`))); 

try query:

select *       vpas_posts_users       post_user_id =:id  , post_type != 4  , post_updated > :updated  union  select u.*  vpas_posts_users u         join pas_follow f on f.folw_followed_user_id = u.post_user_id      u.post_updated > :updated , (   (f.folw_follower_user_id = :id , f.folw_deleted = 0)      or  (u.post_type = 4 , u.post_passed_on_by = f.folw_follower_user_id , u.post_user_id != :id) )  order u.post_posted_date desc; limit :limit 

other improvements

indices: sure have indices on following columns:

  • pas_user.user_user_id
  • pas_post.post_user_id
  • pas_post.post_type
  • pas_post.post_updated
  • pas_follow.folw_followed_user_id
  • pas_follow.folw_deleted
  • pas_post.post_passed_on_by

after done, please 1- check performance again (sql_no_cache) , 2- extract explain plan can adjust query.


explain results

explain results


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -