## Bug Number Seven

One of my favorite Facebookers, Ari Steinberg, just resolved bug #7 in Facebook's bugzilla.

LIMIT, OFFSET, and ORDER BY are all implemented.
docs at http://developers.facebook.com/documentation.php?v=1.0&doc=fql are updated. enjoy guys, and let me know if there are any problems with it. tyler, don't go too crazy with it...keep in mind that order by in particular can be an expensive operation (but do try it out - when used in the appropriate ways it could lead to a savings)

When used correctly, LIMIT, OFFSET and ORDER BY can really make writing application-level code much easier, because you're offloading a lot more onto Facebook. For example, instead of fetching an entire list of people (presumably friends) and then sorting by their name, you can perform a query like:
SELECT uid,name FROM user WHERE uid IN (SELECT uid1 FROM friend WHERE uid2 = $UID) ORDER BY name This query will fetch an alphabetically sorted list of$UID's friends along with their uid, preventing any sorting you might need to do.

Make sure you check the FQL documentation for which "columns" are keyed such that you perform the most optimal queries possible. Of course, you should already make sure you're selecting as often as possible on keyed "columns" in FQL, but when you're offloading large amounts of sorting onto Facebook's API servers, it becomes more important to form optimal queries to make sure that you can fetch data from Facebook as fast as possible and render your application's pages.

Another fun query that becomes more fun with ORDER BY is fetching events for a particular user:
SELECT eid, name FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid = \$UID) ORDER BY name

This of course is using ORDER BY on the event.name "column" which is not keyed so it will theoretically perform slower than the example above, but it's far less likely that a user will have thousands of events versus thousands of friends, so the real-world performance hit will be negligible.

As as side note, Ari was on stage with me at Graphing Social, helping me give the Facebook App Development 101 workshop a few weeks ago. You can regularly find him cruising through bugzilla and every so often on the #facebook channel on Freenode.