As database tables grow bigger, you want to consider table sharding. I am using symfony2, so I would like to ask, how does symfony2 split databases and tables... As database tables grow bigger, you want to consider table sharding. I am using symfony2, so I would like to ask, how does symfony2 split databases and tables...
Reply content:
As database tables grow bigger, you want to consider table sharding. I am using symfony2, so I would like to ask, how does symfony2 split databases and tables...
Let's start with the following:
If the database supports (such as MySQL or PostgreSQL), we recommend that you directly use the database's partitioning. if you cannot solve your needs, you can:
Use event listening to modify or dynamically register database connection instances based on the user ID or other Database Sharding conditions.
Or simply, register multiple connected instances and define a helper for the desired instance, for example, Database Sharding by user ID:
// (1) in app/config. yml: # define the connection of each database // (2) in the controller: private function getManager () {$ user = $ this-> getUser (); // get the current user $ shardId = null! ==$ User? $ User-> getId () % 4: 0; // 0, 1, 2, 3 A total of four libraries return $ this-> getDoctrine () -> getManager (sprintf ('Shard _ % s', $ shardId);} // (3) in Business Action: public function someAction () {$ om = $ this-> getManager (); // The current user's database is connected to the instance //...}
In your business code, you have to consider the integrity of your business after partitioning.
Different from traditional