Posts

Showing posts with the label index scan

Expression Index

Image
Introduction Expression Index is an extremely powerful feature of PostgreSQL, which can be used for any data type (such as text, numbers, time, arrays and more) as long as the result of the expression returns a Deterministic value You can use Expression Index for all index types ( B-Tree , Hash , GIN , GiST and more) as long as the expression you write in the CREATE INDEX command returns a data type that the Index type supports for processing The nature of Expression Index is that instead of indexing on the original column value, Postgres precomputes the result of the function or expression as soon as you INSERT/UPDATE and saves the result directly into the Index file Characteristics After creating an Expression Index, when using a query, you must write it exactly like the expression in the Index, otherwise the index will not work Every time a row of data is modified, Postgres must run that function or expression to get the result to create the Index. Therefore, avoid using function...

Using Hash Index

Image
Introduction In this article, we will explore another type of index, which is the Hash index. True to its name, when using this index type, Postgres passes the value to be indexed through a hash function to generate a number ranging from 0 to 4,294,697,295 with a uint32 (4 bytes) type. Index Creation Process As soon as you create a Hash index, Postgres pre-allocates Pages to store the indexes. If the table does not have data yet, Postgres will still create: 1 Metapage : Always located at the first position (Block 0). This page stores the configuration of the index. 1 Bitmap page : Used to manage which pages in the file are currently empty to avoid Overflow pages. 10 default Primary Bucket Pages . Thus, right from the start, your newly created Hash Index file will have a size of 12 Pages x 8KB/Page = 96 KB. If the table already contains data, based on the configuration information about the Ram limit that Postgres can use, it will create the maximum number of Pages (that it can create)...