Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9233203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:29:47+00:00 2026-06-18T06:29:47+00:00

I’m a database newby. I am wondered about some things in Databases. For example,

  • 0

I’m a database newby. I am wondered about some things in Databases. For example, I saw the structure of how Facebook stores a friend relationship (see : https://developers.facebook.com/docs/reference/fql/friend). There only two columns, 1st users id and the second users id. Well that’s okay.

As wikipedia says facebook has around 1 billion active users. So in that friend relationship table, there maybe about 100 billion rows. Searching through that table is super-fast (eg: seeing my list of friends). I wonder how they do it at that kind of speed.

Is it because that Facebook has some magic back-end ? Or is it the magic of Databases ? Can I do it also (have millions of users and search through the database within seconds) using PHP and MySQL ?

(I may be asking a silly question, but it always bothers me to know, please leave an answer)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:29:49+00:00Added an answer on June 18, 2026 at 6:29 am

    The database makes use of indexes. This way it can find quickly data related to a given userID.

    Depending on the index structure, space occupation etc… there is a gain, i.e. instead of searching N columns, it searches – for instance – log(N). A search by dichotomy of 100 billions rows

    N = 100,000,000,000
    

    would be

    Search(N) : search log2(N) = search (36 rows)
    

    Instead a searching 10^12 rows, only 36 rows have to be analyzed.

    In the case you mention, friends, each user may have several friends, so

    user1 => (userX, userY, userZ, ...)
    userX => (userU, userV, user1, ...)
    

    meaning user1 is friend with userX, userY etc…
    ie you don’t have a unique index per user. But you have a unique index per couple of users.

    on Mysql that would be

    UNIQUE(user1,user2)
    

    meaning the couple (user1,user2) is only once in the table. The syntax would be

    CREATE UNIQUE INDEX friendsindex ON friends(user1,user2)
    

    friendsindex being the index name, friends being the table. Or as you said, declaring the table primary key to be (user1,user2) (primary keys are unique per table).

    —

    The strategy to win a game that consists of finding the exact price of a given object is based on the same principle. Say the price is between 1 and 10000. You tell a price, and the handler says + or -. You have to find the price in as less tries as possible. E.g. the price is 6000.

    You could start from 1 and give all prices until 6000 (ie 6000 tries), but you could also proceed by dichotomy

    • you: 5000
    • gamer: +
    • 7500 or (10000 – 5000)/2
    • –
    • 6250 or (7500 – 5000)/2
    • –
    • etc…

    you divide the remaining range by 2 at each iteration. Instead of 6000 tries, you can find in 12 tries (log2(6000)).

    —

    About logarithms

    For instance, how to find x in 2^x = 1024? Or x = log2(1024) meaning logarithm of 1024 in base 2 (answer: 10). In our story, a 1024 rows table having an index based on a binary tree would need 10 tries (max) to find the right element (instead of 1024 max).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
i got an object with contents of html markup in it, for example: string
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.