Heap utilizes PostgreSQL to efficiently manage backend processes by storing event data as hstore blobs organized in arrays, optimizing performance for tasks such as funnel queries. A notable challenge arose when a PostgreSQL function designed to handle large input arrays became inefficient, executing in quadratic time and taking approximately 40 seconds for 100,000 elements due to the way PostgreSQL processes arrays of variable-length elements like hstores. The original approach relied on array indexing, which incurred significant performance penalties, as PostgreSQL had to re-scan arrays for each index access. A solution was found by replacing the indexing method with the use of the `unnest` function, which linearizes parsing the array and allows for efficient deduplication and sorting of events by `event_id`. This adjustment reduced processing time to about half a second for the same input size, demonstrating a more idiomatic and efficient handling of arrays in PostgreSQL. The experience underscores the importance of understanding PostgreSQL's array handling nuances and suggests using `unnest` over direct array indexing for better performance.