Search code examples
mysqlfacebookauto-increment

Double number IDs


I was wondering how facebook stores comments with IDs since there must be like a really high number of comments and messages in general, so I inspected the source and noticed that comments' IDs have two numbers, for example 530409847013982_5029288. Can somebody explain how that works? I mean how are they being picked up and how are they being inserted, I'm not sure auto increment works this way?


Solution

  • As the other answer explain it, those kind of ID are hierarchical. This is probably some kind of composite key. To "speak MySQL" UNIQUE(page_id, post_id). Which go back to your question:

    there must be like a really high number of comments and messages

    Big numbers! But, according to MySQL documentation, BIGINT UNSIGNED (or the almost equivalent SERIAL type) could hold values from 0 up to 18446744073709551615. Based on your example, and roughly speaking, there is still "room" for something like 10000 times more messages.

    If that wasn't enough, database usually provide a fixed point type (DECIMAL). With MySQL this type could hold up to 65 base 10 digits. Clearly some space left!

    Concerning the keys, MySQL limit these to 3072 bytes using InnoDB tables (as a reference, BIGINT require 8 bytes).Largely enough for that kind of application.

    If Facebook use MySQL, I don't think the ID/key length is there primary concern. I'm not sure they use MySQL thought? :D