pg_bigm is an extension provided by RDS for PostgreSQL. This extension offers full-text search capabilities, allowing the creation of a 2-gram GIN index to accelerate the search process.
Precautions
- The size of the column for creating a GIN index must not exceed 107,374,180 bytes (approximately 102 MB). Any attempt to input data exceeding this limit will cause an error.
- If the content stored in the database is not encoded in ASCII, it is recommended to change the database encoding to UTF8.
Prerequisites
Before using this extension, pg_bigm needs to be added to the shared_preload_libraries parameter. For more information about how to modify parameters, refer to Modifying parameters. warning
It is possible to create the extension without adding pg_bigm to the shared_preload_libraries parameter, but the extension will not function normally. The extension does not check shared_preload_libraries. Adding pg_bigm to the shared_preload_libraries parameter only reserves pg_bigm as a reserved_class_prefix to prevent users from using pg_bigm as a custom variable prefix. When not added to the shared_preload_libraries parameter, custom pg_bigm.xxx variables succeed but do not belong to the pg_bigm class. When added to the shared_preload_libraries parameter, custom pg_bigm.xxx variables fail because pg_bigm exists in reserved_class_prefix.
Create and delete extension
tip
A super account is required to create the extension.
Usage
Create index
Perform full-text search
In this example, full-text search matching is performed using LIKE, and results matching the keyword “Python programming” will be returned.
Perform similarity search using the =% operator
=% operator calculates the similarity between two strings and returns a float, with values closer to 1 indicating higher similarity.
Extension common functions
The pg_bigm extension’s common functions include likequery, show_bigm, bigm_similarity, and pg_gin_pending_stats. The basic information of these functions is as follows:
Examples of using common functions
- bigm_similarity function calculates the similarity between two strings, similar to the =% operator but called as a function.
Extension parameter
Some parameter usage examples are as follows:
tip
In this example, the bitmap index scan retrieved two rows from the full-text search index, but only one row was returned after the recheck process.
Others
- Differences and similarities between pg_trgm and pg_bigm
- pg_trgm is another extension provided by RDS for PostgreSQL, using the 3-gram model to implement full-text search. The pg_bigm extension is a redevelopment based on pg_trgm. The differences between pg_bigm and pg_trgm are as follows: