Database Internals

Database Internals


Data can be retrieved from tables in databases in a variety of ways.

Sequential scanning and B-tree index scanning are two popular techniques.

In this essay, we'll talk about both of them and examine their differences.


Sequential scan:


The simplest method for obtaining data from a table is a sequential scan.

As the name implies, this function reads each tuple on each page in order.

This is accomplished by scanning each page's line pointers.

The tuples on the pages can be found using the line pointers.

Sequential scanning is a brute-force technique that might be sluggish for big tables.

Yet, it can be helpful when the data is little and the query must scan the entire table.


B-tree index scan:


Scan the B-tree index:

It is more effective to get data from a table using the B-tree index scan.

It makes use of an index file with index tuples.

A TID (tuple identifier) pointing to the target heap tuple plus an index key make up each index tuple.

When a query needs to retrieve data, it first looks for the index tuple with the desired key in the index file.

Once the index tuple has been located, PostgreSQL uses the acquired TID value to fetch the required heap tuple.

When a query needs to retrieve data, it first looks for the index tuple with the desired key in the index file.

Once the index tuple has been located, PostgreSQL uses the acquired TID value to fetch the required heap tuple.

Because it doesn't have to read every tuple on every page, the B-tree index scan is quicker than the sequential scan.

Instead, it merely reads the desired heap tuple and the index file.

The index's creation and upkeep, nevertheless, can take some time and have an impact on the database's performance.


Conclusion:


Table data can be retrieved using both the sequential scan and B-tree index scan.

The B-tree index scan is more effective but harder to set up and maintain than the sequential scan, which is straightforward but slow.

Depending on the size of the table, the difficulty of the query, and the available resources, the best approach must be chosen.


#data #databases #postgresql #mysql #relationaldatabases #btree

要查看或添加评论,请登录

Siddharth Sabron的更多文章

  • ?? How Discord Used Rust to Scale Elixir Up to 11 Million Concurrent Users

    ?? How Discord Used Rust to Scale Elixir Up to 11 Million Concurrent Users

    NOTE: I love Discord’s backend team they are doing some amazing stuff at their product and this is just one of them…

    1 条评论
  • Atomicity in Database Management Systems??

    Atomicity in Database Management Systems??

    Introduction: Welcome to another insightful journey through the realm of database engineering! In today’s blog post…

    2 条评论
  • Understanding Isolation in Database

    Understanding Isolation in Database

    Isolation in database refers to the ability of a database system to allow multiple transactions to access the same data…

    1 条评论
  • ACID Properties in Database

    ACID Properties in Database

    Atomicity The concept of atomicity is particularly important in transactional systems, where multiple operations need…

  • Key Concepts in System Design

    Key Concepts in System Design

    Introduction System design is the process of defining and developing a high-level architecture of a system. The…

  • What caused Discord to switch from Go to Rust?

    What caused Discord to switch from Go to Rust?

    NOTE: This was one of the factors that led Discord to change from Go to Rust. Read States Read States is the service…

    1 条评论

社区洞察

其他会员也浏览了