Scaling Postgres · Creston Jamison
In this episode of Scaling Postgres, we review two companies battling one another for text search dominance in Postgres, faster vector search with pg_vectorsearch, pushing Citus scaling with query routers and PostgreSQL 19 RC1 is released. To get the show notes as well as get notified of new episodes, visit: https://www.scalingpostgres.com/episodes/439-text-search-battle-royale/ Want to learn more about Postgres performance? Join my FREE training called Postgres Performance Demystified here: https://www.scalingpostgres.com/courses/postgres-performance-demystified/
0:00Well, we've got a regular battle royale going on between different text search solutions for Postgres. On one hand you got paradedb that keeps optimizing and pushing performance, and then you have PlanetScales 10, which is also trying to push performance as much as possible. But the good news for us as Postgres users is we are the winners in this race because both solutions seemingly keep getting faster. But I hope you, your friends, family and co workers continue to do well. Our first piece of content Making contents and the rest of search really fast, part 2 this is from paradedb.com and they posted last week how they believe they closed the performance gap with 10.
0:47And in this one it shows them where they pull ahead as much as 21 times faster.
0:54But of course you always have to be wary of benchmarks. But this analysis is based upon count.
1:01So they looked at a Wikipedia count and from what they were looking at, they got about twice as fast depending upon the type of query, whether it was a mixed conjunction, disjunction or phrase, although disjunction was not quite as fast.
1:17Now how did they improve this count performance?
1:20The first optimization they did is segment partitioning, because what they realized when doing profiling is that query visibility checking accounted for 80% of the page accesses. So basically how can we reduce these visibility checks? And with their LSM tree implementation, data gets partitioned into immutable segments that are merged together at a particular size threshold and that this merging is relatively naive. It's oblivious to the data contained within a segment, so each segment is basically random data. But with their new implementation they're actually splitting up segments based upon the values of the columns, so there's some correlation between them and they are partitioning merging strategy based upon the spooky LSM compaction paper and they said they can partition by ctid, which gives each segment a range of Postgres page numbers, so they can check that range against the visibility map up front.
2:21And this enhancement brought visibility related page accesses down from 1382 to just 30. So that's definitely an improvement. The next thing they did is they inverted their doc ID map. This allows them to do more efficient visibility checks when they need to do that. So basically it's a compressed column that maps Postgres page numbers to the first doc ID found on that page.
2:47And by doing this it reduced buffer accesses from over 7,500 to just under 400, which is a 95% reduction. And then the third thing they did is used bitmaps for common terms so for the indexes posting list it uses BP 128 encoding, and that's fine for most terms, but very common terms had super dense posting lists and that intersecting and unioning large B128 arrays incurred significant overhead and they were able to get efficiencies by representing them as bitmaps instead. And that basically halved the P99 latency in the Wikipedia benchmark count. And what they said in their comparison to 10 is that 10 is optimized for top K by BM25 and for counts, whereas PARDB is trying to be an Elasticsearch alternative where you're combining sorts and scoring along with the term that you're searching for.
3:46So in this example, looking at a count of hacker news items for the term database with a score greater than 10, when doing a filtered count like this, parade db was 10 times faster than 10. And then doing a filtered top k by BM25 relevance where you're adding in the ordering PreyDB was 11 times faster than 10.
4:09And then looking at the top case search again ordered by time was 21.7 times faster than 10. Now this also depends on what version is being used, because you'll see in the next blog post that PlanetScale has actually upped their game as well. But these are the results with the versions that they're using right now, and they're making the argument that when you're combining filtering and ordering that in These use cases paradedb might be superior because everything's in one index, whereas the 10 solution relies on B tree indexes for filtering and perhaps sorting. And then 10 just takes care of the text queries. And they show an example of that here where you're just creating one index for Parade DB, whereas you have to apply your 10 index and then two other indexes to be able to order by time or do scoring.
5:05But if you want to learn more, definitely check this out. Next blog post 10.1.0.62 to 3 times faster with support for stemming. This is from Planetscale.com so basically they've added some stemming support to basically be able to search by root words. But they also mentioned one competitor, optimized their full text index and identified one read only use case where their index was briefly faster than 10.
5:33So they got to work and the result is 1.0.4 released last week and version 1.0.6 which is releasing they say next week, which should be live already because this was written on October 8. So they talk about the stemming and I don't know if it's just ironic, but they put Competition is good, which was my title from last week's episode, and they discussed the benchmarks with paradedB and what they do say here is that 10 remain faster at counting queries, which paradedB just released an improvement to their account queries, and dramatically faster at any workload that involves concurrent writes. So that may be where the 10 solution has advantages on writes, but maybe parade DB's is the fact you only have one index and when you're combining terms, maybe it will be faster that way. We'll just have to see how this sorts itself out. But they did another set of benchmarks and based upon their improvements they're now showing themselves four times faster on conjunction queries. Again, not quite sure which PARADB version this was, it was probably the one that had the recent enhancements, although not the one I just spoke about in the previous blog post. Again, about 4 times faster, maybe 3 times faster with disjunction queries phrase queries. Again about maybe 4 times faster, 4 to 5 times faster and then looking at top 10 ranked about 4 times faster as well. But anyway, if you would like to learn more, definitely encourage you to check out both these blog posts.
7:08Next piece of content announcing PGvector search scalable open source vector search in PostgreSQL this is from tigerdata.com and they have released an open source extension that makes vector search dramatically faster and more cost efficient because it's using a new index type called Prism, not HNSW.
7:30And in terms of performance at 100 million vectors, Prism achieved 6 millisecond query latency on a machine with 4 times less memory than an HNSW index. And the index builds are also 20 times faster. So PRISM is an acronym for Partitioned Routing Index for Similarity Matching.
7:50And I should mention this particular project is an alpha. But you can get the open source library and start using it if you're interested. So Prism uses a partition based approach to vector search. So quote Instead of connecting every vector to its neighbors in a graph, Prism groups similar vectors into partition and stores them as a list in a compressed format that is densely packed into database pages. So the index will be smaller without the graph connections.