Jump to content

Howto Optimize a Sequence of Reaaaly Long SQl Statement


twmas52712

Recommended Posts

Hi All,

 

I'm working on a facebook app, and I'm using Facebook's FQL API (Facebook's mySQL equivalent) to gather a list of application ID's similar to that which can be found at developeranalytics.com.

 

Problem: Facebook requires all queries to be indexable. In other words, I can not do SELECT app_id from applications WHERE 1. Instead, I have to do SELECT app_id from applications WHERE app_id=1 OR app_id=2 OR app_id=3...etc.

 

Since facebook timesout after 30 seconds, I have to package a thousand of these queries with 2000 OR statements in each query.

 

I'm wondering if I could get some insight on any and all ways I can optimize this approach.

 

Thanks!

The problem with that statement is that it isn't indexable.  Here's FB's explanation:

 

"Another key restriction is that your query must be indexable. You cannot, for example, just specify WHERE 1 as your entire WHERE clause - in general your query must be limited to working on a specific, enumerable set of IDs (the FQL Tables show which columns are indexable). If you do not satisfy this requirement you will get back an error code 604. "

 

Basically the WHERE statement has to either contain an equivalence or IN...:-\

I don't completely understand the reasoning behind them limiting this functionality, but I imagine that statement isn't valid since you could just as easiliy do WHERE app_id>=0 && app_id<=infinity to achieve the same return as WHERE 1, which they don't want.

 

I'm a beginner at SQL, so I don't understand the innerworkings of how queries are processed.  From my tests, it's clear that having such a large number of OR statements slows the query down significantly.  I'm just wondering if there is a possibility that I'm not considering.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.