[HyperDB] is_write_query too strict

Gabriel Koen gkoen at corp.mail.com
Fri Jul 30 17:14:28 UTC 2010

Came across an issue where only the first query (autoload options) was being
sent to the read slave(s). Turns out a couple plugins had the syntax 'SHOW
TABLES LIKE...' which HyperDB thought was a read query, since it didn't
match 'SELECT' as the first word. Made a quick fix for what I think are some
common read statements to db.php:

function is_write_query( $q ) {
		$pattern = '/^\s*(SELECT|SHOW|DESCRIBE|EXPLAIN)\s+/i';
		return (preg_match($pattern, $q)) ? false : true;

As you can see my regex-fu is weak, I spent a good 40 minutes trying to
negatively match those words. Gave up, instead positively match them and
then return true if there's *not* a match.


More information about the HyperDB mailing list