twmas52712 Posted July 9, 2009 Share Posted July 9, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/165319-howto-optimize-a-sequence-of-reaaaly-long-sql-statement/ Share on other sites More sharing options...
trq Posted July 9, 2009 Share Posted July 9, 2009 Ive no idea how FQL works, but this is perfectly valid sql. SELECT app_id from applications WHERE app_id >= 1 && app_id <= 2000; Quote Link to comment https://forums.phpfreaks.com/topic/165319-howto-optimize-a-sequence-of-reaaaly-long-sql-statement/#findComment-871838 Share on other sites More sharing options...
twmas52712 Posted July 9, 2009 Author Share Posted July 9, 2009 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...:-\ Quote Link to comment https://forums.phpfreaks.com/topic/165319-howto-optimize-a-sequence-of-reaaaly-long-sql-statement/#findComment-871843 Share on other sites More sharing options...
trq Posted July 9, 2009 Share Posted July 9, 2009 I still don't see anything wrong with my query. Quote Link to comment https://forums.phpfreaks.com/topic/165319-howto-optimize-a-sequence-of-reaaaly-long-sql-statement/#findComment-871846 Share on other sites More sharing options...
twmas52712 Posted July 9, 2009 Author Share Posted July 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165319-howto-optimize-a-sequence-of-reaaaly-long-sql-statement/#findComment-871851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.