Comments (9)
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.
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.
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.
@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.
Is one page mean a internal node in part10?
from db_tutorial.
@gvzhang One node takes up one page. That's true for both internal nodes and leaf nodes.
from db_tutorial.
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.
[ ] 1
/ \ \
[ ] 2 [ ] ... [ ]
/ \ ....
[ ] 3 [ ]
/ /
[ ] 4 ... [ ] ..... [ ]
not
[ ] 1[ ]2 [ ]3 [ ]4
from db_tutorial.
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)
- How do you fix errors about the getline function HOT 2
- Part 5: page_num out of bounds HOT 1
- a
- No definition of right child.
- No definition of root.
- Update Leaf node split and insert
- Failure/Error: pipe.puts commands Errno::EPIPE: Broken pipe HOT 1
- is there a rust edition of the database? HOT 2
- releases
- Regarding uint8_t in node header definition HOT 1
- translate to zh HOT 6
- Unreadable website HOT 4
- Part1: compilation error: implicit declaration of function 'getline' HOT 1
- Is there possibility of having overflow ?
- Can i continue this awesome project, dear cstack? HOT 1
- Is it opening the whole file and turning it into a BTree? HOT 1
- 这个是不是没有去实现事物处理等相关功能更? HOT 1
- Bug with internal_node_key()
- Could not get the code compiled... HOT 2
- Will the series continue? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from db_tutorial.