Git Product home page Git Product logo

Comments (9)

cstack avatar cstack commented on June 27, 2024 1

When I say search here, I mean finding the row with a given primary key. Each node in the btree tells you which node to look at next for primary keys in a given range.

If you wanted to search for a row based on something other than the primary key, you would have to make an index (which I haven't covered yet in the tutorial). An index is represented as another btree that's sorted by a given column or columns instead of primary key, and each entry points to a row in the main btree instead of storing another copy of the row.

from db_tutorial.

SongZhao avatar SongZhao commented on June 27, 2024

Correct me if I'm wrong. You don't load all the node's content when you do searching, just load the node's index.

from db_tutorial.

gvzhang avatar gvzhang commented on June 27, 2024

I know what you mean about the primary key. But i still can't figuer out how to calculate the 500 data by 4 pages.

Could you list a calculation formula? @cstack

from db_tutorial.

cstack avatar cstack commented on June 27, 2024

@gvzhang Sure, I list a table of calculations in the article https://cstack.github.io/db_tutorial/parts/part10.html

I'm looking at the maximum number of leaf nodes that a tree could have with three layers of internal nodes. That's our branching factor raised to the third power, or 511^3, or 133,432,831 leaf nodes. If each leaf node has a size of 4 kilobytes, the size of all leaf nodes would be about 550 gigabytes.

If we weren't using a tree, we would instead have to scan through every leaf node to find a given primary key. So by using a tree, it's as if we searched through 550 GB of data, but in actuality we only searched through 4 pages (16 kilobytes).

from db_tutorial.

gvzhang avatar gvzhang commented on June 27, 2024

Is one page mean a internal node in part10?

from db_tutorial.

cstack avatar cstack commented on June 27, 2024

@gvzhang One node takes up one page. That's true for both internal nodes and leaf nodes.

from db_tutorial.

gvzhang avatar gvzhang commented on June 27, 2024

One page hold 511 child pointers to leaf node. So four pages can point to 511 * 4=2044 leaf nodes.
And each leaf node has a size of 4 kb, so 2044 * 4kb=8M. So four pages can search 8M data.

which part is wrong? thanks a lot.

from db_tutorial.

cch123 avatar cch123 commented on June 27, 2024

@gvzhang

        [    ] 1
      /      \         \
  [    ] 2   [     ]  ... [   ]
    /            \    ....
 [    ] 3     [     ]
   /             /
[    ] 4  ...  [      ] .....     [   ]

not
[ ] 1[ ]2 [ ]3 [ ]4

from db_tutorial.

cstack avatar cstack commented on June 27, 2024

That's right. Each layer of the tree has 511 times as many nodes as the previous layer, and we traverse four layers by visiting four nodes.

from db_tutorial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.