Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL Server
Expertise: Beginner
Mar 24, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Join Performance

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 the right side of the join.

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 servers maintain certain statistics about the data in each table, and those statistics 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 your expectations 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.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date