MySQL Forums
Forum List  »  Optimizer & Parser

Three(or Four)-Way Joins
Posted by: Malcolm Wardlaw
Date: August 11, 2009 07:10PM

I have some data that's separated out across multiple tables that I need to join into a single query. The tables are all 1-to-1 unique to each other with a single identifier, and the tables contain an identical number of observations, i.e. no table contains an identification key that another table does not. The reason they are spread across multiple tables is because of size limitations. There are over 3000 variables unique to each key, and normalizing it further does not resolve the problem. Size constraints require separating the columns into groups.

Here's my question, I want to create a query whereby I join a table containing a small number of sub identifiers "X" to a select group of variables across several tables that are linked by the same 1-to-1 key "K". I should mention that there are over a million rows in each of these tables.

So:

Table 1("X") <--> Table 2("K, X, A") <--> Table 3("K, B") <--> Table 4("K, C")


With Table 1 being only around 500 rows and Table 2,3,4 being over a million.


My question is on how to form the query in the most efficient way possible. I'm guessing that the order in which MySQL chooses to join the tables and select from them is critically important.

One more thing, this type of query is going to be issued quite a bit using "X", so if there is any benefit to permanently inserting "X" into Tables 3&4 (in this example) I can do that. Also, "X" is indexed in Table 2 (and again, could be in 3&4).

Options: ReplyQuote


Subject
Views
Written By
Posted
Three(or Four)-Way Joins
3761
August 11, 2009 07:10PM
2119
August 12, 2009 08:35PM
1863
August 12, 2009 09:31PM
1966
August 13, 2009 12:16AM
1946
August 13, 2009 12:26PM
2642
August 13, 2009 10:34PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.