Code Monkey home page Code Monkey logo

b-plus-tree-based-index-implementation's Introduction

B+ - Tree-based-index-implementation

Implemented a B+tree based indexing to speed up searching in a relational database resulting in the reduction of search time to log(n) with base d where d is the degree of the B+tree and n is the number of index pages

Workflow

  1. Compile Client.java file present in the src folder.

Screenshot from 2020-07-29 13-35-49

  1. Run the Client file and pass an empty folder as an argument for the creation of data and indexes.

Screenshot from 2020-07-29 13-36-58

Add the complete path of the empty folder while running the client file.

image

  1. Here you go! The window launches with first page as the home page giving a brief summary about the project.

Home Panel

B+trees

  1. Users can create data by switching to the data panel and then enter the number of rows to be created.

Data Panel

Screenshot from 2020-07-29 10-10-37

image

Data will be stored in the form of extents.

Extent -> Pages -> Rows image

For demonstration purpose, the schema of the table is as : Roll number | Name | Username | Password .

  1. Users can create Non-Clustered indexing [?] on any attribute of the table from the index panel which has a drop-down list to select the attribute name for the creation of indexes.

Index Panel

ind

image

  1. Now, it's time to enjoy the benefits of indexing. Switch to query panel.

Query Panel

search

Index Seek

Index seek is performed if query is made using the attribute on which indexes are created.

image

Table Scan

Table scan is performed otherwise. Time taken in table scan is considerably more than that in index seek.

image

Theory

Why Is Indexing Used in the Database?

Imagine you need to store a list of numbers in a file and search a given number on that list. The simplest solution is to store data in an array and append values when new values come. But if you need to check if a given value exists in the array, then you need to search through all of the array elements one by one and check whether the given value exists. If you are lucky enough, you can find the given value in the first element. In the worst case, the value can be the last element in the array. We can denote this worst-case as O(n) in asymptotic notation. This means if your array size is “n,” at most, you need to do “n” number of searches to find a given value in an array. Such type of search is called a Table scan.

B-Tree Indexes

This is the default index for most storage engines in MySql. The general idea of a B-Tree is that all the values are stored in order, and each leaf page is the same distance from the root.

A B-Tree index speeds up data access because the storage engine doesn’t have to scan the whole table to find the desired data. Instead, it starts at the root node. The slots in the root node hold pointers to child nodes, and the storage engine follows these pointers. It finds the right pointer by looking at the values in the node pages, which define the upper and lower bounds of the values in the child nodes. Eventually, the storage engine either determines that the desired value doesn’t exist or successfully reaches a leaf page. Leaf pages are special because they have pointers to the indexed data instead of pointers to other pages.

b-tree

B+ - Tree Indexes

B+tree is another data structure used to store data, which is almost the same as the B-tree. The only difference of B+tree is that it stores data on the leaf nodes. This means that all non-leaf node values are duplicated in leaf nodes again. Below is a sample B+tree.

b-plus-tree

b-plus-tree-based-index-implementation's People

Contributors

apoorva1999 avatar bullishking avatar

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.