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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:27:04+00:00 2026-05-27T03:27:04+00:00

This query is a bit slow, and I’d like to optimize it, any ideas?

  • 0

This query is a bit slow, and I’d like to optimize it, any ideas?

SELECT DISTINCT a.id
FROM   article a
       LEFT JOIN article_comment ac
         ON a.id = ac.article_id
       LEFT JOIN comment c
         ON ac.id = c.id
WHERE  a.id IN (SELECT a2.id
                  FROM   article_user_read aur
                         LEFT JOIN article a2
                           ON aur.article_id = a2.id
                  WHERE  c.published_date > aur.read_date
                     AND aur.user_id = 36748
                     AND aur.followed = 1)
ORDER  BY c.published_date DESC

here is the article_user_read table :

CREATE TABLE `article_user_read` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `article_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `read_date` datetime NOT NULL,
  `followed` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `UNIQ_BBE52A0262922701A76ED395` (`article_id`,`user_id`),
  KEY `IDX_BBE52A0262922701` (`article_id`),
  KEY `IDX_BBE52A02A76ED395` (`user_id`),
  CONSTRAINT `article_user_read_ibfk_3` FOREIGN KEY (`article_id`) REFERENCES `article` (`id`),
  CONSTRAINT `article_user_read_ibfk_4` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20193 DEFAULT CHARSET=latin1;

The other are just simple article & user table.

  • 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-27T03:27:04+00:00Added an answer on May 27, 2026 at 3:27 am
    SELECT DISTINCT a.id
      FROM article AS a
    
      JOIN article_user_read AS aur
        ON aur.article_id = a.id
    
      JOIN comment AS c
        ON ac.id = c.id
    
      JOIN article_comment AS ac
        ON a.id = ac.article_id
    
     WHERE c.published_date > aur.read_date
       AND aur.user_id = 36748
       AND aur.followed = 1
    
     ORDER BY c.published_date DESC
    

    It doesn’t make sense to LEFT JOIN article_user_read with article, because you’re interested in articles, so you don’t care if there are articles without a article_user_read relation — that can be optimized to a JOIN.

    You also only want articles which have a comment after the user reads the article, so the relation between article, article_comment and comment must exist — that can be optimized to JOINs.

    The main change however, is that you don’t need a correlated sub-query (referencing comment c in the sub-query), so the JOIN between article_user_read and article can be pushed to the main query.

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

Sidebar

Related Questions

I have a query that looks a bit like this: SELECT weekEnd, MAX(timeMonday) FROM
In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
I've got a query that looks a bit like this: select records.id, contacts.name +
So I have this query: select ens_use_new_models_bit from cfo_transaction inner join dbo.cfo_trans_entity_rel on te_tr_transaction_id=tr_transaction_id
This query works great: var pageObject = (from op in db.ObjectPermissions join pg in
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although
I have a query that looks a bit like this (note: the actual query
This query SELECT FirstName, LastName, NCAAStats.AccountId, College_Translator.school_name, StatTypeId, COUNT(*) AS 'Count' FROM NCAAstats INNER
This query works: select p.Nombre as Nombre, c.Nombre as Categoria, s.Nombre as Subcategoria FROM
Need a bit of help with this query Any way you guys can help?

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.