performance effect of joining tables from different databases

北战南征 提交于 2019-12-05 11:32:26

问题


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...


回答1:


I can speak from recent personal experience. I have some old mysql queries in some PHP code that worked fine with a relatively small database, but as it grew the query got slower and slower.

I have freeradius running mysql in its own database along with another management php app that I wrote. The freeradius table is > 1.5 million rows. I was attempting to join tables from my app's database to the freeradius database. I can say for sure 1.5 million rows is too many. Running some queries locked up my app altogether. I ended up having to re-write portions of my php app to do things differently (ie not joining 2 tables from different database). I also indexed the radius accounting table on some key fields and optimized some queries (mysql EXPLAIN statement is wonderful to help with this). Things are MUCH faster now.

I will definitely be hesitant to join 2 tables from different databases in the future unless really really necessary.




回答2:


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.



来源:https://stackoverflow.com/questions/3259530/performance-effect-of-joining-tables-from-different-databases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!