-- 40 small top-N scans of a table with order_columns: each opens its units once, reads the sort key of the rows that survive, and keeps its buffers small -- label: 40 x `ORDER BY customer_id LIMIT 10..49`, `order_columns = 'customer_id'`, no btree on the column -- ordered: no --@ pg SELECT count(*), sum(customer_id) FROM ((SELECT customer_id FROM orders ORDER BY customer_id LIMIT 10) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 11) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 12) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 13) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 14) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 15) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 16) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 17) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 18) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 19) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 20) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 21) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 22) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 23) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 24) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 25) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 26) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 27) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 28) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 29) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 30) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 31) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 32) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 33) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 34) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 35) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 36) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 37) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 38) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 39) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 40) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 41) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 42) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 43) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 44) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 45) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 46) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 47) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 48) UNION ALL (SELECT customer_id FROM orders ORDER BY customer_id LIMIT 49)) t