Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

performance effect of joining tables from different databases

I have a web site using a database named lets say "site1". I am planning to put another site on the same server which will also use some of the tables from "site1".

So should I use three different databases like "site1" (for first site specific data), "site2" (for second site specific data), and "general" (for common tables). In which there will be join statements between databases general and site1 and site2. Or should I put all tables in one database?

Which is the best practice to do? How performances differ in each situation? I am using MySQL. So how is the situation especially for MySQL?

Thanks in advance...

like image 512
Mucahit Sancar Kahveci Avatar asked Jul 15 '10 20:07

Mucahit Sancar Kahveci


People also ask

Can we join tables from two different databases?

SQL Server allows you to join tables from different databases as long as those databases are on the same server. The join syntax is the same; the only difference is that you must fully qualify table names.

Are joins more efficient than WHERE?

“Is there a performance difference between putting the JOIN conditions in the ON clause or the WHERE clause in MySQL?” No, there's no difference. The following queries are algebraically equivalent inside MySQL and will have the same execution plan.

Do joins slow down query?

Joins: If your query joins two tables in a way that substantially increases the row count of the result set, your query is likely to be slow. There's an example of this in the subqueries lesson. Aggregations: Combining multiple rows to produce a result requires more computation than simply retrieving those rows.


1 Answers

From the performance point of view, there won't be ANY difference. Just keep your indexes in place and you will not notice whether you are using single DB or multiple DBs.

Apart from performance, there are 2 small implications that I can think of: 1. You can not have foreign keys across DBs. 2. Partitioning tables in DB based on their usage or based on applications can help you manage permissions in easy way.

like image 147
Gaurav Phapale Avatar answered Sep 22 '22 12:09

Gaurav Phapale