TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PostgreSQL Full-Text Search: Fast When Done Right (Debunking the Slow Myth)

427 pointsby VoVAllenabout 1 month ago

14 comments

retakemingabout 1 month ago
I&#x27;m one of the pg_search maintainers. Hello! A few thoughts.<p>First, both strategies - the one outlined by the Neon&#x2F;ParadeDB article, and the one used here -- are presented as viable alternatives by the Postgres docs: <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;textsearch-tables.html#TEXTSEARCH-TABLES-INDEX" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;textsearch-tables.ht...</a>.<p>Second - as the article correctly demonstrates, the problem with Postgres FTS isn&#x27;t &quot;how can I pick and optimize a single pre-defined query&quot; it&#x27;s &quot;how do I bring Postgres to Elastic-level performance across a wide range of real-world boolean, fuzzy, faceted, relevance-ranked, etc. queries?&quot;<p>`pg_search` is designed to solve the latter problem, and the benchmarks were made to reflect that. You can always cherry-pick a query and optimize it at the expense of data duplication and complexity. The Neon&#x2F;ParadeDB benchmarks contained 12 queries in total, and the benchmarks could have:<p>- Created composite b-tree indexes for each of the queries with boolean predicates<p>- Extracted the all the text fields from JSONBs, stored and indexed them as a separate columns for queries against JSONB<p>But that&#x27;s not realistic for many real-world use cases. `pg_search` doesn&#x27;t require that - it&#x27;s a simple index definition that works for a variety of &quot;Elastic style&quot; queries and Postgres types and doesn&#x27;t ask the user to duplicate every text column.
评论 #43630016 未加载
评论 #43629079 未加载
danpalmerabout 1 month ago
&gt; Mistake #1: Calculating tsvector On-the-Fly (Major issue)<p>I&#x27;m shocked that the original post being referred to made this mistake. I recently implemented Postgres FTS in a personal project, and did so by just reading the Postgres documentation on FTS following the instructions. The docs lead you through the process of creating the base <i>unoptimized</i> case, and then optimising it, explaining the purpose of each step and why it&#x27;s faster. It&#x27;s really clear that is what it&#x27;s doing, and I could only assume that someone making this mistake is either doing so to intentionally misrepresent Postgres FTS, or because they haven&#x27;t read the basic documentation.
评论 #43627960 未加载
评论 #43628356 未加载
评论 #43628711 未加载
评论 #43629110 未加载
评论 #43629344 未加载
ltbarcly3about 1 month ago
I first used pg full text in around 2008. I&#x27;ve also used SOLR and ElasticSearch to power search and recommendation in substantial products.<p>The issue I have had with postgres full text search isn&#x27;t that it&#x27;s too slow, it&#x27;s that it&#x27;s too inflexible. It&#x27;s a nice way to add simple search to fields but poor if you want to tune the search at all. Even allowing for general substrings is too much to ask, even allowing for custom tokenization is too much to ask. There&#x27;s no tokenization pipeline to speak of unless you want to write c extensions (which of course you can&#x27;t do for hosted databases anyway). Solr and Elasticsearch let you set up very complex indexes and search processing via configuration. There&#x27;s absolutely nothing that would prevent postgres from adopting a lot of this capability, but instead postgres offers literally NOTHING. I get the impression that most of the developers for postgres full text haven&#x27;t spent much time with other solutions as from previous discussions they don&#x27;t really understand what I mean when I talk about tokenization and filter setup, and they don&#x27;t really understand why this is a deal-breaker even for very simple applications. Postgres just splits on whitespace (and lets you basically manually use stopwords and stemming, which is crap). There is really no way to concatenate fields in a clean way into a single index, which again makes it extremely annoying to work with. There&#x27;s no way to score searches based on field weighting or really any other kind of weighting beyond BM. Compared to the alternatives it&#x27;s a toy system.
nattaylorabout 1 month ago
I wish there were some explain plans in either post, since I don&#x27;t get what&#x27;s going on.<p>If the query uses the index, then the on the fly tsvector rechecks are only on the matches and the benchmark queries have LIMIT 10, so few rechecks right?<p>Edit: yes but the query predicates have conditions on 2 gin indexes, so I guess the planner chooses to recheck all the matches for one index first even though it could avoid lots of work by rechecking row-wise
nostreboredabout 1 month ago
I&#x27;m legitimately curious -- why do people want to put EVERYTHING into postgres? I don&#x27;t understand this trend (vector search, full text search, workload orchestration, queues, etc.)
评论 #43628242 未加载
评论 #43628388 未加载
评论 #43628217 未加载
评论 #43628661 未加载
评论 #43628099 未加载
评论 #43628791 未加载
评论 #43630714 未加载
评论 #43629108 未加载
评论 #43631938 未加载
评论 #43628482 未加载
评论 #43628431 未加载
评论 #43628350 未加载
评论 #43629540 未加载
评论 #43628425 未加载
评论 #43632943 未加载
评论 #43628678 未加载
评论 #43628093 未加载
评论 #43629587 未加载
评论 #43628136 未加载
评论 #43628197 未加载
Vonngabout 1 month ago
BTW for anyone who interested, I&#x27;ve packed pg_search and vchord_bm25 extension RPM&#x2F;DEBs <a href="https:&#x2F;&#x2F;pigsty.io&#x2F;ext&#x2F;fts&#x2F;vchord_bm25" rel="nofollow">https:&#x2F;&#x2F;pigsty.io&#x2F;ext&#x2F;fts&#x2F;vchord_bm25</a> <a href="https:&#x2F;&#x2F;pigsty.io&#x2F;ext&#x2F;fts&#x2F;pg_search" rel="nofollow">https:&#x2F;&#x2F;pigsty.io&#x2F;ext&#x2F;fts&#x2F;pg_search</a> In case anyone want to benchmark by themselves. ;)
zhousunabout 1 month ago
Glab to see more &#x27;postgres-native&#x27; full-text search implementation.<p>Alternative solutions (lucene&#x2F; tantivy) are both designed for &#x27;immutable segments&#x27; (indexing immutable files), so marrying them with postgres heap table would results in a worse solution.
评论 #43628811 未加载
atemerevabout 1 month ago
10 million records is a toy dataset. Usually, you can fit it in memory on a laptop.<p>There are open large(-ish) text datasets like full Wikipedia or pre-2022 Reddit comments, that would work much better for benchmarking.
some_developerabout 1 month ago
Years ago I wanted to use native FTS (because of tall the things mentioned, having to sync to external simply adds complexity) and it failed at another point.<p>Not completely surprising, but on a table with _potentially_ couple of thousand of inserts &#x2F; seconds, it slowed down the overall updates to the point that transactions timed out.<p>We already added an index for one of the columns we wanted to index and were running the statement for the second one. The moment this the second index finished, we started to see timeouts from our system when writing to that table, transaction failing etc.<p>We had to drop the indices again. So, sadly, we did never get to the point to test the actual FTS performance :&#x2F; I would have like to test this, because didn&#x27;t necessarily had to search hundreds of millions of documents, due to customer tenants this would always be constrained to a few million _at most_.<p>ps: I already wrote about this -&gt; <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27977526">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27977526</a> . Never got a chance to try it nowadays (newer versions of everything, never hardware, etc.)
评论 #43632595 未加载
chenhoey1211about 1 month ago
I’ve seen a lot of teams jump straight to Elasticsearch or Meilisearch without realizing how much performance you can get out of native PG FTS when used properly.<p>could we get similar performance in the browser using something like SQLite + FTS5 + Wasm? Seems like an interesting direction for offline-first apps...
johnthescottabout 1 month ago
for text search we use the &quot;rum&quot; extension from postgrespro. search terabytes of pdfs &lt; 1sec. a talk here<p><pre><code> https:&#x2F;&#x2F;github.com&#x2F;jmscott&#x2F;talk&#x2F;blob&#x2F;master&#x2F;pgday-austin-20161112.pdf</code></pre>
briankellyabout 1 month ago
&gt; 10M log entries<p>I don’t think the question is speed, it’s scale. Use it until it breaks, though.
Thaxllabout 1 month ago
When it&#x27;s custom code that runs on PG I don&#x27;t call it native.
评论 #43630728 未加载
Syttenabout 1 month ago
Off topic but this kind of content marketing is excellent for any startup that tries to get its name out compared with a well-known competitor, like it is the case here with ParadeDB.