Postgresql Indexes In-Depth
Improve Query Performance
This ebook may not meet accessibility standards and may not be fully compatible with assistive technologies.
Hi,
Working with indexes on SQL queries .. is the heart of good DB programmer and accordingly a fast DB performance.
INDEX Is a entry point to certain data(column) in an entity(table).
Typically a normal query on a table will scan each column and each row in every page of the table...then provide a result...
in big tables which may contains millions of records this will consume the resources(CPU,RAM) and accordingly degrade the query performance which lead to delay in fetching results .
-- Index will speed up the query result...as it limit the number of pages in a table that should be scanned looking for certain data when we do query without index.
-- How index works :
a- We select a frequently used column of a table.
b- We create index on that column.
c- Index will copy all data of that column (process 1).
d- Index will write all that column data into a new table file(process 2).
e- We save that new table file on the hard disk(process 3)
Now... A regular query without index would scan all the records of the original table ...including the frequently used column.
With index..the query will scan the new table file which contains ONLY the frequently used column.
Index can enhance the machine resources usage(CPU,HD, memory) through minimizing the workload of processes 1,2 and 3 .
Obviously with index the scan process is faster and accordingly the search time and result retrieval is quicker.
-- After creating index on a table :
A- Since making an index on a table require that all table data be scanned , the table will be locked until index build is finished...
On a large table the lock can take a long time...this will prevent any DML(insert,update,delete) transactions on the table though DQL(select) can be run on a table while index build is creating.
We will discuse all this issues and more through examples in this book ,,,, Enjoy
Details
- Publication Date
- Feb 19, 2025
- Language
- English
- Category
- Computers & Technology
- Copyright
- All Rights Reserved - Standard Copyright License
- Contributors
- By (author): Mohammed N. S. Al Saadi
Specifications
- Format
- EPUB