Join Performance

Question:
I’m wondering whether it would be faster to join a large table to a small table by placing the large table on the left side or theright side of the join.

Answer:
Every database optimizer operates differently, and even the queries posed to the same database will choose a different optimization path depending upon the distribution of the data involved. Database serversmaintain certain statistics about the data in each table, and thosestatistics play an important role. In other words, there’s no easy answer to your question short of trying both methods with your particular data.

If your server vendor has documented the operation of its optimizer, you may find some clues about what to expect. If your server lets you see the execution plan, you can determine which indexes it intends to use and whether or not it will have to create temporary tables to complete the query (temporary tables can add to the execution time in some cases). You then can use this information to compare with yourexpectations of the optimal plan and adjust your query to try to “force”the optimizer to do it another way.

Again, this is very table-specific, so the results you find for any two tables will not necessarily apply the next time you have a similar query, because the tables’ statistics may have changed.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: