Facebook Releases FQL.multiquery

If you’re a developer you’ll know that one of the most important things to making efficient code is to reduce your code’s dependency on SQL queries. Rather than running 1,000 SQL “INSERT” queries for 1,000 individual items for example, it’s better to batch those items into a single “INSERT” statement. There are other methods that can be used to improve query performance as well including general query batching in which multiple queries are batched into a single request.

Last night Facebook announced a pretty cool upgrade which is FQL.multiquery. The service enables developers to batch multiple queries into a single request. Additionally, the new service allows for subqueries by reference. As Julie Tung writes on the Facebook developer blog, queries can batched into an associative array. For example:

$queries = {
  "user_stream":"SELECT post_id, actor_id, message FROM stream
    WHERE source_id=UID",
  "actor_info":"SELECT uid, name, pic_square FROM user
    WHERE uid IN (SELECT actor_id FROM #user_stream)"


Whether you are looking to reduce the number of FQL calls that you are making, or just looking to create cleaner code, FQL.multiquery is an efficient service for developers. I haven’t had the opportunity to test out the FQL.multiquery service but I’ll most definitely take advantage of this on future apps.

And yes, if you’re wondering that’s an image of the Matrix. That’s what programming in real life looks like.