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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:49:25+00:00 2026-06-15T14:49:25+00:00

First of all i have the following table structures. Table Document ## DocID ##

  • 0

First of all i have the following table structures.

Table Document
  ## DocID ##  ## DocName## ## DuplicateID ##
      1              Doc1        null
      2              Doc2        null
      3              Doc3        null
      4              Doc4         1

Table FolderTree
  ## FolderID ##  ## MemberDocID ##
       1                1
       1                2
       1                3

I have index on DocID, DuplicateID and MemberDocID and FolderID

My Query is this :

SELECT d.* 
from Document d, FolderTree f 
WHERE (d.DocID = f.MemberDocID or d.DuplicateID = f.MemberDocID) and f.FolderID = 1 
GROUP BY d.DocID ;

So basically i want to retrieve all documents from Folder with id 1 and also its duplicate documents from the table. The group by is used to maintain uniqueness of record that no document will be retrieve twice.

This query is working fine but in large volume of records it getting slower.Here is the explain output.


| select type | table | type | possible_keys | key    | rows  |   extra         |

   simple        d     range   PRIMARY,...    PRIMARY   83168   Using temporary..
   simple        f     All     DuplicateIDInx Null      108787  Using join buffer

What concerns me is that the table f does not use the index on DuplicateID.
My question is, Why is it so? Can somebody enlighten me on this matter.
Im using Mysql 5.x
Thanks 🙂

  • 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-06-15T14:49:26+00:00Added an answer on June 15, 2026 at 2:49 pm

    Try this version:

    SELECT d.* 
    FROM Document d 
    WHERE EXISTS
          ( SELECT *
            FROM FolderTree f 
            WHERE ( d.DocID = f.MemberDocID OR d.DuplicateID = f.MemberDocID )
              AND f.FolderID = 1 
          ) ;
    

    and this one (edited):

    SELECT d.* 
    FROM ( SELECT 1 AS FolderID
         ) AS Parameter
      CROSS JOIN 
         Document d 
    WHERE EXISTS
          ( SELECT *
            FROM FolderTree f 
            WHERE f.MemberDocID = d.DocID
              AND f.FolderID = Parameter.FolderID
          ) 
       OR EXISTS
          ( SELECT *
            FROM FolderTree f 
            WHERE f.MemberDocID = d.DuplicateID
              AND f.FolderID = Parameter.FolderID
          ) ;
    

    I would also add a compound (composite) index on FolderTree (FolderID, MemberDocID).

    If you haven’t already an index on Document (DuplicateID), add one as well.

    The extra requirement could probably be better solved by writing the query in a stored procedure with a parameter.

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

Sidebar

Related Questions

all! I have the following problem: I have 2 simple tables. The first one,
First of all let me tell you that i have read the following questions
Hi all i have the following table called student in SQLite database. this is
I have the following structure: <table> <tr> <td>first</td> <td class=price>__</td> <td><input type=text class=quantity></td> <td
First of all I have many Django instances setup and running like this. In
First of all I have searched many times in this forum but none is
First of all I have to say I am new to iOS development. My
First of all i have frames on my SD Card and frames are there
First of all i have to clear few things 1.This is not spam group
So first of all I have such image (and ofcourse I have all points

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.