Posts

Showing posts with the label normalization

Normalization and Denormalization

Image
Introduction Data Anomalies Before diving into the main content of this article, we need to understand Data Anomalies, which are logical flaws or data discrepancies that occur in relational databases when proper table normalization has not been applied. This leads to information being stored repeatedly in a redundant manner. When data operations (Insert, Update, Delete) are performed, they cause the database to fall into an inconsistent state where data is correct in some places but incorrect in others. Data Anomalies are divided into 3 main types: Insertion Anomaly: Occurs when you cannot add a new record into the database because the system forces you to enter another piece of information that does not yet exist. Deletion Anomaly: Occurs when you delete one piece of information but accidentally lose another completely different and important piece of information. Update Anomaly: Occurs when a piece of information is repeated across too many rows. As a result, when you edit that infor...

GIN Index with TEXT

Image
Introduction In this article, we will continue to explore how to use GIN Index with the text data type First, please note that GIN Index only works with multi-valued data types, meaning fields containing multiple values, so you can easily create an index with the array type However, if you create a similar index with the text type, an error will be reported because text is only a single-valued type, containing only one content string, so you must pass an additional function that defines how to split the text value into items in an array before the index can be created If you remember, when using GIN Index with a text array, you will encounter limitations regarding partial search and must enter the exact word to search for it to work, now you can solve that problem by using text combined with two functions, to_tsvector and pg_trgm Full-Text Search This method uses the to_tsvector function and its index creation process will be as follows Tokenization & Normalization Split the text...