Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6239165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:20:45+00:00 2026-05-24T11:20:45+00:00

What is the best way to show friends’ posts? Each user can have maximum

  • 0

What is the best way to show friends’ posts?

Each user can have maximum 5000 friends.

Steps:

1) mysql retrieve 5000 friends’ usernames.

2) store 5000 friends’ usernames in a php array.

3) SELECT posts, datatime FROM tbl_posts WHERE username IN ($array) ORDER BY id DESC LIMIT 10;

Question : Let’s say zac1987 is 5000th item in php array. If the 10 latest posts are posted by zac1987, does mysql need to waste times to loop through 5000 items to determine whether or not the post is posted by him? So if I want to show 10 latest posts, does mysql need to loop through 5000 friends x 10 posts = 50,000 items? And every 5 seconds need to check if there is any new posts, so it means every 5 seconds need to loop 50,000 items? Is there any method to prevent so many looping/filtering items process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:20:46+00:00Added an answer on May 24, 2026 at 11:20 am
    SELECT  p.*
    FROM    friend f
    JOIN    post p
    ON      p.author = f.friend_id
    WHERE   f.user_id = $myuserid
    ORDER BY
            p.post_date DESC
    LIMIT 10 
    

    You should create indexes on post (post_date), post (author), friend (friend_id, user_id)

    Depending on the cardinality, MySQL will either make post leading in the join (in which case the first index will be used) or make friend leading (in which case it will gather all friends’ posts and sort them).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi friends what is the best way to show the mysql enum values while
What is the best way to show different form fields for different user in
What's the best way to show just 2 posts in the loop? <?php $i
what's the best way to show each blocks' respective sum in the labels provided
what is the best way to show a spinner? I have prepared a div(id=spinner),
What is the best way to show a message to user after session is
What is the best way to show a user that he is in offline
I have a quick question on the best way to show a particular message
Can you please suggest me, best way to show pdf files in iphone since
What is the best way to show a list with 20 images in rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.