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

  • Home
  • SEARCH
  • 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 8136365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:44:27+00:00 2026-06-06T10:44:27+00:00

I have 2 table t1 -> t2 (common one to many relationship) with 140.000

  • 0

I have 2 table t1 -> t2 (common one to many relationship) with 140.000 records on table t2 reffering 50.000 records on t1, foreing key some times is null (no parent).

CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
KEY `name_idx` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=125666 DEFAULT CHARSET=utf8

CREATE TABLE `t2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`t1_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `t1_id_idx` (`t1_id`)
CONSTRAINT `t1_fk` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=125666 DEFAULT CHARSET=utf8

This query running on 15 seconds:

SELECT * FROM t2
LEFT JOIN t1 ON t2.t1_id = t1.id
ORDER BY t1.name ASC
LIMIT 10; 

This query running on 0.5 seconds:

SELECT * FROM t2
LEFT JOIN t1 ON t2.t1_id = t1.id
WHERE t1.name <> 'any not found value'
ORDER BY t1.name ASC
LIMIT 10;

Can any body explain to me why this occurs?

Obs: Edited.

News:

This query running on 0.06 seconds: (WHAT’S CHANGE? inner join!!)

SELECT * FROM t2
INNER JOIN t1 ON t2.t1_id = t1.id
ORDER BY t1.name ASC
LIMIT 10; 

but above query does not is a solution for my, in my case t2.t1_id can be null some times.

Any Idea??

News:

Running explain with left and inner join:

Mysql show: Using temporary; Using filesort; Rows: 140.000

With Inner Join:

Mysql show: Using Where; Rows: 8

  • 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-06T10:44:28+00:00Added an answer on June 6, 2026 at 10:44 am

    Solved!

    The Problem is on order by, when using order by mysql create a temporaty file (Explain…Using Temporary), this temporary file is too big causing the lag.

    Tips:

    • Avoid Using Tempoaray
    • When Using temporary don’t load much data.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some tables. These tables all have one column in common called 'classified_id':
I have many tables.But there are Two columns common in each table. They are
I have the One-to-Many bidirectional relationship below. After generating the crud actions with a
I have two entities with a Unidirectional Many-to-One mapping. Here's Product : use Doctrine\Common\Collections\ArrayCollection;
I have a many-to-many relationship between a list of codes and a main table
I have a table that contains common entries in two columns. For Example: Column1
I have a pretty common layout issue that I have traditionally used a table
I have a Client/Server application, where the Client and Server have some common tables
I have two tables, related by a common key. So TableA has key AID
I have 2 entities, A and B that have a many to many relationship.

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.