News for hackers. Stuff that matters.
Re:See Twitter's SQL. by ojbyrne on Sunday July 06, 2008 @10:01PM (#238209)
It seems like twitter is taking fail to new levels every day.
Re:See Twitter's SQL. by boredguy8 on Monday July 07, 2008 @02:54AM (#238390)
I hate to upmod something so derisive, but when you have truth on your side...
Re:See Twitter's SQL. by IsaacSchlueter on Sunday July 06, 2008 @10:11PM (#238220)
They really weren't kidding when they said that they'd mistakenly built it as a CMS instead of as a messaging platform.
Re:See Twitter's SQL. by shimon on Sunday July 06, 2008 @10:51PM (#238247)
The title pretty much covers it. Twitter is more like an IM network or email list service than like a typical database-backed webapp; a relational database is just the wrong platform for large-scale messaging.
Re:See Twitter's SQL. by IsaacSchlueter on Monday July 07, 2008 @03:05AM (#238393)
I agree, of course. But before the twitter bashing starts, I wanna say, I don't think that they foresaw messaging being the primary use-case. After all, you already have IM and SMS and a gillion other messaging systems. Twitter was conceived as a blogging platform, but smaller. Messaging was how you would post to twitter, not what you would do with twitter.

Of course, that was wrong. (How annoying are the twitter users who actually "answer the question: What are you doing?") But that kind of insight only comes out once your product is exposed to real humans. It's obvious, but only in hindsight.

As it turns out, when you make LiveJournal really small, you get Jabber.

Re:See Twitter's SQL. by jonknee on Sunday July 06, 2008 @11:22PM (#238268)
And sadly it's not even close to large-scale yet. They only have a few hundred thousand users.
Re:See Twitter's SQL. by immad on Sunday July 06, 2008 @11:02PM (#238257)
Did anyone get a screenshot before they disabled it?
Re:See Twitter's SQL. by Jax on Monday July 07, 2008 @01:45AM (#238357)
Yeah... screenshot please!!! And I'm also wondering how this ink was found
Re:See Twitter's SQL. by thomasswift on Monday July 07, 2008 @04:12AM (#238425)
here's a screenshot. i didn't include the table stuffs. http://skitch.com/thomasswift/xef3/twitter
Re:See Twitter's SQL. by dcurtis on Monday July 07, 2008 @01:13PM (#238827)
What are they using to analyze the queries like this? It looks pretty useful.
Re:See Twitter's SQL. by jzell on Monday July 07, 2008 @01:42PM (#238870)
They are using query reviewer

http://code.google.com/p/query-reviewer/

Re:See Twitter's SQL. by socksandsandals on Sunday July 06, 2008 @11:35PM (#238279)
I dimed this out and had it disabled. Twitter doesn't need people poking through its' SQL. Imagine what we'd find if we were poking through yours...
Re:See Twitter's SQL. by amarcus on Sunday July 06, 2008 @10:03PM (#238210)
these queries are not optimised at all. first of all, every page gives of MySQL warnings...and second, there are alot of SELECT count(*)...instead of SELECT count(1). This may not seem like it would increase speed alot but given the number of users and the amount of times that query is executed, it will speed up twitter by a bit. There are a few other things that i have noticed...they should really clean up their sql
Re:See Twitter's SQL. by sharksandwich on Sunday July 06, 2008 @10:26PM (#238230)
The search page looks particularly sloppy. Searching 'john' yields 27 queries, including a number that look redundant

Grabbing the users

SELECT * FROM `users` WHERE (users.id in (<list of user ids>))

followed by queries for each user id in that list

SELECT * FROM `users` WHERE (`users`.`id` = <user id>)

Maybe there's a reason for doing that, but if there is, I can't think of it

Re:See Twitter's SQL. by gaius on Monday July 07, 2008 @03:04AM (#238392)
Most likely whoever wrote it cut their teeth on MySQL 4.0 or earlier which didn't have subselects.

They don't do this so much now, but back in the day (mid-late 90s) MySQL documentation was notorious for glossing over why they didn't have features. Foreign keys were "too slow". Transactions were "too slow", etc. If you need to rollback, store the previous values in memory in your own code, they told everyone (then quietly added the feature and changed the docs).

[deleted]
Re:See Twitter's SQL. by senthil_rajasek on Sunday July 06, 2008 @11:26PM (#238270)
Why roundtrip to the db for the same user info again? I have seen this type of behavior in data access "frameworks"... the optimization would be to reduce the roundtrip to the db...
Re:See Twitter's SQL. by jrockway on Monday July 07, 2008 @12:45AM (#238328)
s/frameworks/poorly-written frameworks/.

It's really amazing what poorly-written frameworks have done to the minds of people. When I teach classes on DBIx::Class (the Perl ORM), my students are shocked that $foo->bar->baz actually generates the SQL to follow the two relations as opposed to the "easy" "get list of results, then run query on each result, then return an array...". Actually, $foo->bar->baz, by itself, doesn't touch the database. The database is only contacted when you actually try to get information out of the result object. (And of course, the database is only queried once.)

