Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2019 July PostgreSQL: Create Index on Full Text Search tsvector Data

PostgreSQL: Create Index on Full Text Search tsvector Data

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am sharing an example of applying Full Text Search on PostgreSQL Table with Index.

Here, I am using tsvector for full text search which is document type and uses match operator like @@.

PostgreSQL: Example of Trigram Index for Full Text Search using pg_trgm Extension

Below is an example:

Create a sample table with data:

1
2
3
4
5
6
CREATE TABLE tbl_Textdata
(id int, txt character varying);
 
INSERT INTO tbl_Textdata VALUES
(1,'I am DBA'),(2,'database research & development'),(3,'think for data only')
,(4,'data is important'),(5,'data is a future'),(6,'I am data owner');

Do Full Text Searching:

1
2
3
SELECT txt
FROM tbl_Textdata
WHERE to_tsvector(txt) @@ to_tsquery('data');

Result:

1
2
3
4
5
6
txt
--------------------------
'think for data only'
'data is important'
'data is a future'
'I am data owner'

Apply an Index on require Text Pattern:

1
CREATE INDEX tbl_Textdata_txt_idx ON tbl_Textdata USING GIN (to_tsvector('english',txt));

Check the execution plan:

1
2
3
4
5
6
7
8
9
10
explain analyze
SELECT txt
FROM tbl_Textdata
WHERE to_tsvector(txt) @@ to_tsquery('data');
 
'Seq Scan on tbl_textdata (cost=0.00..4.07 rows=1 width=32) (actual time=0.043..0.058 rows=4 loops=1)'
' Filter: (to_tsvector((txt)::text) @@ to_tsquery('data'::text))'
' Rows Removed by Filter: 2'
'Planning time: 5.494 ms'
'Execution time: 0.083 ms'

Jul 22, 2019Anvesh Patel
SQL Puzzle: SQL Advance Query - Generate the range of data basis on common combinationSQL Puzzle: SQL Advance Query - Generate the group of Sequences

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

July 22, 2019 PostgreSQLAnvesh Patel, database, database research and development, dbrnd, Full Text Search, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Monitoring, PostgreSQL Performance Tuning, PostgreSQL Programming, PostgreSQL Tips and Tricks, to_tsquery, tsvector
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....