dbTalk Databases Forums  

Make join more efficient

comp.databases.mysql comp.databases.mysql


Discuss Make join more efficient in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Joe Hesse
 
Posts: n/a

Default Make join more efficient - 03-21-2011 , 11:55 AM






I have a query that involves joining 4 tables. Each of the tables has
many columns but my query involves a small subset of the columns from
each of the 4 tables.

Would it be more efficient if I created 4 temporary tables, each
containing the columns of interest and then doing the join on the
temporary tables?

My original query is fast enough, I just want to be kind to the MySQL
server.

Thank you,
Joe

Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Make join more efficient - 03-21-2011 , 02:05 PM






On 3/21/2011 1:55 PM, Joe Hesse wrote:
Quote:
I have a query that involves joining 4 tables. Each of the tables has
many columns but my query involves a small subset of the columns from
each of the 4 tables.

Would it be more efficient if I created 4 temporary tables, each
containing the columns of interest and then doing the join on the
temporary tables?

My original query is fast enough, I just want to be kind to the MySQL
server.

Thank you,
Joe
Why fix something that isn't broken?

Think about it - you'll make 4 queries to create temporary tables,
selecting all rows and the columns you want from the permanent tables.

Then you'll make another query from the temporary tables, selecting
specific rows.

How can this be faster than selecting those columns from a subset of the
rows in each table?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #3  
Old   
Luuk
 
Posts: n/a

Default Re: Make join more efficient - 03-21-2011 , 02:23 PM



On 21-03-2011 21:05, Jerry Stuckle wrote:
Quote:
On 3/21/2011 1:55 PM, Joe Hesse wrote:
I have a query that involves joining 4 tables. Each of the tables has
many columns but my query involves a small subset of the columns from
each of the 4 tables.

Would it be more efficient if I created 4 temporary tables, each
containing the columns of interest and then doing the join on the
temporary tables?

My original query is fast enough, I just want to be kind to the MySQL
server.

Thank you,
Joe

Why fix something that isn't broken?

Think about it - you'll make 4 queries to create temporary tables,
selecting all rows and the columns you want from the permanent tables.

Then you'll make another query from the temporary tables, selecting
specific rows.

How can this be faster than selecting those columns from a subset of the
rows in each table?

in stead of being 'kind to his server', he wants to be RUDE/MEAN

--
Luuk

Reply With Quote
  #4  
Old   
Erick T. Barkhuis
 
Posts: n/a

Default Re: Make join more efficient - 03-21-2011 , 02:34 PM



Joe Hesse:

Quote:
Would it be more efficient if I created 4 temporary tables, each
containing the columns of interest and then doing the join on the
temporary tables?
I would expect not, but only someone who knows what's actually going on
inside the MySql engine can tell (and you didn't mention the engine
you're using).

But...apparently you have the database and sufficient data (so it might
matter at all). I'm curious: what was the result when you tried the
alternative method with four temporary tables, and compared it with the
obvious join?


--
Erick

Reply With Quote
  #5  
Old   
John Nagle
 
Posts: n/a

Default Re: Make join more efficient - 03-23-2011 , 01:32 AM



On 3/21/2011 10:55 AM, Joe Hesse wrote:
Quote:
I have a query that involves joining 4 tables. Each of the tables has
many columns but my query involves a small subset of the columns from
each of the 4 tables.

Would it be more efficient if I created 4 temporary tables, each
containing the columns of interest and then doing the join on the
temporary tables?

My original query is fast enough, I just want to be kind to the MySQL
server.

Thank you,
Joe
The MySQL engine is reasonably smart about joins. Considerable
optimization takes place. The system tries hard to use indexes
to make the search fast.

Submit your query with the word EXPLAIN in front of the query.
This tells you how the database system will do your query. Read
the documentation for EXPLAIN to understand the output. It's
important that the EXPLAIN result not say "ALL" for some field;
that means a linear search that looks at all entries in a table,
which is usually slow.

John Nagle

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.