Heap relies on PostgreSQL for backend processing, storing events as hstore blobs and maintaining arrays of user events to enhance performance in funnel queries. The company discovered inefficiencies in a PostgreSQL function that used array_append in loops, leading to quadratic runtime increases, as evidenced by a function that took 36 seconds to generate a 100,000-element array. The inefficiency arises because PostgreSQL creates a new array and copies data with each append operation, unlike other languages that handle such operations more efficiently. The solution involves using the array_agg function, which aggregates a set into an array in linear time, drastically reducing the runtime to 300 milliseconds for the same task. This experience emphasizes the need to avoid procedural idioms in relational databases and highlights the importance of understanding expected runtimes for operations. Heap encourages feedback and further PostgreSQL discussions, hinting at future content about their use of Citus Data.