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 7163207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:51:48+00:00 2026-05-28T13:51:48+00:00

THE INFO Currently I have two tables I am working with- a POST table

  • 0

THE INFO

Currently I have two tables I am working with- a POST table that holds data for a individual posts, and a FAVORITES table that holds data for users that opt to save favorite posts in their profile.

The tables look like this:

POSTS and FAVORITES table

On the POSTS table there is only a primary key on id, no indexes that I have set. On Favorites I have a combined index that I was testing of (postid, deviceid).

The POSTS table contains approx. 10,000 entries.

The FAVORITES table contains approx. 4,680,500 entries.

The query I use to grab the favorites from a particular deviceid is:

SELECT post FROM POSTS 
WHERE id IN 
   (SELECT postid FROM favourites WHERE deviceid="12d4a4a4a4a4a4a");

THE PROBLEM:

With the amount of data being returned, and several devices having multiple favorites, the query can take upwards of 7-10 seconds to both COUNT favorites for a particular device and/or SELECT using the above query and subquery. When this happens during peak times, you can obviously imagine the issues that can cause.

Caching the query results is an option, but since the data is pretty specific in that the same user is not calling the query multiple times, but rather unique instances, I think there is a better solution. On another note, caching would need to be short lived, which would nullify its benefit.

I know the method of indexing, and I am familiar with foreign keys, but I’m not sure practically if and how they could be implemented between the query and the subquery to enhance performance.

Any advice/guidance is much appreciated.

Cheers,

Jared

  • 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-28T13:51:49+00:00Added an answer on May 28, 2026 at 1:51 pm
    SELECT post FROM POSTS 
    INNER JOIN favourites ON POSTS.id=favourites.postid 
    WHERE favourites.deviceid="12d4a4a4a4a4a4a");
    

    split the index in favourites in 2 indices one on deviceid and one on postid

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

Sidebar

Related Questions

I have a page that pulls together aggregate data from two different tables. I
We currently have a View that queries active directory info. I was wondering if
I have two tables : create table CurrentDay ( ID int identity primary key,
I currently am working on a little app that requests user info from my
I currently have two joined tables in a SQL Server database, one with news
In my MySQL database I have two tables: 'orders' and 'orders_lines'. Orders contains info
I have two tables: one table (okay, it's a view), vComputer, lists many computers
Background Info: File Replication is Lame Currently, we have a massive, high-traffic ASP.NET web
I have a C++ application with data that needs to be shared with a
I have two tables. One contains information on hotels, added to my website by

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.