Is it possible to set up different indexing on a read only slave, from on the master? Basically, this seems like it makes sense given the different requirements of the two systems, but I want to make sure it will work and not cause any problems.
Master vs Slave Simply, a master is a device or a process that controls other devices or processes and a slave is a device or a process that is controlled by another device or a process.
If there is a choice between multiple indexes, MySQL normally uses the index that finds the smallest number of rows (the most selective index). If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to look up rows.
The master has a thread, called the dump thread, that continuously reads the master's binlog and sends it to the slave. The slave has a thread, called the IO thread, that receives the binlog that the master's dump thread sent, and writes it to a file: the relay log.
The master-slave database architecture can be used for scaling out your application by distributing your data load across multiple databases.
I believe so. After replication is working, you can drop the indexes on the slave and create the indexes you want and that should do it. Since MySQL replicates statements and not data (at least by default), as long as the SQL necessary to insert or update or select from the table doesn't need to change, it shouldn't notice.
Now there are obviously downsides to this. If you make a unique key that isn't on the master, you could get data inserted on the master that can't be inserted on the slave. If an update is done that uses an index it may run fast on the master but cause a table scan on the slave (since you don't have whatever index was handy).
And if any DDL changes ever happen on the master (such as to alter an index) that will be passed to the slave and the new index will be created there as well, even though you don't want it to.
For sure. I do it all the time. Issues I've run into:
FORCE/USE/IGNORE INDEX
in SELECTS
will error outALTER
statments on the master can break replicationUNIQUE
indexes, any INSERT... ON DUPLICATE KEY
, INSERT IGNORE
or REPLACE
statments will cause extreme data drifting / divergenceIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With