Gwen (Chen) Shapira Profile picture
Mar 19, 2024 13 tweets 4 min read Read on X
If you are using Postgres for embeddings, JSON or large text columns, or all of the above... then you are using TOAST, whether you know it or no.
TOAST can have massive impact on performance. So lets talk about it a bit: 🧵
Postgres has 8K pages, and you can't spread a row across pages. In fact, Postgres prefers to leave a bit of room for additional versions of rows or additional rows.

So if a row exceeds 2K (modifiable TOAST_TUPLE_THRESHOLD), Postgres is going to try and do something about it. Image
What does it do? it looks for "TOASTABLE" columns. With variable length type (varlena) like text, jsonb or vector, and that have storage type "extended" or "external". These storage types indicate data that can be stored outside the main table. Extended can also be compressed.
Then it starts with the largest value in one of these columns, it separates it into chunks, compressed them and stores them in another table.

The process continues until the row is under 2K. If it still does not fit, you'll get an error. Image
Every table with TOASTABLE types has a matching pg_toast table. This blog shows you how to find it: medium.com/quadcode-life/…
What's the performance implication? Well, anything that accesses TOAST data will need to "detoast" - read, decompress and process large amounts of data from another table. This can lead to serious IO and much slower and more IO intensive operations than you may expect.
This blog shows a good example: blog.anayrat.info/en/2022/02/14/…
What about pgvector? Embeddings can get really large. OpenAI's small embedding is 1536 points each, which leads to ~6K for the vector alone. Well over the threshold. Oh, and it looks like pgvector doesn't support compressing them.
However, this means that searches through the embeddings table are very IO intensive (putting index strategy aside for a second).
@jkatz05 gave a great talk on all things pgvector, and showed how you can improve performance by using smaller vectors and forcing Postgres to avoid TOAST.

Slide 30 for TOAST stuff, but the entire talk is amazing: postgresql.eu/events/pgconfe…
Finally, a common practice is to save a join by storing the source chunks for the embedding in the same row as the vector. This of course makes the row even larger, and if you force PG to avoid TOAST, it will reject inserts of too-large rows. So, move them to another table.
Oh, and one more bit, if you are wondering whether you use toast: Image
And how big are these rows, really? TOAST data included? Image

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Gwen (Chen) Shapira

Gwen (Chen) Shapira Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @gwenshap

Jun 19, 2023
I've ran into quite a few social posts that conflate relational databases, SQL, transactions and ACID. This is wrong in the sense that these are different concepts and you can mix and match them in different ways.

But turns out that historically, RDBMS predates SQL and ACID by… twitter.com/i/web/status/1…
The intersection between transactions and ACID is especially interesting.

You can have ACID without transactions (BerkleyDB had ACID guarantees on single statements).

But once you had transactions, they interact with all letters.

Atomic: fully committed or fully rolled back… twitter.com/i/web/status/1…
Transactions and their isolation levels are complex.

3 years after the 4 transaction isolation levels were defined, it turned out that a 5th level is needed: arxiv.org/pdf/cs/0701157…

And all this just with a single server! We didn't get anywhere near distributed databases yet.
Read 4 tweets
Sep 27, 2022
I didn't expect to attend in-person conferences this year. It is hard to justify taking time away from a very new company and product.

But @QConSF is convincing enough that I'll make an exception.

The talks I'm looking forward to the most: 🧵
Microservices: The whole track looks great, but Orchestration vs Choreography by @anatomic and Enabling Data Mesh by @zhamakd are topics that I've been interested in for years and would love to discover new perspectives.
"Architectures You've Wondered About" by @randyshoup . Every single talk looks like an amazing opportunity to learn something exciting and different. I love the diversity of problems, technologies *and* presenters.
Read 8 tweets
Jan 23, 2022
Future of Data prediction from @sriramsubram: "One DB will never happen. One platform will".
My thoughts:
When I started my career, the DB world was pretty clear - You had OLTP database for running transactional workloads, you had a DWH for analytical workloads and your had ETL/ELT in between.
Then NoSQL/BigData happened with new data stores on the OLTP side (non-transactional, but with lots of similarities in workload regardless) and on the DWH size (less structure, but again lots of workload similarities).
Read 11 tweets
Nov 7, 2021
One of the ways developers get in trouble is when they try to outsmart the framework they are using.

The framework has some limitations, and they work hard to get around these limitations without understanding what they are trading off when they do this.
Example! You have a Kafka producer, writing events about a large set of entities to a topic. You want events about each entity to be processed in order. And you also want some degree of parallelism between the entities.
It is super simple! Give each entity an ID, use the ID as a key, and use the number of partitions to control the degree of parallelism.
Read 9 tweets
Oct 10, 2021
Some advice on the enterprise SKU where you need to contact sales. But only very little, because I know very little about enterprise sales.
First, if your target persona is sales-averse (all developers), you'll win by minimizing the situations they have to talk to a salesperson. Do you really need them to contact sales, or maybe just provide an option? "For discounts, contact sales" may be better.
Second, make sure you actually have salespeople. If you are 3 founders in a garage, you have even more to gain by making sure people can pay first and contact you later.
Read 6 tweets
Oct 9, 2021
I am not sure SaaS companies understand how challenging and important SKUs are. A lot of what I see on pricing pages seems completely random. A thread.
1/ Why are they important? First, they are critical for landing customers. Each target user needs to look at your pricing page and go, "Yes. This SKU has the features I need, at a price that I am willing to pay".
2/ They are also crucial because you leave a lot of money on the table if you price too low. This is a risk for the future of your business.
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(