Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Sadeed Ahmad
Sadeed Ahmad

Posted on

PostgreSQL: An Introduction to Indexes

Indexes serve as auxiliary structures within a database, serving two main purposes: enhancing data retrieval speed and enforcing integrity rules. Lets explore indexes in PostgreSQL in detail, look into the different types of indexes available, explain why there is such diversity, and see how they can be utilized to optimize query performance.

Index Types

As of version 9.6, PostgreSQL offers six built-in types of indexes. All index types associate a specific key with the corresponding table rows that contain that key. Each row is uniquely identified by a tuple id (TID), which comprises the block number within the file and the row's position within that block.

Any operation performed on indexed data, such as inserting, deleting, or updating table rows, necessitates updating the indexes for that particular table within the same transaction.

Extensibility of Indexes

PostgreSQL has implemented an interface in its general indexing engine to facilitate the easy addition of new access methods to the system. The primary purpose of this interface is to obtain tuple ids (TIDs) from the access method and perform some tasks. It reads data from the appropriate versions of table rows and retrieve row versions using individual TIDs or in batches using a prebuilt bitmap. It determines the visibility of row versions for the current transaction, considering its isolation level.

The indexing engine is involved in query execution and is invoked based on a plan generated during the optimization stage. The optimizer evaluates various ways to execute the query, taking into account the capabilities of all potential access methods.

By using the indexing engine, PostgreSQL ensures uniform handling of different access methods while considering their specific characteristics. The primary scanning techniques are index scan and bitmap scan. In an index scan, TID values are sequentially returned until the last matching row is reached, and the indexing engine accesses the table rows indicated by these TIDs. On the other hand, in a bitmap scan, all TIDs matching the condition are initially returned, and a bitmap of row versions is constructed based on these TIDs before reading the corresponding row versions from the table. The choice between these scanning techniques depends on factors such as the number of retrieved rows and is determined by the optimizer.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Engineering Intern | Machine Learning and Data Science
  • Location
    Pakistan
  • Education
    NUST
  • Joined

More fromSadeed Ahmad

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp