Nikki Siapno avatar

Nikki Siapno

@NikkiSiapno

Database indexing clearly explained.

A database index is a lot like the index on the back of a book. 

It saves you time and energy by allowing you to easily find what you're looking for without having to flick through every page.

Database indexes work the same way. 

An index is a key-value pair where the key is used to search for data instead of the corresponding indexed column(s), and the value is a pointer to the relevant row(s) in the table.

Most databases require some form of indexing to keep up with performance benchmarks.

To get the most out of your database, you should use the right index type for the job.

The ๐—•-๐˜๐—ฟ๐—ฒ๐—ฒ is one of the most commonly used indexing structures where keys are hierarchically sorted. When searching data, the tree is traversed down to the leaf node that contains the appropriate key and pointer to the relevant rows in the table. B-tree is most commonly used because of its efficiency in storing and searching through ordered data. Their balanced structure means that all keys can be accessed in the same number of steps, making performance consistent.

๐—›๐—ฎ๐˜€๐—ต ๐—ถ๐—ป๐—ฑ๐—ฒ๐˜…๐—ฒ๐˜€ are best used when you are searching for an exact value match. The key component of a hash index is the hash function. When searching for a specific value, the search value is passed through a hash function which returns a hash value. That hash value tells the database where the key and pointers are located in the hash table.

๐—•๐—ถ๐˜๐—บ๐—ฎ๐—ฝ ๐—ถ๐—ป๐—ฑ๐—ฒ๐˜…๐—ถ๐—ป๐—ด is used for columns with few unique values. Each bitmap represents a unique value. A bitmap indicates the presence or absence of a value in a dataset, using 1โ€™s & 0โ€™s. For existing values, the position of the 1 in the bitmap shows the location of the row in the table. Bitmap indexes are very effective in handling complex queries where multiple columns are used. When you are indexing a table, make sure to carefully select the columns to be indexed based on the most frequently used columns in WHERE clauses.

A ๐—ฐ๐—ผ๐—บ๐—ฝ๐—ผ๐˜€๐—ถ๐˜๐—ฒ ๐—ถ๐—ป๐—ฑ๐—ฒ๐˜… may be used when multiple columns are often used in a WHERE clause together. With a composite index, a combination of two or more columns are used to create a concatenated key. The keys are then stored based on the index strategy, such as the options mentioned above.

Indexing can be a double-edged sword. It significantly speeds up queries, but it also takes up storage space and adds overhead to operations. Balancing performance & optimal storage is crucial to get the most out of your database without introducing inefficiencies.

๐Ÿ’ญ Over to you. What would you add? ๐Ÿ’ฌ

~~
Thanks to our partner Udacity who keeps our content free to the community.

๐—ช๐—ฎ๐—ป๐˜ ๐˜๐—ผ ๐—ฏ๐˜‚๐—ถ๐—น๐—ฑ ๐—”๐—œ ๐˜€๐˜†๐˜€๐˜๐—ฒ๐—บ๐˜€ ๐˜๐—ต๐—ฎ๐˜ ๐—ด๐—ผ ๐—ฏ๐—ฒ๐˜†๐—ผ๐—ป๐—ฑ ๐—ท๐˜‚๐˜€๐˜ ๐—ฝ๐—ฟ๐—ผ๐—บ๐—ฝ๐˜ ๐—ฐ๐—ต๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด?
Learn to design, orchestrate, and deploy agentic AI with Udacityโ€™s new program.

Check it out here: 
Partager
Explorer

TweetCloner

TweetCloner est un outil crรฉatif pour X/Twitter qui vous permet de cloner n'importe quel tweet ou fil de discussion, de le traduire et de le remixer en un nouveau contenu, et de le republier en quelques secondes.

ยฉ 2024 TweetCloner Tous droits rรฉservรฉs.