I have been using oracle and mysql top 10 queries view to proactively diagnose slow queries and optimize them for next release. But sometimes the same query will have different plans depending on data set its executed on. So if you have a sharded database then a query like select * from files where file_path=? and customer_id=? would run fine locally and for most shards but not for some shards.
To diagnose live production issues or issues that occurred in past it would be good to know some query context and one trick to do this is to annotate your queries with context information in comments.
public static String annotateSql(String contextInfo, String sql) {
return " /*" + contextInfo + "*/" + sql;
}
now your top queries report over last day would have top queries along with context info. This context info can be customerId or shard id.
To diagnose live production issues or issues that occurred in past it would be good to know some query context and one trick to do this is to annotate your queries with context information in comments.
public static String annotateSql(String contextInfo, String sql) {
return " /*" + contextInfo + "*/" + sql;
}
now your top queries report over last day would have top queries along with context info. This context info can be customerId or shard id.
Comments
Post a Comment