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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:00:17+00:00 2026-05-24T10:00:17+00:00

I run the following query on my database : SELECT e.id_dernier_fichier FROM Enfants e

  • 0

I run the following query on my database :

SELECT e.id_dernier_fichier
FROM Enfants e JOIN FichiersEnfants f
ON e.id_dernier_fichier = f.id_fichier_enfant

And the query runs fine. If I modifiy the query like this :

SELECT e.codega
FROM Enfants e JOIN FichiersEnfants f
ON e.id_dernier_fichier = f.id_fichier_enfant

The query becomes very slow ! The problem is I want to select many columns in table e and f, and the query can take up to 1 minute ! I tried different modifications but nothing works. I have indexes on id_* also on e.codega. Enfants has 9000 lines and FichiersEnfants has 20000 lines. Any suggestions ?

Here are the info asked (sorry not having shown them from the beginning) :

Table FichiersEnfants
Table Enfants
Index Enfants
Explain Query 1
Explain Query 2

  • 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-24T10:00:18+00:00Added an answer on May 24, 2026 at 10:00 am

    The difference in performance is possibly due to e.id_dernier_fichier being in the index used for the JOIN, but e.codega not being in that index.

    Without a full definition of both tables, and all of their indexes, it’s not possible to tell for certain. Also, including the two EXPLAIN PLANs for the two queries would help.

    For now, however, I can elaborate on a couple of things…

    If an INDEX is CLUSTERED (this also applies to PRIMARY KEYs), the data is actually physically stored in the order of the INDEX. This means that knowing you want position x in the INDEX also implicity means you want position x in the TABLE.

    If the INDEX is not clustered, however, the INDEX is just providing a lookup for you. Effectively saying position x in the INDEX corresponds to position y in the TABLE.

    The importance here is when accessing fields not specified in the INDEX. Doing so means you have to actually go to the TABLE to get the data. In the case of a CLUSTERED INDEX, you’re already there, the overhead of finding that field is pretty low. If the INDEX isn’t clustered, however, you effectifvely have to JOIN the TABLE to the INDEX, then find the field you’re interested in.

    Note; Having a composite index on (id_dernier_fichier, codega) is very different from having one index on just (id_dernier_fichier) and a seperate index on just (codega).

    In the case of your query, I don’t think you need to change the code at all. But you may benefit from changing the indexes.

    You mention that you want to access many fields. Putting all those fields in a composite index is porbably not the best solution. Instead you may want to create a CLUSTERED INDEX on (id_dernier_fichier). This will mean that once the *id_dernier_fichier* has been located, you’re already in the right place to get all the other fields as well.

    EDIT Note About MySQL and CLUSTERED INDEXes

    13.2.10.1. Clustered and Secondary Indexes

    Every InnoDB table has a special index called the clustered index where the data for the rows is stored:

    • If you define a PRIMARY KEY on your table, InnoDB uses it as the clustered index.
    • If you do not define a PRIMARY KEY for your table, MySQL picks the first UNIQUE index that has only NOT NULL columns as the primary key and InnoDB uses it as the clustered index.
    • If the table has no PRIMARY KEY or suitable UNIQUE index, InnoDB internally generates a hidden clustered index on a synthetic column containing row ID values. The rows are ordered by the ID that InnoDB assigns to the rows in such a table. The row ID is a 6-byte field that increases monotonically as new rows are inserted. Thus, the rows ordered by the row ID are physically in insertion order.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I run the following query in SQL Server 2000 Query Analyzer: BULK INSERT
How do I run the following WMI query, both programmatically to and as a
When I try to run the following code (from the REPL) in Clojure: (dotimes
I am trying to run the following. <?php $db = mysqli_connect(localhost,user,pw) or die(Database error);
I've got the following function: public function already_tweeted($tweet){ return mysql_num_rows(mysql_query(SELECT * FROM `retweeted` WHERE
When I run the following, PowerShell hangs waiting for the dialog to close, even
When I run the following code to test copying a directory, I get a
When I run the following test in Gallio's Icarus it passes, but when I
I want to run the following code: ajaxUpdate(10); With a delay of 1 second
I'm trying to run the following commands: replace -x must A2input.txt replace -x a

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.