Re:See Twitter's SQL. by there on Sunday July 06, 2008 @11:09PM (#238260)
Re:See Twitter's SQL. by jey on Monday July 07, 2008 @12:37AM (#238319)
Good, because that would be really pathetic to not perform the simplest dead code elimination.
Re:See Twitter's SQL. by amarcus on Monday July 07, 2008 @12:39AM (#238322)
Only for MyISAM tables...its a different story with Innodb: http://www.mysqlperformanceblog.com/2006/12/01/count-for-inn...
Re:See Twitter's SQL. by neilc on Monday July 07, 2008 @01:57AM (#238364)
Not AFAICS; count( * ) and count( 1 ) are trivially equivalent, and this doesn't depend on the storage engine being used. It is true that count( * ) without a WHERE clause is much faster in MyISAM than in Innodb (or Postgres), but that is a different optimization (count( * ) => metadata lookup, not count( 1 ) => count( * )).
Re:See Twitter's SQL. by fendale on Monday July 07, 2008 @07:20AM (#238491)
Mentioned elsewhere in this thread, but count() and count(1) mean basically the same thing and are equivalent.

There is a nice optimisation in MYISAM table that makes count() from table <with no where clause> almost instant as its stored as meta-data on the table - in InnoDB, Oracle or Postgres this optimisation doesn't exist ...

Re:See Twitter's SQL. by wallflower on Sunday July 06, 2008 @10:17PM (#238225)
Boy this demystifies the social animal that is twitter. The test database is very small.
Re:See Twitter's SQL. by ashleyw on Monday July 07, 2008 @10:36AM (#238617)
Wish I'd taken a screenshot now.

It was basically a semi-transparent box in the top left of the screen which showed you the query as well as which DB served the data (for me they came from db007, and the friend data from some shards), and two links, one for a popdown box with info about the query, and another with the file trace infomation.

Quite intresting, shame they have removed it.

Re:See Twitter's SQL. by dmoney on Sunday July 06, 2008 @10:53PM (#238248)
I give up. How do I enable the analyzer?
Re:See Twitter's SQL. by immad on Sunday July 06, 2008 @10:59PM (#238253)
I think you missed it. It seems to have disappeared.
Re:See Twitter's SQL. by jamesjyu on Sunday July 06, 2008 @10:21PM (#238226)
Seems like this was a mistake by twitter: http://getsatisfaction.com/twitter/topics/staging_twitter_co...

Some profile pages are being linked to the staging server.

Re:See Twitter's SQL. by jamesjyu on Sunday July 06, 2008 @10:33PM (#238237)
Okay it's down now. They put up the whale page on staging and probably just disabled the plugin.
Re:See Twitter's SQL. by bluelu on Monday July 07, 2008 @12:18PM (#238758)
Thanks to Twitter's chief architect for giving me a good laugh :)
Re:See Twitter's SQL. by st3fan on Sunday July 06, 2008 @10:10PM (#238219)
Wouldn't a working service be more interesting than this thing? Or are they expecting us to fix their code?
Re:See Twitter's SQL. by wallflower on Sunday July 06, 2008 @09:46PM (#238202)
Too bad we can't run 'explain plan' on them :)
Re:See Twitter's SQL. by ojbyrne on Sunday July 06, 2008 @10:09PM (#238217)
Explain Plan? Isn't that oracle? I ask because there is an "EXPLN" link that gives you what I think you're asking for.
Re:See Twitter's SQL. by wallflower on Sunday July 06, 2008 @10:21PM (#238227)
Saw that after I posted that, thanks.
Re:See Twitter's SQL. by newt0311 on Monday July 07, 2008 @01:01AM (#238332)
postgres has something similar. Pretty nice for benchmarking and optimizing queries.
Re:See Twitter's SQL. by wensing on Monday July 07, 2008 @11:28AM (#238700)
Postgres: EXPLAIN ANALYZE.
Re:See Twitter's SQL. by 0x44 on Monday July 07, 2008 @08:45AM (#238523)
In MySQL it's just "EXPLAIN <YOUR QUERY>".
Re:See Twitter's SQL. by Jax on Monday July 07, 2008 @01:43AM (#238355)
Before being acuired by Google, does anyone know Jaiku's uptime and other stats? Were they too this bad as Twitter?
Re:See Twitter's SQL. by silpol on Tuesday July 08, 2008 @12:09AM (#239553)
uptime was much better, and reaction was much quicker and to the point. with recent switchover to Google infra they are almost non-stop -- only Google is not that stupid to pay for your messaging ;)
Re:See Twitter's SQL. by bdotdub on Sunday July 06, 2008 @10:06PM (#238215)
Yeesh. This does not seem safe.

At least maybe (big maybe) some good will come of this?

Re:See Twitter's SQL. by bprater on Sunday July 06, 2008 @09:35PM (#238193)
Mmmm... this should be juicy hacker fun for a few days!
Re:See Twitter's SQL. by jmorin007 on Sunday July 06, 2008 @09:48PM (#238203)
Days? I think we're already into negative minutes...
Re:See Twitter's SQL. by immad on Sunday July 06, 2008 @10:06PM (#238214)
I wonder how many minutes to techcrunching...
[dead]
Re:See Twitter's SQL. by Jax on Monday July 07, 2008 @01:42AM (#238353)
Nachiket, That should have been "Hello Babloo"...

Anyway... I didnt understand that... "Kolega to bolega". What does it mean? Open the bottle and then it will talk?